William Ducker, a professor of Chemistry at Virginia Tech, offers this explanation:
Refraction
Image: Geometry Center, University of Minnesota

REFRACTION. The water droplet changes the angle at which light passing through it travels, depending on the wavelength of the light rays.

Rainbows appear when light originating from the sun is refracted and reflected by small water droplets suspended in the air. The need for water droplets and strong sunlight is the reason rainbows are often observed after rain. When a water droplet refracts sunlight, it changes the angle at which the light travels both as it enters and exits the droplet. How much the angle changes depends on how the light interacts with the water molecules.

Light from the sun is a mixture of different colors--red, yellow, green, blue, violet--that look white when they are superimposed. Each color interacts with water molecules slightly differently. And as a result, the water droplet changes the angle of each color slightly differently. The water droplets in the rainbow cause these different colors to be viewed at slightly different angles and thus to appear as separate colors.

The actual colors present in a rainbow represent the wavelengths of light that make it through our atmosphere from the sun. But the colors that we see are slightly different because our eyes are more sensitive to certain hues, such as green. Even so, our eyes have evolved so that they are sensitive to the colors that the sun puts out. Hence, the distribution that we see is simply an exaggeration of the original distribution of the light wavelengths emitted by the sun.

rainbow
Image: Wilderness Alaska

MIDNIGHT RAINBOW. The size of a rainbow-- such as this one at the Arctic National Wildlife Refuge--depends on how our brain perceives features near it, such as mountains.

The physics of rainbow formation dictates the angle between the viewer, the sun and the rainbow--but not the absolute position or actual size of the rainbow. Thus a rainbow appears to move as a viewer moves (hindering the search for a pot of gold). And its size is a matter of human perception. Our brain receives only the information on the angle. From experience, each person knows that the boundary of an object that is far away subtends a smaller angle than one that is near. In other words, a single head can obscure your entire view of a movie screen if the head is close enough to you.

To gage the size of a rainbow, the human brain uses this experience in reverse. It measures the angle subtended by the rainbow and then looks at other features such as mountains in the surroundings. If the other features are far away, then the brain interprets the rainbow as a very large object. Conversely, if the rainbow appears to be near the observer, it also looks much smaller. The same effect explains why the moon looks so much larger when it sits behind many features on the horizon than when it appears above us in the sky.
Answer posted August 31, 1998