Simple Answer

The molecules in the air scatter the light coming from the sun. However, they do not scatter the light with different frequencies equally and blue light (high frequency) gets far more scattered in the sky, giving it its color.

Coulomb's Law

Coulomb's Law

To understand how this works, we are first going to need to do some refresh. This image represents the Coulomb's Law defined by:

F=kq1q2r2er\vec{F} = k \frac{q_1 q_2}{r^2} \vec{e_r}

Here, F\vec{F} represents the force applied by q1q_1 on q2q_2, kk is the Coulomb's constant equal to 14πε0\frac{1}{4 \pi \varepsilon_0} and er\vec{e_r} is the unit vector going from q1q_1 to q2q_2.

Note that if both charges are of the same sign, the force is going to be repulsive, whereas if the charges have different sign, their product will be negative and the force will be atractive, which is aligned with what we would expect.

From this force, we can derive the electric field created by q1q_1:

F=q2E    E=kq1r2er\begin{aligned} \vec{F} & = q_2 \vec{E}\\ \implies \vec{E} & = k \frac{q_1}{r^2} \vec{e_r} \end{aligned}

Link Between Electric Field And Electric Potential

We also need to recall the link between the electric field and the potential in the frame of electrostatics:

V=E.δlE=V\begin{aligned} V & = - \int \vec{E} . \vec{\delta l} \\ \vec{E} & = - \vec{\nabla} V \end{aligned}

Note that the electric potential VV is defined with an invariance to shifting by a constant, (that is why we mostly care about differences of potentials) most of the time we take that constant so that limrV=0\lim_{r \to \infty} V = 0. In the case of a single charged particle as before we get:

V=kq1rV = k \frac{q_1}{r}

Electrostatic Dipole

Dipole

Now we are going to see what happens when we have two opposites charges affecting the field. Note that here, OO is a point with no charge in the middle of NN and PP, we define rr as the distance between OO and the viewer in MM. Given the symmetry of the problem, the electric field has no part outside of the plane and does not depend on what plane containing the charges we are using. Thus, we can only define a single angle θ=(OP,OM)\theta = (\vec{OP}, \vec{OM})

Note that this graph is not at scale and actually represents a situation where r>>dr >> d, which makes sense when we compare the distance between you and an air molecule in the atmosphere (which is going to act as the dipole) with the size of that molecule.

The electric field has the linearity propriety that makes it possible to calculate it as the sum of the two electric fields that would exist for each of both charged particle. To calculate it we are first going to compute the potential (also linear because integration is linear) and then derive the electrical field from that potential by taking the opposite of its gradient:

V=V++VV=kq(1PM1NM)\begin{aligned} V & = V_+ + V_- \\ V & = kq \left( \frac{1}{PM} - \frac{1}{NM} \right) \end{aligned}

We are now going to use the fact that r>>dr >> d to approximate PMPM and NMNM.

Dipole Approximation

Since we are very far from the dipole we are looking at, it is as we have parallel lines between the two poles and we can make the following approximation:

PMPM=OMOP=rdcosθNMNM=OM+ON=r+dcosθ\begin{aligned} PM \approx P'M & = OM - OP' = r - d \cos \theta \\ NM \approx N'M & = OM + ON' = r + d \cos \theta \end{aligned}

Here PP' and NN' are, respectively, the projection of PP and NN on (OM)(OM). We can now have the potential in MM with the dipolar moment p=2qdp = 2qd:

V=kq(NMPMPMNM)kq(2dcosθ(rdcosθ)(r+dcosθ))=kq(2dcosθr2d2(cosθ)2)kpcosθr2\begin{aligned} V & = kq \left( \frac{NM - PM}{PM \cdot NM} \right) \\ & \approx kq \left( \frac{2d \cos \theta}{(r - d \cos \theta)(r + d \cos \theta)} \right) \\ & = kq \left( \frac{2d \cos \theta}{r^2 - d^2 (\cos \theta)^2} \right) \\ & \approx \frac{kp \cos \theta}{r^2} \end{aligned}

Okay, now let's compute the electric field where eθ\vec{e_\theta} is er\vec{e_r} rotated by 90°90° in the counter-clockwise direction:

