Thisspost has been updated. It published on January 8, 2019.

Because of their colorful and unique display, rainbows have generated countless legends and myths throughout history. Among the most popular is the Irish folklore that leprechauns store their pot of gold at the end of a rainbow. But the truth is, rainbows can be seen only if you are in the right place at the right time.

If you’ve ever seen one, consider yourself lucky. For the magical band of the colors to appear, the conditions must be just right. Which leads us to the question, how are rainbows formed exactly?

Rainbows can be seen when light passes through raindrops, says Kristin Calhoun, a research scientist at the National Oceanic & Atmospheric Administration (NOAA), the scientific agency focusing in part on the conditions of weather.

When a person sees a rainbow, it’s really an optical illusion created by the refraction and reflection of light. An optical illusion is when you see something that appears to be something other than what is really there.

When sunlight passes through raindrops, the light bends, or refracts, as it enters the droplet, and then reflects off the inside of the raindrop. This happens because the water is more dense than the air that surrounds it. As it exits the droplet, the light separates into wavelengths. Visible light is made up of various wavelengths, and each wavelength appears as a different color: red, orange, yellow, green, blue, indigo and violet. Red light, for example, bends at a different angle than violet light.

This is why “the person on the ground sees each color at a different location,” Calhoun says, and why rainbows look like a bow or an arc. Sometimes, however, rainbows can actually form an entire circle that you can see in a plane with the right conditions.

[Related: What causes a rainbow at night?]

Because rainbows are created by light via raindrops, the best time to catch a rainbow is when it’s sunny and raining. “There is an even better chance when the sun is at a lower angle, so early or later in the day,” Calhoun says.

If you’re trying to spot one, the key is to face the rain and have your back to the sun.

With the conditions just right, Hawaii gets lots of rainbows. “Small showers and storms often form in late afternoon due to the combined effects of topography and daytime heating of the land,” Calhoun says. “These types [of] showers often produce heavy rain, but remain isolated over the center of the island.”

Because rainbows are optical illusions, they’re not located at a specific distance. The location is relative to the person. That means there’s no chance you’ll ever find that pot of gold.