We know that light refracts when it travels from one medium to another. Though the earth's atmosphere contains only air, refraction takes place because the atmosphere consists of layers of air that are at different temperatures. The layers of air that are hotter behave like an optically rarer medium and those that are cooler behave like an optically denser medium. Therefore, when light travels through these layers of air of different optical densities, bending of light, or refraction, takes place.