E=Vkpcosθr2=Vrer1rVθeθ=2kpcosθr3er+kpsinθr3eθ=kpr3(2cosθer+sinθeθ)\begin{aligned} \vec{E} & = - \vec{\nabla} V \\ & \approx - \vec{\nabla} \frac{kp \cos \theta}{r^2} \\ & = - \frac{\partial V}{\partial r} \vec{e_r} - \frac{1}{r} \frac{\partial V}{\partial \theta} \vec{e_\theta} \\ & = \frac{2kp \cos \theta}{r^3} \vec{e_r} + \frac{kp \sin \theta}{r^3} \vec{e_\theta} \\ & = \frac{kp}{r^3} (2 \cos \theta \vec{e_r} + \sin \theta \vec{e_\theta}) \end{aligned}

Rayleigh Scattering

Rayleigh scattering is, in our case, the scattering of light coming from the Sun by air molecules with a small size compared to the wavelength of the light they are scattering, i.e. d<<λd << \lambda. We are going to see later why we need this hypothesis but let's see first if it is a reasonable assumption to make. Well, the visible light has wavelengths in [400nm,800nm][400\:nm, 800\:nm] and the air is mainly homogeneous and composed of dinitrogen, dioxygen and water vapor which have sizes around 0.3nm0.3\:nm. Thus, it is pretty safe to say that d<<λd << \lambda.

Excitation

When the electromagnatic waves that are the light from the Sun hit the air molecules, they excite them at their frequencies and the dipoles start oscillating at those same frequencies radiating their own electromagnetic field coming from their dipolar moment.

In this case, it is as we replaced our charges qq by q0cosωtq_0 \cos \omega t and q-q by q0cosωt-q_0 \cos \omega t. We have the charges oscillating at the frequency of the light f=ω2πf = \frac{\omega}{2 \pi} and here, having d<<λd << \lambda allows us to be sure that the excitation is pretty homogeneous at the scale of the dipole and that the speed of the charges v<<cv << c meaning that we don't have to take relativistic effects into account.

In MM, we have then the following retarded potential (taking into account the time we need to perceive the charges in NN and PP):

V=kq0(cosω(tPMc)PMcosω(tNMc)NM)V = kq_0 \left( \frac{\cos \omega (t - \frac{PM}{c})}{PM} - \frac{\cos \omega (t - \frac{NM}{c})}{NM} \right)

Now, using the approximation we previously made on PMPM and NMNM, we can simplify the cosines:

PM=rdcosθ    cosω(tPMc)cos(ω(trc)+ωdccosθ)=cos(ω(trc))cos(ωdccosθ)sin(ω(trc))sin(ωdccosθ)ωc=2πλ    ωdc=2πdλ<<1    cosω(tPMc)cos(ω(trc))ωdccosθsin(ω(trc))\begin{aligned} & PM = r - d \cos \theta \\ \implies & \cos \omega \left(t - \frac{PM}{c}\right) \approx \cos \left( \omega \left(t - \frac{r}{c}\right) + \frac{\omega d}{c} \cos \theta \right) \\ & = \cos \left( \omega \left( t - \frac{r}{c} \right) \right) \cos \left( \frac{\omega d}{c} \cos \theta \right) \\ & - \sin \left( \omega \left( t - \frac{r}{c} \right) \right) \sin \left( \frac{\omega d}{c} \cos \theta \right) \\ & \frac{\omega}{c} = \frac{2\pi}{\lambda} \\ \implies & \frac{\omega d}{c} = \frac{2\pi d}{\lambda} << 1 \\ \implies & \cos \omega \left(t - \frac{PM}{c}\right) \approx \cos \left( \omega \left( t - \frac{r}{c} \right) \right) - \frac{\omega d}{c} \cos \theta \sin \left( \omega \left( t - \frac{r}{c} \right) \right) \end{aligned}

In a similar way, we obtain:

cosω(tNMc)cos(ω(trc))+ωdccosθsin(ω(trc))\cos \omega \left(t - \frac{NM}{c}\right) \approx \cos \left( \omega \left( t - \frac{r}{c} \right) \right) + \frac{\omega d}{c} \cos \theta \sin \left( \omega \left( t - \frac{r}{c} \right) \right)

By plugging those approximations in the formula for V, we get a two kilometer long equation, which I'm going to spare you the details of, that simplifies to:

