As a wise Muppet once said, rainbows are only illusions. They're the product of perception and do not physically exist. Speaking of things that aren't what they appear to be, let's talk sunlight. People tend to think the nearest star is yellow or orange, but if you viewed it from outer space — above Earth's atmospheric distortions — you'd see that the light produced by our sun actually looks white.
White light is a blend of all the different colors in the visible light spectrum. Each one travels at its own wavelength, with some being shorter than others.
Regardless of color, a beam of light's trajectory can change once it encounters a new medium. Air is less dense than water, and light that's passed through the former bends — or "refracts" — when it enters the latter.
Rainbows only become visible to us while large quantities of water droplets fill the air. And that's just one item on the checklist. To see a rainbow, you need to stand with your back to the sun. But if that big ball of plasma is obscured by clouds or precipitation, you won't get to witness any colorful arches. In order for a rainbow to appear, the sky around the sun has to be nice and clear.
Once all the criteria have been met, it's showtime. First, the sunlight emanating from behind you enters the water droplets. On their journey through a bead of H2O, the light's component wavelengths all bend at different angles and get separated. Next they'll hit the back of our droplet. Bouncing off of this, the wavelengths travel back toward you, refracting a second time over while they exit the water.
Here's where your eyeballs come in. Each droplet in the watery haze before you will only send out one color that's at the right angle to meet your eyes. Thus, the colors of the rainbow become segregated, with red at the top and violet at the bottom.
This is by no means the whole story; we haven't even mentioned the fact that rainbows are circular. But for now, let's move on to a more striking topic.