To understand why the sky is blue, we first need to understand a little bit about light. Although light from the sun looks white it is really made up of a spectrum of many different colours, as we can see when they are spread out in a rainbow.
We can think of light as being a wave of energy, and different colours all have a different wavelength. At one end of the spectrum is red light which has the longest wavelength and at the other is blue and violet lights which have a much shorter wavelength.
Why is the sky blue?
When the sun's light reaches the Earth's atmosphere it is scattered, or deflected, by the tiny molecules of gas (mostly nitrogen and oxygen) in the air. Because these molecules are much smaller than the wavelength of visible light, the amount of scattering depends on the wavelength. This effect is called Rayleigh scattering, named after Lord Rayleigh who first discovered it.
Shorter wavelengths (violet and blue) are scattered the most strongly, so more of the blue light is scattered towards our eyes than the other colours. You might wonder why the sky doesn't actually look purple, since violet light is scattered even more strongly than blue. This is because there isn't as much violet in sunlight to start with, and our eyes are much more sensitive to blue.
The blue light that gives the sky its colour, is sufficiently bright to make all the stars that we see at night disappear since the light they emit is much dimmer.
Why does the blue fade towards the horizon?
You might also notice that the sky tends to be most vibrant overhead and fades to pale as its reaches the horizon.This is because the light from the horizon has had further to travel through the air and so has been scattered and rescattered. The Earth's surface also plays a role scattering and reflecting this light.
As a result of this increased amount of scattering, the dominance of blue light is decreased and so we see an increased amount of white light.