As sunlight enters the Earth's atmosphere, it passes through layers of air with varying densities. This causes the light rays to bend, or refract. Near the horizon, where sunlight travels through a larger amount of atmosphere, this refraction is significant. The atmosphere bends the light rays downwards, towards the Earth's surface. This bending makes the Sun appear higher in the sky than its actual position. As a result, we see the Sun before it has actually risen above the horizon (advanced sunrise) and after it has actually set below the horizon (delayed sunset).