On a clear day, the sky above you is a deep, bright blue. But sunlight itself is not blue. It looks white or slightly yellow. So where does all that blue come from? The answer has to do with tiny particles in the air and the way light travels.
Sunlight is made of all the colors of the rainbow mixed together. You can see this when sunlight passes through a glass prism or through raindrops and splits into red, orange, yellow, green, blue and violet. Light travels in waves, and each color has a different wavelength. Red light has the longest waves. Blue and violet light have the shortest.
The air around Earth is made mostly of nitrogen and oxygen molecules, which are far too small to see. When sunlight hits these molecules, some of the light bounces off in all directions. This is called scattering. Short waves are scattered much more than long waves. So blue light is bounced all around the sky, and wherever you look, some of that blue light reaches your eyes. This effect is called Rayleigh scattering, after the British scientist Lord Rayleigh, who explained the math behind it in 1871.
If violet waves are even shorter, why isn't the sky violet? There are a few reasons. Sunlight contains less violet light than blue light to begin with, and some violet light is absorbed high in the atmosphere. Most important, our eyes are much more sensitive to blue than to violet. Together, these facts make the sky look blue to us.
Scattering also explains red sunsets. When the Sun is low on the horizon, its light has to pass through much more air to reach you. By the time it arrives, most of the blue light has been scattered away. The light that is left is mostly red, orange and yellow, and those colors paint the evening sky.
The sky is not blue everywhere. On the Moon, there is almost no air, so nothing scatters the sunlight, and the sky is black even in the middle of the day. On Mars, the thin air is full of fine dust, which makes the daytime sky look a dusty, yellowish brown. Strangely, sunsets on Mars are bluish. In 2015, NASA's Curiosity rover took pictures of a blue sunset on Mars.