The fundamental process at work in a rainbow is refraction -- the "bending" of light. Light bends -- or more accurately, changes directions -- when it travels from one medium to another. This happens because light travels at different speeds in different mediums.
To understand why light bends, imagine you're pushing a shopping cart across a parking lot. The parking lot is one "medium" for the shopping cart. If you're exerting a constant force, the cart's speed depends on the medium it's traveling through -- in this case, the parking lot's paved surface. What happens when you push the shopping cart out of the parking lot, onto a grassy area? The grass is a different "medium" for the shopping cart. If you push the cart straight onto the grass, the cart will simply slow down. The grass medium offers more resistance, so it takes more energy to move the shopping cart.
But when you push the cart onto the grass at an angle, something else happens. If the right wheel hits the grass first, the right wheel will slow down while the left wheel is still on the pavement. Because the left wheel is briefly moving more quickly than the right wheel, the shopping cart will turn to the right as it moves onto the grass. If you move at an angle from a grassy area to a paved area, one wheel will speed up before the other and the cart will turn.
Similarly, a beam of light turns when it enters a glass prism. This is a simplification, but think about it this way: One side of the light wave slows down before the other, so the beam turns at the boundary between the air and the glass (some of the light actually reflects off the prism surface, but most passes through). The light turns again when it exits the prism, because one side of it speeds up before the other.
In addition to bending light as a whole, a prism separates white light into its component colors. Different colors of light have different frequencies, which causes them to travel at different speeds when they move through matter.
A color that travels more slowly in glass will bend more sharply when it passes from air to glass, because the speed difference is more severe. A color that moves more quickly in glass won't slow down as much, so it will bend less sharply. In this way, the colors that make up white light are separated according to frequency when they pass through glass. If the glass bends the light twice, as in a prism, you can see the separated colors more easily. This is called dispersion.
Drops of rainwater can refract and disperse light in the same basic way as a prism. In the right conditions, this refraction forms rainbows. In the next section, we'll find out how this happens.