Mirage occurs due to total internal reflection of light. When the sun is high in the sky, the sand gets heated first and then the layers of air above it. The rays from the trees travel from an optically denser air layer to a rarer layer and hence bend away from the normal. This bending continues and a stage is reached where the angle of incidence becomes greater than the critical angle and total internal reflection takes place. The totally reflected rays that reach the eyes appear to come from a point on the ground where the image of the tree is formed. Thus one sees an inverted image of the tree though there is no water around.