The motion of a star relative to us can be determined by measuring two quantities, radial motion and proper motion. Radial motion is the motion of a star along our line of sight. That is, motion directly toward us or away from us. Proper motion is the change in angular position of the star, from which we can calculate the motion perpendicular to the line of sight (known as transverse motion. You can see how this works by imagining someone walking through a room. If we know the rate at which the person is walking toward us or away from us (radial motion) and their movement relative to the far wall (proper motion), then we can use a bit of simple geometry to calculate their path through the room.With stars, it turns out that the radial motion is easiest to measure. Stars don’t give off a continuous spectrum of light, but instead have dark gaps within their spectra (known as absorption lines). The pattern of these gaps have a specific pattern depending on the type of atom or molecule doing the absorbing. We can observe these patterns in the lab and compare them to the patterns seen in starlight. What we find is that the starlight patterns are slightly different colors. The pattern is either redder than we observe in the lab (redshifted) or bluer (blueshifted).
This is because of an effect known as the Doppler effect. You are probably familiar with the Doppler effect with sound. For example, how a train whistle sounds higher when a train is moving toward you, and lower when it’s moving away from you. The same effect occurs for light. It appears bluer when the star is moving toward us, and redder when it’s moving away from us. The amount of redshift or blueshift depends on how fast the star is moving. So by observing the color shift in the absorption spectra, we can calculate the radial motion of the star.
Proper motion is more difficult given the large stellar distances. Even if a star is moving relatively quickly, its apparent motion relative to background stars is fairly small. For example, the Alpha Centauri star system is about 4 light years away, and has a proper motion of 3.7 arcseconds per year. An arcsecond is 1/3600 of a degree, so this motion is quite tiny. With more distant stars the proper motion becomes even smaller. So you either need to observe a star over a period of years, or you need a really precise measurement of its position.
Given the smallness of stellar proper motion, you might think measuring the proper motion of a galaxy would be impossible. After all, even the closest galaxies are millions of light years away, so their proper motions are likely too small to measure. But it turns out in one case we can measure the proper motion of a galaxy, as seen in a paper published several years ago.
The Triangulum galaxy, also known as M33, is a nearby galaxy about 2.5 million light years from us. Within this galaxy are molecular clouds, and the water vapor within these clouds are emitting laser-like microwave signals known as astrophysical masers. Because astrophysical masers emit a strong light signal at a very precise wavelength, it is possible for radio astronomers to use a large telescope array (in this case the Very Long Baseline Array) to precisely determine the position of these maser clouds. From this they were able to measure M33’s proper motion as 30 millionths of an arcsecond per year. That motion through the sky is roughly equivalent to the width of a human hair compared to the circumference of the Earth.
It’s extraordinary that we can make such a precise measurement.