Vkpocosθr(1rcosω(trc)ωcsinω(trc))ωc=2πλ>>1r    Vkpoωcosθrcsinω(trc)\begin{aligned} V \approx & \frac{kp_o \cos \theta}{r} \left( \frac{1}{r} \cos \omega \left( t - \frac{r}{c} \right) - \frac{\omega}{c} \sin \omega \left( t - \frac{r}{c} \right) \right) \\ \frac{\omega}{c} & = \frac{2\pi}{\lambda} >> \frac{1}{r} \\ \implies V \approx & - \frac{kp_o \omega \cos \theta}{rc} \sin \omega \left( t - \frac{r}{c} \right) \end{aligned}

It's nice, however, in electrodynamics, VV is not sufficient in order to derive E\vec{E}. We also need to compute A\vec{A}, the magnetic potential. Note that ez\vec{e_z} is the unit vector in the direction NP\vec{NP}. I will also somewhat speed up the derivation here:

I(t)=q0ωsin(ωt)ez    A=μ0q0ω4πddsinω(tr(z)c)ezr(z)dzμ0p0ω4πrsinω(trc)ez=kp0ωrc2sinω(trc)ez\begin{aligned} \vec{I}(t) & = - q_0 \omega \sin ( \omega t ) \vec{e_{z}} \\ \implies \vec{A} & = - \frac{\mu_0 q_0 \omega}{4\pi} \int_{-d}^d \frac{\sin \omega \left( t - \frac{r(z)}{c} \right) \vec{e_z}}{r(z)} dz \\ & \approx - \frac{\mu_0 p_0 \omega}{4\pi r} \sin \omega \left( t - \frac{r}{c} \right) \vec{e_z} \\ & = - \frac{k p_0 \omega}{rc^2} \sin \omega \left( t - \frac{r}{c} \right) \vec{e_z} \end{aligned}

Electromagnetic radiation

Now that we have the electric and magnetic potentials VV and A\vec{A}, we can compute the electromagnetic field E\vec{E} and B\vec{B} radiated by the dipole:

E=VAtV=Vrer+1rVθθ\begin{aligned} \vec{E} & = - \vec{\nabla} V - \frac{\partial \vec{A}}{\partial t} \\ \vec{\nabla} V & = \frac{\partial V}{\partial r} \vec{e_r} + \frac{1}{r} \frac{\partial V}{\partial \theta} \vec{\theta} \\ \end{aligned}

The computation of this gradient gives two terms in 1r\frac{1}{r} and another one along er\vec{e_r} in ωc=2πλ>>1r\frac{\omega}{c} = \frac{2\pi}{\lambda} >> \frac{1}{r}. Thus, we can approximate again:

Vkp0ω2cosθrc2cosω(trc)erAt=kp0ω2rc2cosω(trc)ezThus, E=kp0ω2rc2cosω(trc)(cosθerez)ez=cosθersinθeθ    E=kp0ω2sinθrc2cosω(trc)eθ=μ0p0ω2sinθ4πrcosω(trc)eθ\begin{aligned} \vec{\nabla} V & \approx \frac{kp_0\omega^2 \cos \theta}{rc^2} \cos \omega \left( t - \frac{r}{c} \right) \vec{e_r} \\ \frac{\partial \vec{A}}{\partial t} & = - \frac{kp_0\omega^2}{rc^2} \cos \omega \left( t - \frac{r}{c} \right) \vec{e_z} \\ \text{Thus, } \vec{E} & = - \frac{kp_0\omega^2}{rc^2} \cos \omega \left( t - \frac{r}{c} \right) \left( \cos \theta \vec{e_r} - \vec{e_z} \right) \\ \vec{e_z} & = \cos \theta \vec{e_r} - \sin \theta \vec{e_\theta} \\ \implies \vec{E} & = - \frac{kp_0\omega^2 \sin \theta}{rc^2} \cos \omega \left( t - \frac{r}{c} \right) \vec{e_\theta} \\ & = - \frac{\mu_0 p_0\omega^2 \sin \theta}{4\pi r} \cos \omega \left( t - \frac{r}{c} \right) \vec{e_\theta} \end{aligned}

