In my example above, instead of star, I should have said galaxy, as it would be impossible, or nearly impossible, to detect such subtle shifting in individual stars at distances where cosmic expansion comes into play.
“You’ve experienced the Doppler effect if you’ve ever had a train go past you and heard the whistle go to a lower pitch (corresponding to a longer wavelength for the sound wave) as the train moves away. The Doppler effect can happen for light waves too (though it can’t be properly understood without knowing special relativity). It turns out that just like for sound waves, the wavelength of light emitted by an object that is moving away from you is longer when you measure it than it is when measured in the rest frame of the emitting object.
In the case of distant objects where the expansion of the universe becomes an important factor, the redshift is referred to as the “cosmological redshift” and it is due to an entirely different effect. According to general relativity, the expansion of the universe does not consist of objects actually moving away from each other - rather, the space between these objects stretches. Any light moving through that space will also be stretched, and its wavelength will increase - i.e. be redshifted.
(This is a special case of a more general phenomenon known as the “gravitational redshift” which describes how gravity’s effect on spacetime changes the wavelength of light moving through that spacetime. The classic example of the gravitational redshift has been observed on the earth; if you shine a light up to a tower and measure its wavelength when it is received as compared to its wavelength when emitted, you find that the wavelength has increased, and this is due to the fact that the gravitational field of the earth is stronger the closer you get to its surface, causing time to pass slower - or, if you like, to be “stretched” - near the surface and thereby affecting the frequency and hence the wavelength of the light.)
Practically speaking, the difference between the two (Doppler redshift and cosmological redshift) is this: in the case of a Doppler shift, the only thing that matters is the relative velocity of the emitting object when the light is emitted compared to that of the receiving object when the light is received. After the light is emitted, it doesn’t matter what happens to the emitting object - it won’t affect the wavelength of the light that is received.
In the case of the cosmological redshift, however, the emitting object is expanding along with the rest of the universe, and if the rate of expansion changes between the time the light is emitted and the time it is received, that will affect the received wavelength.
Basically, the cosmological redshift is a measure of the total “stretching” that the universe has undergone between the time the light was emitted and the time it was received.”