There is a good explanation of how this can be derived on Math24.net. it boils down to:
P at height h = Pressure at sea level x e^-(mgh/RT)
This looks slightly different to the one I posted from Wiki two days ago. In that version "m" is the mass per molecule, which is the mass of a mole of gas divided by the Avogadro Constant (6 x 10^23), and "k" is the Boltzmann Constant (1.38 x 10^-23). So you are dividing a tiny number by a tiny number.
In this version, "m" is the mass of a mole of 'air' (0.029 kg), and it uses "R" instead of "k". "R" is the Gas Constant, which is just Avogadro Constant x Boltzmann Constant = 8.314. So this saves you a lot of decimal places.
"g" is the same in both version, 9.8m/s^2, which falls only imperceptibly as you go up through the troposphere, so can be assumed to be constant.
If you have three constants, you can just multiply/divide them to give a single constant, which is 34.2. You can save more faff with decimal places if you express "m" in grams rather than kilograms and "h" in kilometres rather than metres.
The formula tells you the equilibrium/typical relationship* between height above sea level; pressure at that height; and temperature at that height (in K). There's no need to worry about what causes what, they all affect and are affected by each other. It's like balancing two playing cards edge to edge to form an inverted "V". Card A causes Card B to stay up and vice versa.
I tweeted Den Nikolov (@NikolovScience) and pointed out that the formula makes the same predictions as the much maligned Nikolov-Zeller Hypothesis. (If you Google it, you'll get a dozen articles claiming to refute it for every article that agrees with it). Therefore, I continued, if his theory is wrong, the formula must be wrong and vice versa (the fact that one is correct does not necessarily mean the other is also correct).
He agreed with both of those points, but told me that the Barometric Formula is standard physics text book stuff, they won't be able to pretend it isn't widely accepted (like air brushing the Roman and Mediæval Warm Periods out of the history books).
So no longer shall I use obscure terms like Gravity-Thermal-Effect or Atmospheric-Thermal-Effect or Nikolov-Zeller Hypothesis, I'm sticking with text book "Barometric Formula"!
----------------------
Next time I can be bothered to discuss this with somebody who claims that the Earth's surface is 33C warmer than it would be from sunlight alone because of Greenhouse Gases, I shall refer them to the the widely accepted and standard textbook Barometric Formula, which tells you the equilibrium/typical relationship* between altitude, pressure and temperature. It tells you that the surface (at sea level) will be +/- 33C warmer than it "should" be; it also tells you the "adiabatic lapse rate"; and as a bonus, that the top of Mount Everest will be much colder than it "should" be.
Bearing in mind the formula is based on Ideal Gas Laws, the results are surprisingly accurate*.
The Greenhouse theory is one possible explanation for higher-than-expected surface temperatures generally (and, to be fair, even if you accept the validity of the Barometric Formula, a possible explanation for the correlation between higher CO2 and slightly higher temperatures we have seen in the past few decades) but it offers no explanation for the lower-than-expected surface temperatures at high altitudes, which is the Barometric Formula's trump card.
(Of course, neither the Barometric Formula NOR the Greenhouse theory explain other climate changes over the past two thousand years - Roman Warm Period, Dark Ages Cold Period, Mediæval Warm Period, Little Ice Age, early 20th C warming, or mid/late 20th C cooling. The Barometric Formula does not purport to do so, and the Greenhouse theory has to be modified endlessly to get the facts to fit the explanation).
And as back up, I shall point out that the Barometric Formula applies to, and its effects can be observed on, all planets with an atmosphere, including Gas Giants, and that the vertical gradients apply at day (when surface is being warmed) and at night (when it isn't), over the sea (stable temperature) and over land (warms/cools).
----------------------
Hopefully this will be last time I ever have to post about this! I'm sure I've lost most of my audience by now, but I do like to get to the bottom of things :-)
----------------------
* Yes, I am perfectly aware that there is loads more stuff that influence conditions at any one place or point in time; at the Equator it will always be warmer than at the Poles; the seasons; sun spots and solar activity; cold or warm winds; high or low pressure; the jet stream; clouds; Hadley Cells; the coriolis effect; updrafts, downdrafts; weather inversions; the fact that most landmass is in the Northern Hemisphere; Pacific and Atlantic oscillations; volcanic eruptions; large forest fires; oceans warming and cooling more slowly than dry land does; the list is endless.
But they skew the results in all directions and on the whole, their net effect is close to zero. These things also affect local results if you subscribe to the Greenhouse Gas explanation, so aren't really relevant when comparing the merits of Barometric and Greenhouse Gas explanations.