Rayleigh scattering is the elastic scattering of light or other electromagnetic radiation by particles much smaller than the wavelength of the light. This effect in our atmosphere causes diffuse sky radiation, which is the reason for the blue color of the sky and the yellow tone of the sun itself.
A portion of the light coming from the sun scatters off molecules and other small particles in the atmosphere. It is this scattered light that gives the sky its brightness and its color. The resulting color, which appears like a pale blue, is actually a weighted average of all the scattered colors, mainly blue and green.
The color of sunlight is intensified when the sun is near the horizon because the volume of air through which sunlight must pass is significantly greater. The Rayleigh scattering effect is therefore increased, removing virtually all blue light from the direct path to the observer. The remaining unscattered light is of a longer wavelength and therefore appears to be orange.
In locations with minimal light pollution, the moonlit night sky is also blue for the same reasons that the sky is blue during the day, as moonlight is reflected sunlight with a slightly lower color temperature due to the brownish color of the moon. The moonlit sky is usually not perceived as blue because at low light levels human vision occurs mainly from rod cells in the eye that do not produce any color perception.