Astronomers use a phenomenon called the Doppler shift to measure how fast objects are moving towards or away from us in outer space. But how does the Doppler shift work? Here's the common example. You pull over to the side of the road because you hear an approaching ambulance. As the ambulance gets closer, the siren sounds like it's being emitted at a higher pitch. This happens because the sound waves are compressed in the air as the ambulance approaches, making their wavelength shorter and pitch higher. The opposite occurs after the ambulance passes; the sound waves stretch and increase in wavelength and the siren sounds lower pitched.
Light waves experience this same phenomenon of squeezing and stretching as an object moves. Relative to the Earth, objects that are moving away from us have their light waves stretched to longer wavelengths, making the object appear more red. If an object is moving towards earth, it's light waves are compressed to smaller wavelengths making the object appear more blue. We can measure how Doppler shifted an object is by observing spectral lines emitted or absorbed by different elements in the moving object. In the image above, some absorption lines were red shifted, meaning this object is moving away from us. The larger this change in wavelength (called "red shift" or "blue shift"), the faster the object is moving. Some objects are moving so or are so far away that their lines are shifted out of the visible spectrum and into other portions of the spectrum not normally seen! Astronomers have viewed many ancient galaxies whose light appears today in the radio, but was originally emitted in the visible spectrum.
Image Credit: Wikipedia commons