When sunlight encounters a drop of water in the atmosphere it can produce a colorful rainbow because the amount that light rays are bent as they pass in and out of the raindrop depends on the wavelength (or color) of the light. Sunlight contains the full spectrum of colors that are visible to human eyes, but when nearly equal amounts of all these colors are mixed together, the result is white (or nearly white) light. Passing white light from a distant source through a raindrop is one way to separate the colors.
The diagram illustrates what happens to a single ray of sunlight as it passes through a spherical water drop (actual raindrops are not exactly spherical, but the mechanism is still very similar). Upon entering the drop, the light ray is refracted (or bent) into an angle that depends on wavelength (or color). Blue light is bent more than red light, with green and yellow in between. The diagram uses a red ray and a blue ray to illustrate how the long-wavelength and short-wavelength light is bent into different angles.
At the back of the drop, some of the light is reflected (what the diagram does not show is that much of the light passes into the air and continues traveling to the right). When the reflected light passes back into the air, it refracts (bends) again, which causes the colors to separate even further. The angle between the incoming ray of sunlight and the ray that has been refracted twice and reflected once is approximately 40 degrees for blue light and 42 deg for red light. The specific angle depends on the purity of the water and the exact wavelength being considered.
If you look carefully at the blue and red light rays exiting the lower left portion of the water drop in the figure, you might realize that your eye cannot usually see both red and blue from a single drop. If there really was only one raindrop, you would have to move your head up and down to see the colors change from red to blue. In fact, you can experience this by looking up close at a drop of water hanging from a flower or blade of grass with the sun behind you. In the case of a rainbow, there are many raindrops in the air, some at the right angle to send red light to our eye, some at the right angle to send blue light to our eye, and some at the right angle to send other colors to our eye.
In a large region of raindrops, the circular symmetry of the drops causes us to see the colors displayed in a circular band in the sky. Usually we only see a small section of the full rainbow circle because the rest of it is blocked by the ground in front of us. Standing on perfectly flat ground, the largest rainbow we can see is a half circle (when the sun is on the horizon behind us). Looking down from an airplane or a mountain, it is possible to see more of the circle, or even a complete circle. Do not, however, be confused if you see small colored circles of light either around the sun (or moon) or around the point directly opposite the sun (or moon). Several other optical phenomena that appear as colored circles are haloes and coronas (around the light source) and glories (around the point directly opposite the light source).
Contributor: Joseph Shaw