If the accelerating expansion of the universe is driving galaxies away from each other, how is it that the Andromeda and Milky Way galaxies are on a collision course?
As you point out, the universe is expanding, carrying the galaxies inside it away from each other like raisins inside rising bread dough. This means that one day, far in the future, inhabitants of our galaxy will not see any other galaxies in the night sky.
That doesn’t mean that galaxies that are near to one another don’t interact, however.
Just as Earth’s gravity might pull on a nearby asteroid, sending it on a collision course with our planet, the Andromeda and Milky Way galaxies interact with each other gravitationally. This has resulted in the two galaxies falling toward each other at a rate of about 37 miles per second (60 km per second). Because Andromeda is 2.5 million light-years away — with 1 light-year equivalent to 5.9 trillion miles (9.5 trillion km) — this galactic crash won’t occur for 4.5 billion years. And thankfully, the space between stars is so great that it’s unlikely anything will truly collide. But the merger will change the paths of stars within each galaxy.
As it turns out, a majority of the Milky Way halo was “formed by the merging of numerous progenitor galaxies,” according to a paper published in The Astrophysical Journal earlier this year. Though the exact number of times our galaxy has merged with another is unclear, what is clear is that the Andromeda collision won’t be the first time the Milky Way has merged with another galaxy. Nor will it be the last.
Our galaxy is part of a galaxy cluster known as the Local Group. One day, this collection of nearly 100 galaxies may have all merged. And there’s even evidence that the Local Group might itself merge with the closest large galaxy cluster, the Virgo Cluster!