In the troposphere, temperature decreases as altitude increases primarily because Earth's atmosphere is heated upward from the lowest level. Although sunlight passes through the higher altitudes to reach the surface of the Earth, the surface is much better at absorbing the solar heat.
Air is warmer near a heat source than the air farther from it, and the Earth is a heat source for the atmosphere. From the ground up, heat gradually radiates through the troposphere, with a portion of it radiating away into space. Additionally, air has low thermal conductivity by volume. As warm air rises and expands, it pushes off against existing atmosphere, but it transfers so little heat that the process results in a net loss of energy. However, there are exceptions known as temperature inversions, and these are caused by warm fronts, oceanic upwelling and other weather effects. Also, temperature decreases with altitude only in the troposphere and the mesosphere; in the thermosphere high above Earth, ultraviolet radiation, not the Earth's surface, is the primary source of heat, as it is in the stratosphere. The thermosphere has its name because individual air molecules may reach a temperature of 2,500 degrees Centigrade there. Beyond the thermosphere is the exosphere, which is the edge of space.