Rainbows form when sunlight enters water droplets from behind the viewer. The geometry of the water droplets allows for refraction and reflection. Sunlight, which is composed of light of different wavelengths, splits into the constituting wavelengths because of refraction when it enters the water droplet, and it is then reflected from the inner surface of the droplet to the viewer. The ray undergoes refraction again when it exits the droplet.
The ray of light might undergo several internal reflections within the water droplet. Secondary rainbows form when the light reflects twice inside the droplet before exiting. Light can reflect as many as six times inside the droplet.
The size of the water droplets does not affect the rainbow's geometry. However, very small droplets, such as those in mist or fog, reduce the effect. The scattering effect overpowers the effect of dispersion of light into its component colors due to refraction. A "fogbow" thus formed has the same arc as a rainbow, but it lacks the spectral colors and appears as a white bow. Moonbows also form at night. They appear white because human eyes are less sensitive to color at night.
Rainbows are visible only from a particular position, and they alter and move as the viewer moves. They appear different to different viewers because of the change in perspective.
It is possible to recreate the refraction of light seen in rainbows by using a glass prism. The number of colors seen in refracted light can be as many as 100, however, due to the sheer number of variables in forming a rainbow, the number of colors visible can change greatly. The seven colors associated with rainbows-red, orange, yellow, green, blue. indigo and violet, can be traced back to Isaac Newton, which he associated with the seven notes in a musical scale.