Under standard conditions, temperature decreases about 2 C or 3.5 F. for each 1,000-foot increase in altitude. Variations to this standard are common and the standard decrease is not always found. For example, what is called a temperature inversion may actually cause an increase rather than a decrease in temperature at some locations. How much it changes in any direction is partially based on the extent to which Earth's surface area is exposed to the Sun, our primary source of heat. The Sun's rays penetrate the atmosphere and heat Earth's surface, which in turn heats the atmosphere next to it.
Atmospheric temperature is based on the amount of heat absorbed or reflected by the Earth's surface.
Sand, water, and forested surfaces differ in the amount of heat they absorb and reflect so the air over them will be heated differently. If a cubic foot of air on the Earth's surface is heated, the air will expand and rise in the atmosphere. This cubic foot of air may then occupy two cubic feet. Both its pressure and density will have decreased. As the air rises and expands, the heat it contains is spread over a larger area, and its temperature decreases with altitude.