Maths behind the rainbow

Marianne Freiberger Share this page

When the great mathematician Isaac Newton explained the colours of the rainbow with refraction the poet John Keats was horrified. Keats complained (through poetry of course) that a mathematical explanation robbed these marvels of nature of their magic, conquering "all mysteries by rule and line". But as we will see, the mathematical explanation, requiring just the basic geometry of lines and circles, is just as elegant as the rainbows themselves.

Bent on refraction


The visible spectrum from violet (left) to red (right).

The colours of the rainbow are a result of refraction splitting the light into its constituent components, just as happens when light shines through a prism. The white light that arrives from the Sun is a combination of electromagnetic waves with varying frequencies. You see white when this mix of frequencies hits your eye at the same time, but when your eye catches an individual wave on its own, you perceive a particular colour.

Waves with frequencies between around 670 and 780 THz are perceived as shades of violet. On the other end of the spectrum are waves with frequencies between around 400 and 480 THz, which are perceived as shades of red. All the other colours come from frequencies in between these two bands. Electromagnetic waves of other frequencies can't be perceived at all by the human eye.


Figure 1: A ray of light being refracted, reflected and then refracted again.

When a ray of sunlight hits a spherical water droplet some of it will be reflected by the surface of the droplet, but some of it will enter it. As it enters, the light ray will be bent, or refracted. It's the same phenomenon you see when you stick a straw in a water glass. The ray then continues until it hits the back of the droplet. Some of the light will exit, but some of it will be reflected back, leaving the droplet on the other side and being refracted again in the process. See figure 1.

Refraction is a result of a ray of light being slowed down as it passes from one medium to another. For a very crude analogy think of pushing a shopping trolley from the road onto grass at an angle: it will change direction because the side of the trolley that hits the grass first will be slowed down first.

Different coloured light being refracted

Figure 2: Light of different frequencies is refracted by different amounts.

When light from the Sun travels through a vacuum (and to a very good approximation through air) all frequencies travel at the same speed $c$, roughly 300,000 km per second. As the ray of light passes into water, the frequency, and therefore colour, remains the same. However, its speed will change by an amount that depends on the frequency. This is because the atomic structure of water interacts differently with waves of different frequencies. A measure of the slowing-down of light with frequency $f$ is given by the refractive index $n_{f,w}.$ Its value depends not only on the frequency $f$ but also on the medium the light is entering (in this case water, as indicated by the subscript $w$). The index is defined as

$n_{f,w}=\frac{\mbox{Speed of light in a vacuum}}{\mbox{Speed of light with frequency $f$ in water}}.$

The refractive index barely changes as the frequency $f$ varies: $n_{f,w}$ is around 1.34 for the violet end of the spectrum and around 1.33 for the red end. But this small variation is enough to split sunlight into the beautiful spectrum of colours we see in a rainbow. (The refractive index also varies slightly with temperature, but we can ignore this here.)

Snell's law

Figure 3: The diagram shows the cross-section of the water droplet containing the incident ray, the refracted ray and the normal. The angles α and β are related by Snell's law.

Just how much the light of different frequencies is bent when entering the droplet is described by Snell’s law. The law says that the refracted ray of light lies in the plane formed by the incident ray and the normal at the point of incidence – the normal is the line that passes through the point where the ray hits the droplet and is perpendicular to the surface of the droplet. Since we’re assuming the droplet to be spherical, the normal in this case is just the extended radius of the droplet, connecting its centre to the point of incidence.

Snell’s law also tells us that the angle by which a ray is refracted is given by this equation:

$\displaystyle \frac{\sin {\alpha }}{\sin {\beta }}=\frac{n_{f,w}}{n_{f, a}}.$

Here $\alpha $ and $\beta $ are the angles shown in figure 3 and $n_{f,a}$ and $n_{f,w}$ are the refractive indices of air and water, respectively, for light with frequency $f$. As air is very similar to a vacuum, the refractive index $n_{f,a}$ is very nearly equal to 1 for all frequencies. Thus, if a light ray hits the droplet so that $\alpha =45^\circ $, then red light with a refractive index 1.33 has

  \[ \beta =\arcsin {\frac{\sin {45^\circ }}{1.33} = 32.12^\circ .} \]    

(The result is rounded to two decimal places.) Violet light with a refractive index of 1.34 has

  \[ \beta =\arcsin {\frac{\sin {45^\circ }}{1.34}=31.85^\circ .} \]    

It's these different refraction angles for the different frequencies of light that gives a rainbow its colours.

Catching rainbow rays

