All children ask this question and then become adults and... keep asking it. Today we will answer it as clearly as possible.
Everything we see consists of unimaginably small particles with different properties. Light is no exception. And particles of light behave like waves.
'Light particles behave like waves', what does it mean?
It means that when a particle moves, it oscillates, not jumping from one position to another, but as if it were simultaneously in all the places where it oscillates. The distance between the extremities within which the wave particle oscillates is called the wavelength. This is, of course, a very rough simplification of complex quantum phenomena, but for now this explanation will do for us.
Light particles with different energy (= different oscillation frequency) have different wavelengths. Whether we can see this light and what color it has depends on the wavelength.
Sunlight is white, so particles of all colors overlap. But as soon as the particles of light released by the Sun hit the upper layers of the Earth's atmosphere, they are met by particles of our air, consisting mainly of nitrogen and oxygen.
Most of the visible light hardly notices the air and falls freely into our eyes and around us. But some - blue particles in particular - have a wavelength that causes them to interact more visibly with the air particles.
Sunlight scattering occurs: air molecules absorb some of the energy of the blue light particles and begin to emit blue light themselves. And not in one direction, but around them.
How light interacts with air
Air consists of molecules, while air molecules consist mainly of nitrogen and oxygen atoms. Each atom in the molecule has a nucleus and its own particles, electrons, which form a 'cloud' around the nucleus of the atom.
These electron clouds have their own frequency of oscillation - the result of stabilizing forces that keep the molecule together and prevent the particles from flying away.
If the frequency of the light wave that passes through the air molecule is close to the frequency of the natural oscillations of the atom in the molecule, there is a resonance - the electron clouds begin to oscillate more strongly.
You don't have to know quantum mechanics to describe the force of this effect - the Newton's Second Law is enough: the acceleration a body will receive depends on the force of action.
The force here is the light wave, the body is the cloud of electrons. And acceleration is the oscillation force of the electron cloud.
Luminescence occurs as a result of the acceleration of electron clouds.
The closer the light frequency and the resonance frequency of the atom are to each other, the stronger is the acceleration and the more intense is the luminescence.
In the atoms of nitrogen and oxygen, the resonance frequency is close to the frequency of violet and blue light waves, so the scattering in the sky occurs mainly at blue and violet frequencies.
In other words, the air we breathe seems to 'take' blue from sunlight and shine blue all over the sky. White light, lacking its blue component, seems yellowish to us – so the Sun is often drawn yellow.
The full name of the phenomenon that makes the daytime airglow blue is Rayleigh scattering. At sunset and dawn, the position of the Sun shifts to the horizon, so light has to interact more with the atmosphere than during the day before reaching our eyes. More interaction between light and air is stronger than scattering. The air starts to 'take' more colors, so the sky seems red already: particles with a 'red' wavelength dominate because they scatter less than others.
But this is only part of the answer. The truth is that not only blue particles scatter - in general, particles of all visible colors can be scattered. And it's violet particles, not even the blue ones, that scatter most of all in the sky!
The answer's in our eyes. Objectively there are no colors - there is only a wavelength, which our eyes interpret as a certain color.
The 'main' colors for our eyes are only three - red, green, and blue. There are three receptors in our eyes (they are called cones), one for each of these colors. All other colors are born from combinations of these three.
The human eye can distinguish purple well if it is a combination of blue and red (i.e. a lot of 'blue' and 'red' particles and few 'green'). But if it is a 'real', monochrome purple light, i.e. it consists mainly of particles with a 'purple' wavelength, then it gets problematic. Monochrome purple is on the edge of our eyes' capabilities.
If our eyes worked a little differently, we would see the sky purple. But in the course of evolution, it turned out that we have enough colors to survive, so we hardly notice 'purple' particles.
As a result, the sky seems blue to us. To be precise, whitish-blue - as we mentioned above, the particles of all visible light scatter, just in different ways.