Sunlight is composed of lights with different wavelengths displayed in colours of red, orange, yellow, green, blue, indigo and violet. If you have ever played with prism, you will observe that light is scattered into 7 rainbow colours when passing from one side of the prism.
The same principle applies when sunlight reaches the atmosphere where molecules in the air scatter the blue light whilst letting lights with longer wavelengths pass through, leaving the sky in blue colour. The process is called "Rayleigh scattering".