Now we can calculate B\vec{B} as ×A\vec{\nabla} \times \vec{A}. Since A\vec{A} doesn't depend on φ\varphi and has no component along eφ\vec{e_\varphi}, the computation of the curl in spherical coordinates is simplified to the following:

B=×A=1r(r(rAθ)Arθ)eφμ0p0ω2sinθ4πrccosω(trc)eφ\begin{aligned} \vec{B} = \vec{\nabla} \times \vec{A} & = \frac{1}{r} \left( \frac{\partial}{\partial r}(rA_\theta) - \frac{\partial A_r}{\partial \theta} \right) \vec{e_\varphi} \\ & \approx - \frac{\mu_0 p_0\omega^2 \sin \theta}{4\pi rc} \cos \omega \left( t - \frac{r}{c} \right) \vec{e_\varphi} \end{aligned}

Here we also made another approximation of the same type as before.

Poynting Vector

Now that we have the full electromagnetic field radiated by the dipole, we can compute the Poynting vector Π\vec{\Pi} which defines a flux density of the energy radiated by an electromagnetic field.

Π=E×Bμ0=μ0p02ω4sin2θ16π2r2ccos2ω(trc)er\begin{aligned} \vec{\Pi} & = \frac{\vec{E} \times \vec{B}}{\mu_0} \\ & = \frac{\mu_0 p_0^2 \omega^4 \sin^2 \theta}{16 \pi^2 r^2 c} \cos^2 \omega \left( t - \frac{r}{c} \right) \vec{e_r} \end{aligned}

Which averaged over time gives (since <cos2>=12<\cos^2> = \frac{1}{2}):

<Π>=μ0p02ω4sin2θ32π2r2cer\begin{aligned} <\vec{\Pi}> & = \frac{\mu_0 p_0^2 \omega^4 \sin^2 \theta}{32 \pi^2 r^2 c} \vec{e_r} \end{aligned}

Notice that the radiated power density varies in sin2θ\sin^2\theta, the power is zero along the axis of the dipole and is maximal along the equator. We can see on the following graph the radiated power as the radius for a given angle where the dipole is oscillating along the top-bottom axis

Dipole Radiation Graph

So, in order to get the power radiated, we need to integrate the density over a sphere of radius rr:

P=S(r)<Π>.dS=μ0p02ω432π2cS(r)[sin2θr2(rdθ)(rsin(θ)dφ)]=μ0p02ω416πcS(r)[sin3(θ)dθ]\begin{aligned} P & = \int_{S(r)} <\vec{\Pi}> . \vec{dS} \\ & = \frac{\mu_0 p_0^2 \omega^4}{32 \pi^2 c} \int_{S(r)} \left[ \frac{\sin^2 \theta}{r^2} (r d\theta) (r \sin (\theta) d\varphi) \right] \\ & = \frac{\mu_0 p_0^2 \omega^4}{16 \pi c} \int_{S(r)} \left[ \sin^3 (\theta) d\theta \right] \end{aligned}

To calculate the integral of sin3θ\sin^3\theta, we can separate it into sin2θsinθ\sin^2\theta * \sin\theta which equals (1cos2θ)sinθ(1-\cos^2\theta)\sin\theta. Now we define u=cosθu = \cos\theta, so du=sin(θ)dθdu = - \sin(\theta) d\theta. Thus the integral of sin3θ\sin^3\theta is:

S(r)(u21)du=[13u3u]S(r)=[13cos3θcosθ]0π=23+23=43\begin{aligned} \int_{S(r)} (u^2 - 1) du & = \left[ \frac{1}{3}u^3 - u \right]_{S(r)} \\ & = \left[ \frac{1}{3}\cos^3\theta - \cos\theta \right]_0^\pi \\ & = \frac{2}{3} + \frac{2}{3} = \frac{4}{3} \end{aligned}

We finally have:

P=μ0p02ω412πc\begin{aligned} P & = \frac{\mu_0 p_0^2 \omega^4}{12 \pi c} \end{aligned}

Conclusion

Power vs Wavelength

We have P1λ4P \propto \frac{1}{\lambda^4}. We can see on the graph that in the visual spectrum [400nm,800nm][400\:nm, 800\:nm], the little wavelength (blues) get far more scattered than wavelength at the other end of the spectrum (reds), thus giving the sky its color.