It’s actually both. The universe is expanding, yet Andromeda is hurtling toward us at 110 kilometers per second—the result of an invisible tug-of-war between space and gravity.
The expansion of the universe operates on a truly cosmological scale. When astronomers talk about galaxies moving apart, they are referring to the vast, empty voids between distant galaxy clusters. Over these immense distances, the expansion of space is the dominant force.
But on smaller, "local" scales, gravity is vastly stronger.
The Milky Way and Andromeda are the two most massive members of a galactic neighborhood called the Local Group, which contains about 80 galaxies. The distance between our two galaxies is roughly 2.5 million light-years. While that sounds enormous, in cosmic terms, they are practically next-door neighbors. Because they are so close and so massive, their mutual gravitational attraction easily overpowers the expansion of space between them.
Think of two people standing on a moving walkway that is carrying them apart. If they start walking toward each other faster than the walkway is moving, they will still eventually meet. The space between the Milky Way and Andromeda is expanding, but gravity is pulling them together much faster than space can separate them.
In about 4.5 billion years, this gravitational dance will culminate in a massive collision. The two spiral galaxies will pass through one another, distorting their spiral arms, before eventually settling into a single, giant elliptical galaxy that astronomers have nicknamed 'Milkomeda.'