Sunlight is a rainbow in disguise
The light arriving from the Sun looks white, but it is really a mixture of all the colours of the rainbow, each travelling as waves of a different length. Reds are long waves; blues and violets are short ones.
On its way to your eyes, that light has to cross the whole atmosphere — and the air itself has opinions about which colours get through easily.
Scattering: the sky’s trick
Air is made of molecules far smaller than the wavelength of light. When sunlight meets them, the short blue waves are scattered — bounced off in all directions — far more strongly than the long red ones. This is called Rayleigh scattering, after the physicist who explained it.
So wherever you look, some of that scattered blue light is raining down into your eyes from every part of the sky. The sky is blue because the air is, in effect, glowing faintly blue with borrowed sunlight. Violet is scattered even more, but our eyes are less sensitive to it, so blue wins.
Sunsets are the flip side
At sunset, sunlight crosses much more air to reach you. By the time it arrives, most of its blue has been scattered away along the path — leaving the reds and oranges behind.
Blue noon and red sunset are the same physics seen from two angles: the sky keeps the short waves, and lets the long ones travel.

