Nature's Arc of Color
A rainbow stretching across the sky after a rain shower is one of nature's most beautiful sights. For centuries it inspired myths and legends. But a rainbow is not a magical object hanging in the sky, and it is not really an object at all. It is an optical effect, created by sunlight interacting with countless tiny raindrops in the air. To see one, you need both sunshine and rain at the same time.
White Light Holds Every Color
The starting point for understanding rainbows is sunlight. Although it appears white, sunlight is actually made up of all the colors of the spectrum mixed together. Each color is a slightly different wavelength of light, and importantly, each color bends by a slightly different amount when it passes from one material into another. This bending of light is called refraction, and it is the heart of how a rainbow's colors get separated.
Inside a Raindrop
When a ray of sunlight strikes a raindrop, three things happen in sequence. First, the light enters the drop and refracts, bending as it slows down in the water, and because each color bends differently, the colors begin to spread apart. Second, the light travels to the back of the drop and reflects off the inner surface, bouncing back. Third, as the light exits the drop, it refracts again, spreading the colors even further apart. The result is that white sunlight is split into a band of separate colors.
Why It Looks Like an Arc
A single raindrop sends out separated colors, but a full rainbow needs millions of raindrops. Each drop sends light to your eyes at a specific angle, and only drops sitting at the right angle relative to the Sun and your eyes deliver their color to you. All the drops at that correct angle together form the curved shape of the rainbow. This is also why the Sun must be behind you when you see a rainbow, and why the bow always appears in the part of the sky opposite the Sun.
Source
This article was written using information from Wikipedia.