A rainbow appears when a ray of sunlight hits droplets of moisture, usually raindrops, in the sky. You will a rainbow only if this occurs when the sun is low in the sky.
As light passes through an object, some of it will be reflected (mirror-image) and the rest will be refracted (bent). The amount of refracted light depends on the wavelength of each color in the spectrum of white light.
Each wavelength travels at a different speed. This speed changes as the droplet crosses to a medium that has a different density. Thus, hitting a droplet changes the speed at which the sunlight travels. Since the colors that make up the white light have different speeds, the white light separates into the colors of the rainbow. This process is known as dispersion.
The speed of the light is modified as it leaves the droplet. This time, the light is shifting from a denser medium (droplet) to a less dense medium (air). As this happens, the light increases its speed and the path bends away from the normal line. This is an example of refraction.
As the sunlight passes through the droplets, the light is refracted, then reflected from the back of the drop, and again refracted as it departs the droplet. The light is reflected back over a wide range of angles.
The white light runs into the water-to-air interface at the rear of the droplet. If the light is reflected at the rear of the droplet, you will see a rainbow appear. If light is not reflected this way, it will shine out the other side of the droplet and a rainbow will not appear.
As the light is bent once again, the different wavelengths will separate farther, and so will the component colors of the white light. This is the colorful rainbow that people enjoy seeing.
One can create a rainbow by standing opposite to the sun (180°) and spraying a mist in a circular motion.