Thinking
about light going through a prism is an easy way to understand the
reason why the sky is blue.
When
a ray of light crosses over any material, its propagation direction
deviates a certain angle, which depends on the type of this material.
Transparent materials are usually characterized by a parameter called
"refraction index", and its value depends on the colour
of the light that comes across it. Therefore, each colour contained
in a ray of white light will be deviated a different angle, bringing
about a unique ray of white light separated into different colours
behind the prism.
Each
colour is characterized by a number called "wave length".
The deviation of colours is maximum for the blue (with short wave
length), that is, blue is the colour that diverts a wider angle from
the initial light ray, and it is minimum for red and yellow (with
a longer wave length), which do not diverges appreciably.
The blue light rays, once deviated from the initial ray, interact
with other particles of the air, varying once more their direction.
They make a zigzag trajectory through the atmosphere and finally
they arrive to us. This is the reason because the rays seem to come
from everywhere in the sky. Yellow rays of light do not actually
deviates from the sun and, therefore, we can see the sun as being
yellow.
When
the position of the sun is near the horizon (low in the sky), its
rays come across a higher thickness of air and will interact more
often with the particles contained in it. The blue and violet rays
are highly deviated to the sides than yellow and red ones, which maintain
their trajectory in the same sunlight direction. This effect creates
those wonderful sunsets that we can see from earth.