The velocity of light in a material, and hence the index of refraction of the
material, depends on the wavelength of the light. Since the refractive
index depends on the wavelength of the light, light waves with different
wavelengths and therefore different colors are refracted through
different angles. This is called dispersion, because white light
is dispersed into its component colors while traveling through the
Snell's law combined with a wavelength-dependent index of refraction n explains the dispersive properties of a prism. The sides of a prism are not parallel and light changes direction when it passes through it.
A ~1% variation in the index of refraction over the entire visible range of electromagnetic radiation still results in a significant change in the direction of the emerging red and blue rays. Since in general the index of refraction is bigger for shorter wavelengths, blue light bends more than red light.
A rainbow is produced by dispersion and internal reflection of light in water droplets in the atmosphere. White light from the sun enters a spherical raindrop. The different colors are refracted through different angles, reflected off the back of the drop, and then refracted again when they emerge from the drop. The white light now has been dispersed into its component colors, and the different colors travel in slightly different directions. You see red light coming from water droplets higher in the sky than violet light. The other colors are found between these, making a rainbow. In the figure to the right and below, red light arrives at the eye of the observer from the upper drop and violet light from the lower drop. Other raindrops yield the other colors.
Rainbows are usually seen as half circles. From a plane or from a very tall building or mountain, however, one can see a complete circle. Sometimes one can see a double rainbow. The second, dimmer, band, which is higher in the sky than the first, comes from light reflected twice inside a raindrop. This reverses the order of the colors in the second band.
At sunset, in which direction are you most likely to see a rainbow?
The sun should be behind you, so you would most likely see a rainbow looking approximately east.
Sunset rainbows are special. The sun's rays are nearly horizontal, so the top of the rainbow is high in the sky. Because of scattering the sunlight at sunset contains more red and less blue hues. Therefore the red bands of the rainbow are emphasized and the blue bands are muted.
Additional information: The Physics Classroom: Refraction and the Ray Model of Light Lessons 4