# How to calculate altitude from current temperature and pressure?

In a certain project, I need to calculate the altitude of the current location given the current location temperature and current location pressure. Temperature, pressure and altitude of a 'reference-level' could be provided if necessary (using a fixed sea-level pressure constant is also acceptable). This project is done between altitudes of-100 meters to 2000 meters above sea level.

This website uses the 'hypsometric formula':

$$h=\frac{((\frac{P_0}{P})^\frac{1}{5.257}-1)\times(T+273.15)}{0.0065}$$ given current location pressure, $P$, pressure at sea level, $P_0$, and current location temperature in Celsius, $T$.

However, I was also told by my friend that finding the altitude could also be calculated by the 'barometric formula': $$h=44330\times\left(1-\left(\frac{P}{P_0}\right)^\frac{1}{5.255}\right)$$ which is obviously not equivalent to the first equation. Furthermore, this formula doesn't allow changes in temperature.

The 'barometric formula' given in Wikipedia is also different;

$$P=P_b\times\left[ \frac{T_b}{T_b+L_b\times(h-h_b)} \right] ^ \frac{g_0M}{R^*L_b}$$

This formula uses more constant values including the universal gas constant, $R^*$, the gravitational acceleration, $g_0$ and the molar mass of Earth's air, $M$. However, this formula isn't what I was looking for because it appears that the temperature at current location isn't taken into account.

My question is what equation is used to calculate current location altitude given current location temperature and current location pressure (or, if no such equation exists, best suited in range from sea level to 2 km altitude).

All these formulas are actually equivalent when $P_b = P_0$, $T_b = 273.15 + T$, $T = 15$, $h_b = 0$ (sea-level), $L_b = -0.0065$ the standard lapse rate, and hence $\frac{g_0M}{R^*L_b} = -5.25579$.