When light enters from one medium to another, it deviates from its path and this phenomenon is called refraction of light. Atmosphere is composed of layers of optical densities and due to the variation in air density there is the deviation of light or other electromagnetic wave from a straight line when it passes through the atmosphere known as Atmospheric refraction.
Due to atmospheric refraction of starlight the star twinkles. When the starlight enters the earth's atmosphere it undergoes refraction continuously before reaching to the earth. The atmospheric refraction occurs in a medium of gradually changing refractive index. As the atmosphere bends starlight towards the normal, so the apparent position of the star is slightly different from its actual position.