When a wave source is moving relative to an observer, the waves change frequency. This is known as a Doppler shift.
Graphic by Kathryn Hadley
When a wave source is moving toward an observer, in effect, it is moving into its own wave pattern. This tends to compress the waves, making the wave crests closer together. For a sound wave, if the distance between the two is decreasing, the frequency of the wave is higher than the frequency that would be heard if the source and observer were at rest with respect to each other. If the distance between the two is increasing, the observed frequency is lower.
A similar effect happens with light waves. When the source and observer are approaching each other, the wavelength becomes shorter. Shorter wavelength light is bluer, so we call this blueshifting. If the source is moving away from the observer, the waves become redshifted. This effect is also seen if the observer is in motion.
Courtesy of Astronomy Interactives: highered.mheducation.com/sites/0072482621/student_view0/interactives.html
This interactive software is a good illustration of the Doppler shift effect.
Observing the Doppler shift of spectral lines in starlight allows us to tell if a star or galaxy is moving toward us or away from us, and how fast it is moving. We can compare observed spectral lines with those measured in the rest frame, such as in a laboratory. If the lines are shifted toward the blue end of the continuous spectrum, the source is moving toward us. If the lines are shifted toward the red, the source is moving away.
The equation above can be used to calculate the recession velocity, or the speed that the source is moving away from us. The shifted wavelength is the one we measure from the moving source. The rest wavelength is the one we measure in a laboratory.
For example, if we were using the Hydrogen alpha Balmer line to calculate recession velocity, we would use the rest wavelength of 656.3 nanometers, as shown in the hydrogen energy spectrum diagram on the Spectroscopy page.
If the velocity that we calculate turns out to be negative, it means that the source is moving toward us. That makes sense, since to make the equation negative, the shifted wavelength must be smaller than the wavelength at rest. The observed spectrum would be blueshifted.