The fundamental process at work in a rainbow is refraction when it travels from one medium to another. This happens because light travels at different speeds in different mediums. Different colors of light have different frequencies, which causes them to travel at different speeds when they move through matter. Drops of rainwater can refract and disperse light in the same basic way as a prism. In the right conditions, this refraction forms rainbows. When white sunlight hits a collection of raindrops at a fairly low angle, you can see the component colors red, orange, yellow, green, blue, indigo and violet -- a rainbow. When the white light passes from air into the drop of water, the component colors of light slow down to different speeds depending on their frequency. The violet light bends at a relatively sharp angle when it enters the raindrop. At the right-hand side of the drop, some of the light passes back out into the air, and the rest is reflected backward. Some of the reflected light passes out of the left side of the drop, bending as it moves into the air again.
A prism separates white light into its component colors. For simplicity's sake, this diagram shows only red and violet, which are on opposite ends of the spectrum.