Spend a small amount of time reading about astronomy, and you'll very quickly hit upon the term "Red Shift". What is it ? What does it tell us ? and how is it linked to galaxy distances ?
Interestingly, it's something you will almost certainly be very familiar with, albeit a phenomena we notice in sound, and not light.
So you're walking along a road, you hear an ambulance heading towards you, and as that ambulance passes, the sound of the siren appears to change.
The effect of course is the Doppler effect, an object moving towards you compresses the sound waves, making them have a higher frequency, and an object moving away stretches the frequency, leading to a lower one.
Now I don't need to tell you, that as a wave (duality geeks feel free to smirk at this point) light behaves in the same way, an object moving towards you has its light frequencies move higher in frequency, and those moving away, are stretched longer. In astronomy we refer to these two things as Blue Shift and Red Shift.
The terminology can be easily confused, a red shifted object isn't necessarily red, as above you can see, a near cyan object may become yellow-green, the point of the term is, the original wavelength has moved towards the red, has been stretched by the object's velocity moving away from us.
So in a random universe you'd expect maybe some objects to be moving towards us and some away, but that's not what we see, in fact, almost all galaxies appear to be moving away from us, and the further away they are, the faster they appear to be moving away from us. It's almost as if, somebody is blowing up a balloon, and we as galaxies are sat on its surface.
However, there are a few exceptions, there are around 100 known galaxies that are blue shifted, all of them within our local cluster and close to us, and that includes the M31 Andromeda galaxy which is heading right for us, and is expected to merge in 4-5 billion years.
I remember when I first read about this phenomena as a child, wondering "What if most galaxies just happen to have more red stars and therefore produce longer wavelengths". Of course, I couldn't offer up any reason for why this would be the case, but it did get me thinking how can we be sure it's the movement that is causing the red shift in the first instance.
That's where standard candles come in, objects that no matter where they are are generally always exhibit the same luminosity and similar spectrums. Compare the object in a galaxy 50 million light years away, and the changes in it's spectrum towards the red, are not intrinsic to the object, rather, the effect of the movement of the galaxy.
By searching out these standard candles we can then begin to give the red shift a projected distance, based on other observable metrics (if you're interested in that topic, check out this simple explanation of 1 of a number of other ways of how to measure the distance https://kids.frontiersin.org/articles/10.3389/frym.2019.00142)
It's worth noting, there are other things which can cause this effect, gravity in particular, but that alone couldn't explain why almost every single galaxy is red shifted, so the only other logical outcome is, it's moving away from us.