Look across a fire or a hot road: things behind seem to waver. The hot air is less dense and has a slightly lower refractive index than cooler air, and it keeps moving, so the apparent position of objects keeps changing. This is atmospheric refraction on a small scale.
Twinkling of stars: starlight passes through air layers whose refractive index increases closer to the ground, so it bends towards the normal all the way down. A star near the horizon therefore appears slightly higher than it really is. The air keeps changing, so this apparent position shifts a little, and the light entering the eye flickers: brighter, then fainter. Stars are so far away that they act as point sources, so the flicker shows.
Planets don't twinkle: they are much closer, so they look like extended sources: many point sources together. Their flickers average out to zero.
Advance sunrise and delayed sunset: refraction lets us see the Sun about 2 minutes before it actually crosses the horizon and about 2 minutes after it sets. The same effect makes the Sun's disc look flattened at sunrise and sunset.
Tap the diagram to enlarge it
- Stars: point sources twinkle
- Planets: extended, steady
- About 2 minutes early and late