A rainbow is caused because each colour refracts at slightly different angles as it enters, reflects off the inside and then leaves each tiny drop of rain.

Rainbow
A rainbow is formed when light enters each water droplet, and the different colours bend (refract) at slightly different angles. They reflect off the inside of the drop before refracting again as they leave. The shorter wavelengths refract more.
A rainbow is easy to create using a spray bottle and the sunshine. The centre of the circle of the rainbow will always be the shadow of your head on the ground.
The secondary rainbow that can sometimes be seen is caused by each ray of light reflecting twice on the inside of each droplet before it leaves. This second reflection causes the colours on the secondary rainbow to be reversed. Red is at the top for the primary rainbow, but in the secondary rainbow, red is at the bottom.