Twinkling (scintillation) of stars is caused by the repeated refraction of starlight as it passes through the Earth's atmosphere. The atmosphere has layers of varying densities and temperatures, which cause random fluctuations in the refractive index. This leads to continuous changes in the apparent position and brightness of the star as the light path bends slightly differently each moment.