The Milky Way, our home galaxy, is gravitationally bound to the Andromeda galaxy. Andromeda is a significantly larger galaxy than our own, sitting at about twice the number of stars that our Milky Way has, and so its gravitational clout is significantly stronger. With what we know now about Andromeda and the Milky Way, our two galaxies are destined to merge together.
We’ve known that Andromeda was a little unusual for quite some time - it’s one of the few galaxies which is found to be moving towards us instead of away from us - a red flag that our two galaxies are more intertwined than the average galaxy. But getting the exact details of how this merging was going to go forward has been quite a finicky piece of work.
To know exactly how two galaxies collide, you have to know a lot of things. At a very basic level, you need to know how far apart the two galaxies are, and how massive they are - this gives you the strength of the current gravitational pull between the two galaxies. But the hard part is that you also have to know how quickly the two galaxies are moving, relative to one another. Since we’re stuck in the Milky Way, it’s much easier to measure Andromeda’s motion relative to us, instead of trying to measure our own motion relative to Andromeda. All our best telescopes are in the Milky Way.
This is not to say that measuring the motion of Andromeda relative to the Milky Way is an easy measurement. We can measure Andromeda’s motion towards us without too much trouble; watch for the doppler shift in the light that reaches us, and we can determine how fast the galaxy is moving towards us. It turns out the answer there works out to about 250,000 miles per hour - fast enough to do a round trip to the moon in just under 2 hours. It’d take 3 and a half hours to make it from one edge of the Sun to the other, but any distance scale in between galaxies is so outrageously large that units of miles are functionally useless. Andromeda is currently sitting 2.5 million light years away, where each light year is about 6 trillion miles.
If Andromeda and the Milky Way were just pointed directly at each other, for a face-to-face direct smash-up, this is all the information we need to calculate how long we have before the collision takes place. But galaxies are almost never on these kinds of plunge orbits. There’s usually a sidelong approach, because each galaxy has some kind of sideways, diagonal encounter to the other galaxy. The two galaxies’ first encounter may be less like an asteroid plunging into the surface of a planet, and more like the gentle looping of a periodic comet. If the galaxies are going to loop around each other, the process takes much longer. If the sideways motion is too great, the two galaxies could slingshot past each other, never to meet again. To be sure which kind of interaction the two galaxies are going to have, we need to measure the sidelong motion of Andromeda, not just the motion towards us.
This is phenomenally hard, and was impossible before Hubble’s cameras got upgraded. It was only in 2012 that a reliable sideways motion for Andromeda could be determined. It turns out that part of why it’s hard in this case is that Andromeda’s sideways motion is really, really small. This means that our galaxies are on more of a direct collision course than they would be if Andromeda’s sideways motion were larger. With this information, we can plug all these numbers into theoretical simulations of our two galaxies, and see what gravity does to our home over the next few billion years.
The typical number thrown about for “when our galaxies collide” is about four billion years from now. In fact, it’s four billion years until that first encounter between the two galaxies; when the galaxies are at their new “shortest distance away” record. But as you can see from the simulation, that’s far from the end of the collision.
Galaxy collisions are a long, drawn-out process, which can easily take several billion years between the first close encounter, and the final settling-down into a single object. The simulations for the Milky Way and Andromeda’s collision currently seem to indicate that it’ll take another three billion years before the Andromeda-Milky Way conglomerate galaxy settles down into a single, new object. What will it look like, on the other hand, is yet to be fully understood - it’s possible the newly constructed galaxy will look like a scrambled, fuzzy blob. But if there’s enough gas in both galaxies, the new galaxy may well look like a spiral again, after a time.