When I was a kid I heard that the sky was blue because it was the reflection off the ocean. The light from the Sun, which appears white, is actually made up of all colors of the rainbow, when the light enters the atmosphere the colors can become separated (Imagine looking at light through a prism). We know that bluer light travels in short, tight waves while redder light travels in longer waves. The shorter the wavelength, the more likely the light is to bounce off of an air molecule and become scattered. Blue light is scattered most in our atmosphere.
I also heard, when I was a kid, that when you observe a sunset and you see the shift in color from blue to red that you’re actually seeing the sun’s rays being filtered through the pollution. Well, that sounds dismal. It’s also not entirely true.
One of the main factors in determining a sunset’s color is the Earth’s atmosphere. The atmosphere is made up mostly of gases as well as some other molecules and particles thrown in for good measure. The most common gasses in our atmosphere are nitrogen (78%) and oxygen (21%). The remaining single percent is made up of water vapor and lots of tiny solid particles like dust, soot & ash, pollen, and salt from the oceans. There are also trace gasses like argon present. Also, depending on where you live, you’ll have to factor in that volcanoes can put large amounts of dust particles high into the atmosphere and pollution can add different gases or dust and soot to the air as well.
The atmosphere of the Earth can be thought of like a filter on a camera lens.
So let’s put it all together in how light acts in the air surrounding our planet. Light moves in a straight line until it is messed with (be it gas, dust, ash, etc.). Once something interferes and gets in the way of the light wave it’ll scatter that light in different directions. The probability of light to be scattered by a molecule is proportional its wavelength, so shorter wavelengths of light are scattered much more often than longer wavelengths. In the case of air molecules, the molecules are much smaller than the wavelength of the scattered light, this is called Rayleigh scattering.