But why do we see each of the colours forming a perfect circular arc? To understand the shape of the rainbow, think of light from the Sun as coming down in parallel rays and striking a particular water droplet in the air. Using Snell’s law and the law of reflection (that the angle of incidence equals the angle of reflection), we can work out by how much a ray is deviated in terms of the angle $\alpha $ at which it first hits the droplet. In other words, by what angle it is being turned as it is refracted, reflected and then refracted again (see figure 4). This angle will of course be different for each frequency, or colour of light.

By staring hard at figure 4 you can convince yourself that the deviation $D_ f(\alpha )$ is given by the formula

  \[ D_ f(\alpha )=(\alpha -\beta )+(180^\circ -2\beta )+(\alpha -\beta )=180^\circ +2\alpha -4\beta . \]    
Angle of deviation

Figure 4: Working out the angle of deviation.

From Snell’s law, we know that we can substitute

  \[ \beta = \arcsin {\frac{\sin {\alpha }}{n_{f,w}}} \]    

in the above expression. (We are taking the refractive index of air to be 1 here.)

Figure 5 shows the graph of $D_ f(\alpha )$, taking the refractive index $n_{f,w}=1.33$ for a particular shade of red. Notice that it has a minimum at a value $\alpha _ m$ somewhere in the region of $60^\circ $.


Figure 5: The graph of Df(α).

This minimum angle $\alpha _ m$ is what gives us the rainbow. Figure 6 shows a 2D cross-section of the droplet containing a bunch of rays for our refractive index $n_{f,w}=1.33$. The ray entering at the minimum angle $\alpha _ m$ in this cross-section is shown in red. It is called the rainbow ray. The rays that hit the droplet near the rainbow ray (with an angle close to $\alpha _ m$) cluster close to it during their passage through the droplet and when they emerge. So if your eye happens to catch the rainbow ray from this droplet after it's emerged, you will see a whole bunch of other rays too, making the light that comes from our droplet particularly intense. Since all the clustering rays are of the same colour, our particular shade of red which has $n_{f,w}=1.33$, the droplet lights up red in the sky.
Rainbow ray

Figure 6: The rainbow ray is shown in red. A cluster of rays emerges from the droplet near the rainbow ray, while rays that emerge elsewhere are more spaced out.

The fact that emerging red rays cluster near the rainbow ray is a consequence of $\alpha _ m$ being the minimum of the function $D_ f(\alpha )$. You can see this in figure 7. Take an interval $I_1$ centred on the minimum and an interval $I_2$ of the same width centred elsewhere. The range of deviation angles for values in $I_1$ (given by the interval $J_1$) is much smaller than the range of deviation angles for values in $I_2$ (given by the interval $J_2$). Thus, rays that hit the droplet with angles $\alpha $ in $I_1$ stick closer together than rays with angles $\alpha $ in $I_2$.

If you don't believe the picture, here is a proof.


Figure 7: The interval J1 is smaller than the interval J2.

Colour cones

So you see a red dot in the sky for every droplet from which your eye manages to catch an outgoing red rainbow ray. To see where in the sky these droplets are relative to you, let’s first work out the exact value of $\alpha _ m$. Solving $\frac{d D_ f(\alpha )}{d\alpha }=0$ to find the minimum gives

  \[ \alpha _ m=\arccos {\sqrt{\frac{n_{f,w}^2-1}{3}}}. \]    

(See here for the details).

Substituting $n_{f,w}=1.33$ (for our particular shade of red) gives $\alpha _ m=59.58^\circ $ and $D_ f(\alpha _ m)=137.48^\circ $.

Now if an emerging rainbow ray from a droplet meets your eye, then this means that the emerging ray makes an angle $r_ f=180^\circ -137.48^\circ =42.52^\circ $ with the line $L$ shown in figure 8. It’s the line you get from extending the ray of sunlight that would pass straight through your eye if your head wasn’t in the way. (Remember we’re assuming that the rays from the Sun are parallel.) Let’s call $r_ f$ the rainbow angle. Of course it depends on the frequency $f$ and therefore on colour.


Figure 8: The deviated rainbow ray from your droplet makes a 42.52 degree angle with the line L.

If you take all lines that emanate from your eye and make a $42.52^\circ $ angle with $L$, what you get is a cone (see figure 9). The droplets that light up red for you all lie on this cone: if they didn't, you wouldn't be catching their red rainbow ray. But when you look along the surface of a cone from its vertex, as your eye is doing, all you see is a circle. You can try this by rolling a sheet of paper up into a cone shape and peering through the little hole at the tip. The rainbow comes from droplets that lie on the cone at different distances from your eye, some can be near and others can be far. But your eye can't distinguish the distances, all it sees is red light mingling together to form a circular arc that appears to be located somewhere in the distance. The reason why you don't see the full circle is that the Earth gets in the way. Unless you're above the water droplets, for example when looking down from a plane, in which case you can see a beautiful circular rainbow.

