Sunlight looks white but is actually every color mixed together. When it hits the atmosphere, air molecules scatter the shorter, bluer wavelengths far more strongly than the longer red ones — an effect called Rayleigh scattering, where scattering rises sharply as wavelength shrinks. So blue light bounces around the sky in every direction, and that scattered blue is what reaches your eyes when you look up away from the sun.
At sunset the light travels a much longer, slanted path through the atmosphere. By the time it reaches you, almost all the blue has been scattered away and only the reds and oranges survive the trip — which is why the sun and the clouds near it glow warm. The same wavelength-dependent scattering, running in reverse geometry, produces both the midday blue and the evening red.
In the 1870s the British physicist Lord Rayleigh worked out mathematically how tiny particles much smaller than a wavelength of light scatter it, showing the scattering intensity is proportional to one over the wavelength to the fourth power. That steep dependence means blue light (around 450 nm) scatters roughly ten times more than red light (around 700 nm). Rayleigh's equation, published while he was still early in a career that would later win him the 1904 Nobel Prize, is still the standard explanation taught today, and it also correctly predicted that the scattered light would be polarized — which is why polarizing sunglasses can darken a blue sky.