Why it matters
When you need guaranteed O(n log n), stable sorting, mergesort is the answer. It's also the base for many hybrid sorts and is easier to reason about than quicksort.
The architecture
Divide: split the array or list into two halves. Recursively sort each.
Merge: with two sorted halves, walk them together with two pointers, taking the smaller element each time. Produces a merged sorted output.
How it works end to end
Stability: when merging, taking left before right when equal preserves original order. This is what makes mergesort stable.
Space: standard mergesort uses O(n) auxiliary space for the merge. In-place merge is possible but complex.
Linked list mergesort: no random access penalty; merge is natural. Preferred sort for linked lists.
TimSort: hybrid mergesort that exploits already-sorted runs. Standard in Python and Java. Very fast on real-world data.