The sky is mostly blue, but not always! Why? The short answer is air molecules in the atmosphere of the earth. They scatter sunlight and make the sky appear blue. But there is much more than meets the eye.
As Lord Raleigh explained, small particles (molecules) in the air, smaller than the wavelength of light, scatter sunlight. Differences in the wavelength of various colours in the incoming sunlight affect the intensity of the scattered light. The shorter the wavelength of light, the more intense is the scattered light. And blue has a shorter wavelength than red, for example. The small particles re-radiate the energy in different colours.
The sky at the horizon is not a perfect blue at sunrise and sunset. This is because of the curvature of the earth and thick atmosphere that makes the light travel a long distance to an observer. In the process, all the shorter wavelengths of light (for e.g blue) are laterally scattered by the large number of scattering practices, while only the longer waves (e.g red) reach the observer. Hence the sky looks whitish blue, and the sun can be a deep red. At the zenith, the scattering of blue is more pronounced in view of the fewer particles above the observer (35 times less than at the horizon). Besides the small size of the scattering particles, the transverse nature of light results in its polarisation and intensity.
The horizon can have more colours than just blue and red, and it is a mixture of scattered light from all the particles, often appearing white. The clouds are white, as they scatter sunlight without changing its spectral composition. It should be added that in addition to the air molecules, the atmosphere has dust particles, water vapors, rain drops, sea salt crystals and smog which also scatter sunlight but without changing its composition , as they are longer than the wavelength of light. That is why even polluted air makes the sky white.
As the altitude increases, air molecules decrease and the sky becomes blackish blue, ultimately merging with the deep black of outer space. You can see this from the window of a commercial jet airliner flying at about 10 km above the surface.
Recent research has solved one more riddle about the blue sky. it answers the question:
Why is the sky blue at twilight, when the sun is gone and the particles in the lower atmosphere alone cannot scatter enough blue light ?
The first clue came when the Americans launched the captured German v-2 rockets to probe the atmosphere. They found a thin air of oxygen molecules called ozone. Later research confirmed the presence of ozone at 25 to 35 km above the surface in the atmosphere. It cuts off the harmful ultraviolet rays of the Sun and blocks the other colors except blue. The layer contributes as much as 75 per cent of the blue twilight sky. Ozone is precious, as just 10 molecule part are found in a million air molecules.
Rayleigh scattering also explains the rings of Saturn as well as the light we get from stars that have layers (called atmospheres) which indicates their chemical composition and physical status.