Figure 9: The droplets you see light up in the sky lie on the surface of a cone.

The same reasoning goes for all the other colours of the spectrum: they appear as circular arcs. But the varying indices of refraction give a different rainbow angle for each colour. For example, violet light with $n_{f,w}=1.34$ gives $\alpha _ m=59.0^\circ $ and $D_ f(\alpha _ m)=138.93^\circ $, so the rainbow angle in this case is $41.07^\circ $. Thus, the rainbow appears as a nested sequence of circles of colours in order of their refractive indices, or, equivalently, in order of their frequencies: red at the top all the way through to violet at the bottom.

This explanation also shows why you only ever see a rainbow when you're standing with your back to the Sun: that's the only way you can catch rainbow rays coming from droplets. It also explains why the sky appears much brighter below the rainbow than above. Since the vast majority of rays leaving a droplet do so above the rainbow ray (see figure 6), you won't catch any rays from droplets that are "above" the rainbow (that is, outside the cones for the various colours). So you won't see any reflected light from these droplets. However, your eye does catch reflected light from droplets "below" the rainbow (droplets that lie inside the cones) and it's this light that makes the sky below the rainbow appear brighter. It appears as white light because non-rainbow rays for different colours, coming to your eye from different droplets, are mixed together.

The rainbow geometry also shows that any rainbow you see is yours and yours alone: whatever a person standing next to you might see, it'll come from a different set of water droplets and therefore it'll be a different rainbow.


Sometimes, if you are lucky, you might see a second, slightly fainter rainbow above the main one. The secondary rainbow is a result of light rays being reflected twice within the water droplets. The rainbow angles for the various colours are around 51 degrees in this case, which is why the secondary rainbow is seen higher in the sky. The double reflection also means that the colours of the secondary rainbow appear in reverse order, with violet at the bottom and red at the top. Here's the original sketch by René Descartes, who first explained the shape of the rainbow, showing both the primary and secondary rainbow. The double reflection corresponding to the secondary rainbow is traced in red.


Descartes' sketch of the primary and secondary rainbow.

It is even possible in theory (though it hardly ever happens in practice) to see rainbows coming from three, four or more reflections within the droplets. But I'll leave these calculations to you.

About the author

Marianne Freiberger is co-editor of Plus.



I have seen triple rainbows and read on the BBC website about the first quadruple rainbow being captured on film (photographic?). At what angles would we see the third and fourth rainbows?


We're trying to find out how much light comes out at a certain angle (represented by D). That depends on D(alpha), as the author states. However, it also depends on the intensity of light as a function of alpha. Much more light falls on the drop between alpha = 0 and alpha = 1 degree than falls on the drop between alpha = 89 degrees and alpha = 90 degrees. (In fact it's more than 100 times as much.)

This does not affect the final result of which angle is the rainbow angle. However, it does affect the distribution of light intensity as a function of D and the article is remiss to ignore it.


Great post! In your photo, the secondary rainbow has red at the bottom, which is opposite what is described in the text.

Had to re-read this statement about secondary rainbows being reversed, several times, because the author's color description of the "reversal" still matched the first rainbow's order of hues. I'm not math or physics minded, and already being overwhelmed by those complex details, I thought I must be terrible in English comprehension, as well. My reason for even attempting to read this article was to find out why the color blue in a rainbow begins as light blue before transitioning to darker indigo....which becomes a lighter purple, as violet. I wanted to transpose "the color wheel" mixing of primary colors to understand, without taking into account that the bending of light is not the same as if mixing paint. I'm gonna Google Search the angle from the "Light Color Wheel" to see if Sunlight is the same as Computer Screen Light...which it's probably not. I just want to know what causes a Rainbow blue to transition from light to dark, then to light purple. If I had super vision, would the light purple of violet change to a dark purple. However, my mind has not developed neural synapses to comprehend these answers. I wish!


photons can only go at speed c, individual encounters within the water apparently lowers the overall light velocity more for blue than for red, as a photon encounters the boundary layer at angle alpha, does it push the lower atom down and the upper atom up as it passes through?


Thanks for the post. I'm confused about one point though. In figure 4, why the light is fully reflected first time but not when exiting? In both cases it makes an angle of beta with the normal. Following the Snell's rule, it should be never fully reflected, if it's source is outside of the water droplet according to my understanding. It should always exit with the angle it enters.


Thank you very much for the explanation though I skipped the part of the maths for calculating the angle between incidence and emerging ray. I have seen double rainbows a few times. I even have a photo of one in this Handphone. I read your article because I was searching for the angle of incidence and emerging ray for a rainbow.