Gas Density Calculator – Density of an Ideal Gas ρ = PM/RT
Use this free Gas Density Calculator to find the density of an ideal gas from ρ = PM/(RT). Pick a gas (or enter a custom molar mass), then enter the pressure and temperature — the tool gives the density in kg/m³.
Density is the most tangible property a gas has. A litre of air weighs barely a gram, a litre of carbon dioxide noticeably more, a litre of hydrogen almost nothing — and those small differences steer balloons, pool suffocating gases in cellars, thin the air on mountains and decide how hard an aeroplane wing can push. For a liquid, density is a fixed fingerprint of the substance. For a gas it is a negotiation among three variables: squeeze the gas and it densifies, heat it and it thins, and swap in heavier molecules and it grows heavier in exact proportion. The formula ρ = PM/(RT) is that negotiation written in one line.
The equation is not a new law bolted onto physics; it is the ideal gas law wearing a different coat. Start from PV = nRT, replace the amount n with mass divided by molar mass, and divide both sides by the volume — density, mass per volume, is what remains. That ancestry is reassuring: it means gas density inherits the ideal gas law's wide range of accuracy at ordinary conditions, and it means the three levers in the formula are the only levers there are. Pressure pushes density up one-for-one, temperature pulls it down one-for-one, and molar mass scales it exactly.
One consequence deserves attention before any numbers: at the same pressure and temperature, the density of a gas depends on nothing but its molar mass. A container of oxygen and a container of nitrogen at the same P and T differ in density by precisely the ratio 32:28, because each holds the same number of molecules per litre (Avogadro's principle) and only the mass per molecule differs. This is why the calculator's gas menu is really just a list of molar masses — pick any gas, or type any M, and the physics is identical.
Formula
ρ = PM/(RT) — where P is the pressure (Pa), M is the molar mass (kg/mol), R = 8.314 J/(mol·K) is the ideal gas constant and T is the absolute temperature (K). This comes from rearranging the ideal gas law PV = nRT with n = mass/M. Density is directly proportional to pressure and molar mass, and inversely proportional to temperature.
The rearrangements are worth having at hand: P = ρRT/M if you know a density and want the pressure it implies, T = PM/(ρR), and M = ρRT/P — the last being a classical laboratory method for identifying an unknown gas: measure its density at a known P and T and its molar mass, hence often its identity, falls out. This calculator accepts pressure in kPa and molar mass in g/mol and converts both internally (×1,000 and ÷1,000 respectively), so the answer arrives in kg/m³. Note the happy coincidence that a density in kg/m³ is numerically the same in g/L — 1.29 kg/m³ of air is 1.29 grams in every litre.
| Symbol | Meaning | Units |
|---|---|---|
| ρ | density — mass per unit volume | kg/m³ (= g/L) |
| P | pressure (absolute) | Pa in the formula; kPa in this calculator |
| M | molar mass of the gas | kg/mol in the formula; g/mol in this calculator |
| R | ideal gas constant, 8.314 | J/(mol·K) |
| T | absolute temperature | kelvin (K) |
Three levers, three different stories
Pressure is the straightforward lever: at fixed temperature, doubling the pressure doubles the density, because the same molecules are pressed into half the space. This is Boyle's law hiding inside the density formula, and it is why a scuba tank at 200 bar holds roughly two hundred times the air of the same tank open on the deck — and why "how much gas is in the cylinder?" is always secretly a density question.
Temperature is the subtle lever, because its effect depends on the container. In a sealed rigid tank, heating changes the pressure, not the density — the mass and volume are both locked. In an open or flexible system at constant pressure — the atmosphere, a balloon, a room — heating expands the gas, mass escapes or spreads, and density falls as 1/T. Nearly every density problem in nature is the second kind: the air above a hot road thins and shimmers, the air over a mountain is thin because pressure has fallen, and both effects multiply in the formula.
Molar mass is the silent lever. It never changes during a process — a gas keeps its molecules — but it sets the scale of everything: at STP the densities of hydrogen (M = 2) and carbon dioxide (M = 44) stand 22 to 1 apart purely because their molecules do. When a problem asks which gas pools on a floor and which hugs a ceiling, it is asking about M and nothing else.
How to use
- Choose a gas from the list — the molar mass box fills in automatically — or pick "Custom" and type any molar mass in g/mol.
- Enter the pressure in kPa (normal atmospheric pressure ≈ 101.325 kPa).
- Enter the temperature and pick °C or K; the tool converts to kelvin for you.
- Click "Calculate Density" to get ρ in kg/m³ (the same number is the density in g/L).
- Use absolute pressure, not gauge pressure: if a gauge reads 200 kPa above atmosphere, the P for this formula is about 301 kPa.
Worked examples
Example 1 — air at STP. Find the density of air (M = 29 g/mol) at standard pressure 101.325 kPa and 0 °C (273.15 K).
ρ = PM/(RT) = (101,325 × 0.029) / (8.314 × 273.15) = 2938.43 / 2270.97 = 1.29 kg/m³
That matches the textbook density of dry air at 0 °C. (Warm it to 25 °C and the same formula gives a lighter 1.19 kg/m³.)
Example 2 — carbon dioxide, the floor-pooler. CO₂ (M = 44 g/mol) at the same STP conditions:
ρ = (101,325 × 0.044) / (8.314 × 273.15) = 1.96 kg/m³ — about 1.5 times air, exactly the molar-mass ratio 44/29. Released in a still room, it sinks and spreads along the floor.
Example 3 — hydrogen, the ceiling-hugger. H₂ (M = 2 g/mol) at STP:
ρ = (101,325 × 0.002) / (8.314 × 273.15) = 0.09 kg/m³. A cubic metre of hydrogen weighs about 90 grams — less than an apple — which is why hydrogen leaks in a building collect at the ceiling.
Example 4 — mountain air. At a high pass the pressure is 70 kPa and the temperature −5 °C (268 K). For air:
ρ = (70,000 × 0.029) / (8.314 × 268) = 0.91 kg/m³ — about 30% thinner than at sea level, from the combined fall in P and the modest fall in T. Climbers and carburettors both feel that missing 30%.
Example 5 — oxygen in a cylinder. Oxygen (M = 32) stored at 10,000 kPa (100 bar) and 20 °C (293.15 K):
ρ = (10,000,000 × 0.032) / (8.314 × 293.15) = 131.30 kg/m³ — denser than some woods. (At such pressures real oxygen deviates a few percent from ideal; the formula gives the engineering first estimate.)
Example 6 — helium lift. Helium (M = 4) at STP: ρ = (101,325 × 0.004) / (8.314 × 273.15) = 0.18 kg/m³. Each cubic metre of helium in air (1.29 kg/m³) therefore displaces 1.29 − 0.18 = 1.12 kg of lift — the number every balloon and airship is sized by.
There is a third way to feel the formula: at fixed pressure and temperature, density is a direct readout of molar mass — ρ ∝ M. That is why the table of gases in the quick reference below is ordered almost exactly by molecular weight, and why a leak of a heavy gas (propane, M = 44) pools at floor level while hydrogen (M = 2) collects at the ceiling. Gas detection, mine safety and the design of airships are all, at bottom, applications of that single proportionality: know M and the weather, and you know where the gas will go.
The same proportionality explains a quiet regularity in the atmosphere: well-mixed air keeps a nearly constant mean molar mass (28.97 g/mol) up to about 100 km, because turbulence stirs the gases faster than gravity can sort them. Above that height — the turbopause — stirring fails, each gas settles into its own scale height, and the atmosphere separates by mass, light gases floating to the top. The density formula does not change up there; only M becomes a function of altitude, one more variable the same equation absorbs without complaint.
Gas density in real life
Balloons and airships. Lift is a density difference, nothing more: the craft rises because the gas inside (hot air, helium, hydrogen) is less dense than the air displaced. Every figure in balloon design traces back to this formula evaluated at the day's P and T.
Carbon dioxide hazards. Fermentation cellars, dry-ice stores and volcanic hollows share a danger: CO₂, 1.5× denser than air, pools invisibly at floor level and displaces oxygen. Density, computed exactly as in Example 2, is why the safety rule is "ventilate low, and never enter alone".
Aviation's density altitude. A wing and an engine both respond to air density, not altitude as such. On a hot day at a high airport the density may match conditions thousands of feet higher — pilots compute that "density altitude" from P and T with this very formula before trusting the take-off charts.
Gas leak safety. Natural gas (mostly methane, M = 16, ρ ≈ 0.71 kg/m³ at STP) rises and disperses at ceiling level, so its detectors mount high; LPG (propane, M = 44, ρ ≈ 1.96 kg/m³) sinks, so its detectors mount near the floor. The detector's address is chosen by a density calculation.
Weather and convection. The atmosphere is a density machine: sun-warmed air thins, rises, and is replaced by cooler denser air — the engine of winds, thermals that glider pilots ride, and the shimmer above hot tarmac, where light bends through air of rapidly varying density.
Industrial gas metering. Gas is sold by energy content but measured by volume, so flow computers continuously convert using density from P, T and M — custody transfer of natural gas worth millions rides on ρ = PM/(RT) and its real-gas corrections.
Density in the real atmosphere: two effects at once
Climb a mountain and both levers move against you: pressure falls steeply (roughly halving every 5.5 km) while temperature falls gently (about 6.5 K per kilometre in the lower atmosphere). Because ρ follows P directly but only 1/T, the pressure effect wins easily, and air thins with altitude almost exponentially. At 5,500 m the pressure is near 50 kPa and, at a typical 250 K, ρ ≈ (50,000 × 0.029)/(8.314 × 250) ≈ 0.70 kg/m³ — barely over half the sea-level value despite the cold partially compensating. This is the physics behind altitude sickness, jet-engine derating and the reason Everest's summit air, at about a third of sea-level pressure, delivers roughly a third of the oxygen per breath: the fraction of oxygen is unchanged, but the density — the molecules per lungful — is not.
When gases stop being ideal: the compressibility factor
The formula assumes molecules take up no space and never attract each other. Real gases forgive those assumptions at low pressure, then stop forgiving. Engineers patch the law with a compressibility factor Z: ρ = PM/(ZRT), where Z drifts from 1 as conditions harden. For air at 100 bar, Z ≈ 1.05; for carbon dioxide near its critical point (31 °C, 74 bar), Z can plunge towards 0.3 as the gas hovers on the edge of liquefying, and the simple formula can misjudge density by tens of percent. The practical rule: below about 10 bar and well above the gas's boiling point, ρ = PM/(RT) is accurate to about a percent; beyond that, look up Z for your gas and conditions — the calculator gives the ideal baseline that every correction starts from.
Quick reference: densities of common gases at STP (0 °C, 101.325 kPa)
| Gas | M (g/mol) | Density (kg/m³) |
|---|---|---|
| Hydrogen H₂ | 2 | 0.09 |
| Helium He | 4 | 0.18 |
| Methane CH₄ | 16 | 0.71 |
| Ammonia NH₃ | 17 | 0.76 |
| Air (dry) | 29 | 1.29 |
| Oxygen O₂ | 32 | 1.43 |
| Carbon dioxide CO₂ | 44 | 1.96 |
Every row is the same calculation with a different M — divide any density in the table by air's 1.29 and you recover the gas's molar mass relative to air, the quickest identity check in gas work.
Common mistakes
- Feeding in gauge pressure. The formula wants absolute pressure. A tyre gauge reading of 250 kPa means roughly 351 kPa absolute; using 250 understates the density of the air inside by nearly 30%.
- Using Celsius for T. At 25 °C the kelvin value is 298.15; plugging in 25 makes the density come out almost twelve times too large. The calculator converts for you if you select °C — but only if you select it.
- Mixing up M's units. Inside the raw formula M must be in kg/mol (0.029 for air). The calculator accepts g/mol (29) and converts; doing the sum by hand with 29 and pascals inflates the answer a thousandfold.
- Assuming heating a sealed tank thins the gas. In a rigid sealed container the density cannot change — mass and volume are both fixed. Heating raises the pressure instead. Density falls on heating only when the gas is free to expand at constant pressure.
- Trusting the ideal formula at extreme pressure. At hundreds of bar, or near liquefaction, real gases deviate by percent to tens of percent (the compressibility factor Z). The ideal value is the right starting point, not always the final answer.
FAQ
Why does a gas get less dense when heated at the same pressure?
ρ = PM/(RT): temperature sits in the denominator. In an open container the pressure stays fixed, so hotter gas expands — the same mass spreads over a bigger volume and the density falls. That is why hot air rises and balloons float.
Why is carbon dioxide denser than air?
At the same P and T, density is proportional to molar mass. CO₂ has M = 44 g/mol against air's ≈ 29 g/mol, so CO₂ is about 1.5× denser — which is why it pools in low places and pours "downhill" in demonstrations.
When does this formula fail?
It is exact only for an ideal gas. At very high pressures or near the point where the gas liquefies, real gases deviate a little, but for everyday pressures and temperatures the result is accurate to well under 1%.
Why is the density in kg/m³ the same number as in g/L?
Because the units scale together: 1 kg/m³ = 1,000 g / 1,000 L = 1 g/L. So air at 1.29 kg/m³ is also 1.29 g per litre — a handy way to feel how light gases are.
Does humidity change air's density?
Yes, and counter-intuitively humid air is lighter: water vapour (M = 18) displaces heavier nitrogen and oxygen (M = 28–32), lowering the average molar mass. Saturated tropical air can be about 1% less dense than dry air at the same P and T — a small but real effect in aviation.
How dense is air at room conditions?
At 20 °C and 101.325 kPa, ρ = (101,325 × 0.029)/(8.314 × 293.15) ≈ 1.21 kg/m³. The often-quoted 1.225 kg/m³ is the sea-level value at 15 °C used as the aviation standard.
Can density identify an unknown gas?
Yes — rearrange to M = ρRT/P. Measure the density at a known pressure and temperature and the molar mass follows; combined with a little chemistry, that usually names the gas. It is one of the oldest identification tricks in the book.
Why do gases have such low densities compared with liquids?
Because gas molecules are far apart: in a liquid the molecules touch, in a gas at STP the average spacing is about ten molecular diameters, so roughly a thousandfold fewer molecules occupy the same volume — hence water at 1,000 kg/m³ against air at 1.29.
What is the density of steam?
At 100 °C and atmospheric pressure, water vapour (M = 18) gives ρ = (101,325 × 0.018)/(8.314 × 373.15) ≈ 0.59 kg/m³ — about half the density of the surrounding hot air would suggest, which is why steam rises vigorously from a kettle.
Does density depend on the container's size?
No. Density is intensive: a thimbleful and a warehouse of the same gas at the same P and T have identical densities. Double the container and you double both the mass and the volume, leaving ρ untouched.