The merge base is the whole trick
Two branches have diverged. Comparing their tips gives a set of differences and no way to interpret them: a line present in one and absent in the other could be an addition on one side or a deletion on the other, and those need opposite outcomes.
The missing information is the common ancestor, and Git computes it.
$ git merge-base main feature
a9cb607a61d6aaee5145894e92fa5f146cbdca80
That is the most recent commit reachable from both, and it is available for free because every commit records its parents. Finding it is a graph traversal over information already stored.
With three points instead of two, every line has an interpretable history. Compare the base to each side separately, and it becomes clear which side changed what.
This is a three-way merge, and the base is what makes it work. Systems without a reliable common ancestor cannot do this, which is why merging was historically painful and why cheap, accurate merging is often cited as Git's main practical advance.

