Why is the sky blue but the sunset red?

Rayleigh scattering

Air molecules scatter short blue wavelengths more readily. When the Sun is low, direct light travels through more air, loses more blue light to scattering and looks redder.

Change only the Sun’s elevation. The bars show red, green and blue direct transmission from top to bottom; the blue branches illustrate sideways scattering.

Model readings with the default settings
A/BSun elevationDirect blue / redRelative air path
A65°78.1%1.1×
B5°7.7%11.5×

The model samples 650, 550 and 450 nm with scattering proportional to the inverse fourth power of wavelength. A flat atmosphere omits clouds, aerosols, real sky colors and solar-disc brightness.

NASA · Wave Behaviors