Light travels at different speeds in different substances. But it always takes a path that is locally fastest - meaning that any nearby path would be slower. (This is called the Fermat principle.)
You can see this principle at work when you put a stick into water. Because light travels more slowly in water, the light first heads mostly straight up, then bends when it hits the air. The result is that light does not travel a straight path to your eye. Which means that the part of the stick in the water looks like it is where the light comes out of the water, rather than where the stick is. As a result you can see the stick visibly bend.
Now what is happening here is that you have a layer of warm air over cold air. Light travels faster in warm air. (That is because as air warms it expands, making it less dense. Less dense means that there is less getting in the way of the light and it can move faster.) Therefore that fastest path is for the light to go up into the warm air, go along the warm air, and then dive back down to your eyes.
In many places you can see the reverse of this on hot days where hot ground makes for a hot air layer next to the ground. When the conditions are right the light from the sky can reach your eyes by skimming along the ground, and you get blue patches in the ground. In a desert this can look like water in the distance.