Rainbow is caused by total internal reflection, refraction and dispersion of light by the water particles present in the atmosphere.
Sunlight is first refracted as it enters a raindrop, which causes the different wavelengths of white light to separate.
Longer wangelength of light (red) are bent the least while the shorter wavelength (violet) are bent the most.
These component rays strike the inner surface of the water drop and get internally reflected if the angle between the refracted ray and normal to the drop surface is greater then the critical angle (48°).
The reflected light is refracted again when it comes out of the drop, as violet on the bottom and red on the top.