Disclaimer: I am not an astronomer or physicist. I welcome any corrections or clarifications.
The light from stars and galaxies has a color. For stars that are close enough and bright enough, you can see their color with your eyes just by looking up on a clear night1. Galaxies are dim enough that they just appear grey to our eyes, even when looking through a telescope. But if you use a camera and set the exposure long enough, the camera will capture the color of the galaxies, too.
This is the color we are talking about when we say that as stars age, they get redder. It's the color we see with our eyes.
Light is a wave2 and is subject to the Doppler effect just like sound is. Think of the sound of a car zooming past you. The pitch of its engine starts high, and then drops low. It start high because the sound waves are being compressed as the car moves toward you. As it zooms past, you hear it shift lower. The car is now driving away from you, so the sound waves are being stretched out.
Light has a wavelength, too. Light's wavelength is its color. When something moving towards you emits light, its wavelength is compressed, shifting the color towards the bluer direction of the spectrum from wherever it started. When something moving away from you emits light, its wavelength is stretched out, shifting the color redder.
This is what redshift and blueshift are.
Star color vs. redshift: How to tell them apart
How can we tell if the color of a star is from the star itself, or has just been redshifted because it is moving away from us?
To answer this question, we need to take a bit of a side quest and talk about spectral lines.
How do we know what stars are made of?
We know stars are made primarily of hydrogen and helium, plus smaller amounts of other elements. But how do we know this?
When you pass white light through a prism, the light that goes in bends a little--it refracts--and the light that comes out is split into a rainbow. The rainbow of light that comes out of a prism is called a spectrum.
It turns out that when you heat up atoms, they glow3. Each element--each unique kind of atom--glows in a specific color of light. If you heat up sodium or any other element to a temperature sufficient to make it glow, and then pass that light through a prism, the spectrum that comes out is NOT a full rainbow. Instead, it is only slices of the rainbow so thin they look like lines, which we call spectral lines. Importantly, each element produces a unique set of lines distinct from all other elements. The same element always produces the same lines. They look like this:
Let's recap what we know so far.
- Atoms give off light when heated up.
- We can separate the light into its spectrum using a spectrometer (the scientific instrument version of a prism4).
- We can use that spectrum to identify which elements are present in the star.
So now we have all the tools to find out what stars are made of! Simply pass the light from a star through a spectrometer, and use the resulting spectrum to see which elements are present based on the spectral lines produced5.
Tying it all together
Now we know enough to understand how astronomers can tell the difference between the color of a star or galaxy and its redshift.
- We know the spectral lines present in a star's spectrum correspond to the elements present in the star.
- If the star is moving away from us, the spectral lines will be redshifted by an amount corresponding to how fast the star is receding.
- But the spectral lines will still appear in a recognizable pattern: The width of the lines and the distance between them still correspond to whatever elements are present in the star. They are just uniformly shifted redder than the spectral lines normally produced by those elements.
- We can identify the composition of the star from the pattern in the spectral lines.
- We can identify the direction and speed it is moving towards or away from us from the blueshift or redshift of the spectral lines. I.e., how far the lines are from where they should be based on the composition from #4.
- We can identify the star's true color6 by compensating for the redshift or blueshift.
1 At first glance the stars all seem white, but as you look a little closer, you'll notice they're lightly red, blue, yellow, orange, and white. Once you see it, it's hard to unsee!
2 Light is also a particle. Light is weird and fantastically complicated.
3 It's even cooler than that, actually. Everything glows, all the time! It's called thermal radiation. The "color" or wavelength of light the thing emits depends on its temperature. Even people glow! This is how night vision cameras work. They can see the infrared light you give off. The only way to not glow is to have a temperature of −273.15 °C, which is 0 K, known as absolute zero.
4 More generally, you can split light into its spectrum using a spectrometer. A prism is to a spectrometer what a lens is to a camera. Technically, spectrometers use a diffraction grating instead of a prism. A prism splits light into its constituent colors because it is one kind of diffraction grating.
5 I'm skipping some details like the difference between emission spectrums and absorption spectrums, but it mostly doesn't matter for the purposes of this discussion. My example shows an emission spectrum, but mmeent's answer shows an absorption spectrum, which I believe is what astronomers would actually use when looking at stars and galaxies. I mostly mention it to explain why the two examples look like inverted versions of each other.
6 In fact we rarely need to do this. Having the composition tells us considerably more about the star than its color alone would. But in principle, we have enough information to know its true color, too.