Sunlight, scattered by the air itself
Sunlight looks white, but it is a blend of all the colours, each with its own wavelength — reds long, blues and violets short. As sunlight crosses the atmosphere, it collides with air molecules far smaller than the wavelengths themselves, and those molecules scatter the short wavelengths far more strongly than the long ones. This is Rayleigh scattering, named after Lord Rayleigh, who worked out the mathematics in the 1870s.
The scattered blue light is thrown in every direction, so it reaches your eyes from all over the sky, not just from the Sun's disc. Wherever you look on a clear day, you are seeing sunlight that has been bounced to you by the air itself — and that borrowed light is overwhelmingly blue.
Why sunsets turn the sky red
At sunset, sunlight slants through far more air to reach you — the path through the atmosphere can be dozens of times longer than at noon. Along that long journey, nearly all the blue is scattered away before the light arrives, used up colouring the sky for people further west.
What survives the trip is the stubborn end of the spectrum: reds, oranges and yellows that scatter least. The Sun itself appears red, and clouds near it catch the same leftover light. Pollution and dust add larger particles that scatter differently, which is why volcanic eruptions can produce spectacularly lurid sunsets worldwide.
Other skies, other colours
Violet light is actually scattered even more strongly than blue, yet the sky does not look violet: sunlight contains less violet to begin with, the upper air absorbs much of it, and our eyes are far less sensitive to violet than to blue. The mixture our eyes receive reads as the familiar sky blue.
Remove the air and the effect vanishes. On the Moon, the daytime sky is pitch black and stars are visible alongside the Sun, because there is nothing overhead to scatter light. On Mars, fine dust in the thin air tints the sky a butterscotch tan — scattering again, but by dust instead of gas.

