The Earth is surrounded by layers of gases, which we call the the atmosphere. There are several layers, due to differences on density, temperature or pressure of the different gases.
Because starts are really far away, when the light that comes from them crosses the various layers of the Earth’s atmosphere, their light gets shifted side to side as they cross each layer. This appears to our eyes as twinkling, and the scientific term for this is scintillation.
If you were to look at the stars from outside the Earth’s atmosphere, they would not look like they twinkle.
Comments