Stars twinkle because of turbulence in the Earth’s atmosphere. While this certainly answers the question, it’s not an answer that the average joe can relate to, so here’s the answer explained using everyday terms and objects.
Have you ever seen the air shimmer on a hot day? This is due to warm air rising up. As warm air refracts light differently from cold air, when it slowly rises from the ground, light is refracted as it travels through cold air to hot air and refracted once again when it passes through hot air to cold air. This is similar to what is happening in the Earth’s atmosphere.
Now, the atmosphere of the Earth has hot air that rises up, and is cooled down as it goes higher. Light travelling from the stars has to pass through the Earth’s atmosphere before it reaches us standing here on Earth. As it passes through the atmosphere, it is refracted when it passes from cold air to hot air and from hot air to cold air. As the air in the atmosphere is in a constant state of motion, light from a particular star may have been refracted a certain way when it reaches us, but it would have been refracted differently the next moment. This results in the stars appearing to move around to our eyes. However, as the “movement” is too small for us to register, what we actually see is the stars twinkling. Astronauts who leave the Earth’s atmosphere have found that the stars do not twinkle for them, as there is no light refraction happening for them.
One of the first few questions that people ask when they join an astronomy club, is how to tell a planet from a star. (Or at least it was one of the first few questions for me) The answer is that planets don’t twinkle like stars. The reason for this is because planets are nearer to us than stars, so there are a larger number of light rays from the planet from the planet, while the light from a planet still gets refracted, what we see is the overall effect on the light rays and we see a steady image. This isn’t necessarily true though, as planets can still be seen to be twinkling if there is especially turbulent air.
Another effect light refraction has on a star is that it can actually cause a star to change colors. Blue and green light get bent more than orange and red, resulting in the effect that some stars appear to be changing colors rapidly when we observe them. This is more likely to happen when the star is low on the horizon, as there is more air for it to pass through before it reaches our eye.
So now you know why stars twinkle. Happy star-gazing!