MechSimulator

Ideal Gas Law Calculator & Simulator

PV = nRT — Animate Gas Particles • Simulate • Explore • Practice • Quiz

MODE
UNITS
CALCULATE
MODEL
PRESET
PV = nRT P = 101.3 kPa V = 22.41 L n = 1.000 mol T = 273.2 K
Display Controls
SOLVE FOR
GAS
P
Pressure kPa
101.3 kPa
V
Volume L
22.41 L
T
Temperature K
273.2 K
n
Amount mol
1.000 mol
Molar mass M28.970 g/mol
Mass m = nM28.970 g
Density ρ1.2923 kg/m³
Specific gas const. Rs287.0 J/(kg·K)
RMS speed vrms485.0 m/s
Compressibility Z1.0000+0.00% from ideal
📖 Learning panels
Σ Live equations — values substituted from the current state
Gas properties — mass, density, Rs, molecular speed
Real vs ideal — compressibility factor Z
💡 What-if coach — what to try next
User Guide — Ideal Gas Law Calculator & Simulator
1 Overview

This tool is both a calculator and a simulator for PV = nRT. Type the three values you know, choose which of P, V, n or T to solve for, and read the answer — while animated molecules and a live p–V diagram show what the numbers mean. The universal gas constant R = 8.314462618 J/(mol·K), exact by definition since the 2019 SI revision, ties the four state variables together.

Beyond the single-state solve there are three further engines: a State Change tab for the combined gas law P₁V₁/(n₁T₁) = P₂V₂/(n₂T₂) with p–V work, a real-gas model using the van der Waals equation with a live compressibility factor Z, and a set of derived properties — mass, density, specific gas constant and RMS molecular speed — that follow whichever of the four gases you select.

2 Using it as a calculator
Close-up of the simulator canvas: animated air molecules in a piston container on the left, pressure-volume diagram with isothermal curves and the state dot on the right

Pick the unknown with the Solve For row (P, V, T or n). That variable's card turns purple and shows a COMPUTED badge; its input becomes read-only and displays the answer. Type the other three straight into the number boxes — every value is accepted exactly, so 298 K, 101.325 kPa or 0.037 mol all go in as typed. The slider beside each box is a convenience for sweeping, not the only way in; it is logarithmic for P, V and n so a single track covers 1 kPa to 300 bar, 10 mL to 500 L and 1 mmol to 200 mol.

The answer is never clipped to the slider. If the solution falls outside the slider's span the number is still exact and a note appears explaining that only the slider thumb has stopped at its limit. Press Show Calculation (bottom-right of the canvas) for the full worked derivation: the rearranged formula, the substitution in SI units, the compressibility factor and the mass and density of the charge, all typeset in classical notation.

Six presets load standard conditions in one click — STP, NTP, room air, a car tyre, a 200 bar scuba cylinder and a helium balloon. The SI / Imperial switch reads the same state in US units: psi, cubic feet, °F (with °R alongside, since PV = nRT needs an absolute scale), plus density in lb/ft³ and the specific gas constant in ft·lbf/(lb·°R), where air reads the familiar 53.35. Amount of substance stays in moles, because the mole is SI and used worldwide.

3 The State Change tab — combined gas law

Switch Calculate to State Change when a gas moves from one state to another. Enter state 1 in full, choose a process, then pick which state-2 value to solve for. The process locks whatever it holds constant: Isothermal fixes T₂ = T₁ (Boyle), Isobaric fixes P₂ = P₁ (Charles), Isochoric fixes V₂ = V₁ (Gay-Lussac), Avogadro fixes both P and T, and General leaves everything free.

By default the system is sealed, so n₂ = n₁. Untick n₂ = n₁ to add or remove gas — topping up a tyre, bleeding a receiver, filling a cylinder — and the tool uses the general form P₁V₁/(n₁T₁) = P₂V₂/(n₂T₂) instead of the fixed-mass combined gas law.

The canvas switches to a full-width p–V process diagram showing both states, an arrow along the path and the shaded area beneath it. That area is the work W = ∫p dV, reported in joules (1 kPa·L = 1 J exactly). Work is path-dependent, which is why you must choose a process: the isothermal path uses W = nRT ln(V₂/V₁), the isobaric path W = PΔV, the isochoric path is zero, and the General case states openly that it assumes a straight line on the diagram.

4 Reading the animation

The left panel is an idealised container whose width tracks the volume. Molecular speed follows vrms = √(3RT/M), so it responds to both temperature and the gas you choose: at the same temperature helium moves about 2.7× faster than air, and CO₂ about 20% slower. The colour shifts from blue (cold) to orange-red (hot), and the dot count is proportional to n up to a display cap.

The right panel plots the p–V diagram with isotherms at T/2, T and 2T. Hover an isotherm to read its temperature; click the glowing state dot (or press Space while the canvas has focus) to project dashed lines onto both axes. A dashed trail records where the state has been. The Display Controls panel at the top-left of the canvas switches the grid, isotherms, trail, particles, equation overlay and work shading on or off independently.

Try the classic check: load the STP preset. It sets n = 1 mol, T = 273.15 K and P = 101.325 kPa and solves for V, giving 22.41 L — the standard molar volume, straight out of PV = nRT.

5 Real gases and the compressibility factor

The Model switch changes the equation the tool solves. Ideal uses PV = nRT. Real (vdW) uses the van der Waals equation (P + an²/V²)(V − nb) = nRT, where a corrects for intermolecular attraction and b for the volume the molecules themselves occupy. Constants come from the CRC Handbook for the pure gases; the air figures are mole-weighted from nitrogen, oxygen and argon and are therefore an estimate for a mixture.

The Compressibility Z card reads Z = PV/(nRT) at all times, and highlights itself once the deviation from 1 exceeds 1%. A worked demonstration: choose CO₂, solve for P with n = 1 mol, T = 300 K and V = 0.5 L. The ideal law predicts 4989 kPa; van der Waals gives 3994 kPa and Z = 0.80. A 20% error is not a rounding difference — that is the point of the switch.

Note where the model itself runs out. On the Scuba preset (200 bar air) van der Waals returns Z = 0.98, while the measured value is about 1.04. With only two constants it cannot track a real gas once the density is that high — it gets the size of the deviation roughly right and its direction wrong. Treat it as a teaching model, not a design tool above about 50 bar.

6 Explore, Practice and Quiz

Explore holds five sets of concept cards: Gas Laws, Ideal Gas Equation, Combined Gas Law, Real Gases and Applications. Each card carries a formula, a one-paragraph explanation and a worked numerical example.

Practice generates randomised problems across nineteen templates: the four direct PV = nRT solves, Boyle, Charles, Gay-Lussac, Avogadro and combined-law changes of state, Dalton partial pressures, scuba and tyre scenarios, and the newer derived quantities — mass from moles, density, specific gas constant, RMS molecular speed, compressibility factor and constant-pressure work. Enter a numeric answer and press Check; grading allows 2% so ordinary rounding passes. Show Solution reveals the step-by-step working, and your score persists for the browser session.

Quiz presents five multiple-choice questions drawn at random from a pool of twenty-three, each with an explanation shown after you answer. The pool covers the classical laws, the value and units of R, absolute temperature, work, density, molecular speed, the van der Waals constants and the meaning of Z.

7 Exporting, shortcuts and engineering notes
  • Export CSV writes the full state, every derived property and a 25-point sweep of the current isotherm — or, in State Change mode, both states plus the sampled process path. Everything is in SI with the units in the header, which is what a lab report needs.
  • Save PNG exports the diagram with a mechsimulator.com watermark. Right-click the canvas for Copy state values, Export CSV, Export PNG, Toggle grid and Reset all.
  • Keyboard: Space or Enter toggles the axis projection when the canvas has focus (click it first — elsewhere on the page Space still scrolls normally). Esc closes the calculation modal and the right-click menu.
  • Pressure must always be absolute. A tyre placard quoting 220 kPa means gauge; add roughly 100 kPa of atmosphere before using it in PV = nRT.
  • Remember that 1 kPa·L = 1 J exactly. That is why the same number 8.314 serves as R in both J/(mol·K) and kPa·L/(mol·K), and why the work readout in the State Change tab is already in joules.
  • Watch the isotherms: the further from the origin, the hotter. At a given pressure a hotter gas occupies more volume — the whole of Charles' Law in one picture.
  • Study each sub-law on its own with the Boyle's Law Simulator and the Charles' Law Simulator before tackling combined-law problems here.

How to Use the Ideal Gas Law Simulator — PV = nRT

Ideal gas law calculator at STP: the Calculate, Model and Preset controls across the top, the PV = nRT banner reading P = 101.3 kPa, V = 22.41 L, n = 1.000 mol, T = 273.1 K, a container of animated air molecules on the left, and a pressure-volume diagram on the right with isothermal hyperbolas at T over 2, T and 2T and the state dot at 22.41 L, 101.3 kPa
The STP preset, solving for volume: one mole of air at 101.325 kPa and 273.15 K occupies 22.41 L. Molecular speed follows √(3RT/M), so the particles respond to both temperature and the gas selected; the state dot rides its isotherm as you change any input. Every canvas action sits in the ribbon below.

The ideal gas law, PV = nRT, links the pressure, volume, amount and absolute temperature of a gas through one constant: R = 8.314462618 J/(mol·K). Give this free calculator any three of the four and it returns the fourth exactly, with the full worked derivation, while animated molecules and a live p–V diagram show what the answer means. A second tab solves the combined gas law between two states, and a van der Waals mode shows where the ideal model breaks down.

Understanding PV = nRT — the four variables

P is absolute pressure, V is volume, n is the amount of substance in moles and T is absolute temperature. The Solve For row picks which one the calculator computes: choose Pressure P to see what a compression does; Volume V to size a balloon, a cylinder or a receiver; Temperature T to find the temperature a given pressure implies; Moles n to work out how much gas is actually in a vessel. Every other value is typed in directly, so real numbers like 298 K or 101.325 kPa go in exactly as written rather than being snapped to a slider step.

Which units go into PV = nRT?

This is where most marks are lost, and the rule is simple: R must match the units you use. Three combinations cover almost everything.

PVTValue of R
PaK8.314462618 J/(mol·K)
kPaLK8.314462618 kPa·L/(mol·K)
atmLK0.0820573 L·atm/(mol·K)
barLK0.083145 bar·L/(mol·K)
psiaft³°R10.7316 psia·ft³/(lbmol·°R)

The second row is the useful trick: 1 kPa·L equals exactly 1 joule, so the familiar 8.314 works unchanged with kilopascals and litres. That is the system this calculator solves in internally. Two rules admit no exceptions. Temperature must be absolute — kelvin, or Rankine if you are working in Fahrenheit — because the equation says pressure vanishes when T reaches zero, and a Celsius value makes every ratio meaningless. Pressure must be absolute too: a tyre placard reading 220 kPa is gauge pressure, so add about 100 kPa of atmosphere before it enters the equation.

Where the value of R comes from

Since the 2019 revision of the SI, R is defined rather than measured. It is the product of two exact constants, R = NAkB = 6.02214076×10²³ × 1.380649×10⁻²³, giving 8.314462618 J/(mol·K) with no uncertainty at all. NIST and CODATA publish it under “molar gas constant”. Textbooks round to 8.314, which is 6 parts per million low — far below any laboratory tolerance. This calculator uses the exact value and prints 8.3145 in its worked solutions, so hand-checking with 8.314 will always agree to the displayed digits.

The combined gas law — calculating a change of state

Most exam questions are not a single state but a change: a gas goes from P₁, V₁, T₁ to P₂, V₂, T₂. Because PV/(nT) equals R at both ends, the two states are tied together by

ProcessHeld constantRelationWork W = ∫p dV
GeneralP1V1/(n1T1) = P2V2/(n2T2)Depends on the path
Combined gas lawnP1V1/T1 = P2V2/T2Depends on the path
Isothermal (Boyle)T, nP1V1 = P2V2nRT ln(V2/V1)
Isobaric (Charles)P, nV1/T1 = V2/T2PΔV
Isochoric (Gay-Lussac)V, nP1/T1 = P2/T20
AvogadroP, TV1/n1 = V2/n2PΔV

The State Change tab implements all six. Enter state 1, pick the process, and choose whether P₂, V₂ or T₂ is the unknown — the process greys out whatever it holds fixed, so an isothermal problem will not let you ask for T₂. Untick n₂ = n₁ when gas is added or removed and the tool switches to the general form. The canvas draws the process path on the p–V plane and shades the area under it, because that area is the work, reported in joules. Work depends on the route, not just the endpoints, which is exactly why the process has to be named before the number means anything.

Finding mass and density with the ideal gas law

Engineers rarely want moles; they want kilograms. Substituting n = m/M turns the equation into two forms that appear constantly in thermodynamics and fluid mechanics:

For air, M = 28.97 g/mol gives Rs = 8.3145/0.02897 = 287.0 J/(kg·K), or 53.35 ft·lbf/(lb·°R) in US units. Put 101.325 kPa and 273.15 K into the density form and you get 1.292 kg/m³, the standard density of dry air at 0 °C. The calculator reports M, m, ρ, Rs and the RMS molecular speed as readout cards for whichever of the four gases is selected.

What the particle animation shows

Molecular speed follows vrms = √(3RT/M), and the animation obeys it in both variables. Raise the temperature and the molecules speed up as √T; change the gas and they respond to its molar mass. At 300 K helium averages 1368 m/s against air's 508 m/s — a factor of √(28.97/4.003) = 2.69, visible immediately on screen. Colour runs from blue (cold) to orange-red (hot), the container width tracks the volume, and the dot count follows n, so density on screen behaves like n/V. On the right, the state dot rides its isotherm as you move the sliders, with a dashed trail showing where it has been.

The car tyre worked example — why your pressure climbs in summer

A tyre is inflated to 220 kPa gauge (320 kPa absolute) on a cool spring morning at 15 °C (288.15 K). By mid-afternoon under direct sun it reaches 50 °C (323.15 K). The volume is essentially fixed, so this is isochoric.

StepWorkingResult
Use the Gay-Lussac form: P/T = constantP2 = P1 × (T2/T1)
Plug in absolute valuesP2 = 320 × (323.15/288.15)P2 = 358.9 kPa absolute
Convert back to gauge358.9 − 100258.9 kPa gauge (~37.5 psi)
Pressure rise258.9 − 220+38.9 kPa (~5.6 psi)

Almost 6 psi of rise from the same air in the same tyre — which is why manufacturers specify a cold inflation pressure. Reproduce it in the tool by opening State Change, choosing the Isochoric process, entering P₁ = 320 kPa, V₁ = 30 L, T₁ = 288.15 K and T₂ = 323.15 K, and solving for P₂. The work readout will show W = 0, because a rigid tyre does none.

Where real gases stop being ideal

The ideal gas law assumes molecules occupy no volume and do not attract one another. Both are false, usually by amounts small enough to ignore. The measure of how wrong you are is the compressibility factor Z = PV/(nRT), which equals 1 for a perfect gas and is displayed live in the calculator.

Switch Model to Real (vdW) and the tool solves the van der Waals equation (P + an²/V²)(V − nb) = nRT instead, where a corrects for attraction and b for molecular volume. A striking case: one mole of CO₂ at 300 K squeezed into 0.5 L. The ideal law says 4989 kPa; van der Waals says 3994 kPa, with Z = 0.80. That 20% gap is not a rounding artefact — it is the reason real-gas equations exist.

van der Waals has its own limits, and the tool will show you one. Load the Scuba preset (12 L at 200 bar, 20 °C) and switch to Real: it returns Z = 0.98 and 100.4 mol against the ideal 98.5. But the measured Z for air at 200 bar is about 1.04 — above 1, not below. With only two parameters, van der Waals still has the attraction term winning at a density where, in reality, the molecules' own volume has already taken over. It is right that the gas is not ideal and right about the order of the error; it has the sign wrong. That is why high-pressure design work uses compressibility charts, Redlich–Kwong or Peng–Robinson, or NIST reference data rather than the two-constant equation.

Gasa (L²·bar/mol²)b (L/mol)Critical Tc (K)
Helium (He)0.03460.02385.2
Nitrogen (N2)1.3700.0387126.2
Oxygen (O2)1.3820.0319154.6
Air (mole-weighted estimate)1.3720.0372132.5
Carbon dioxide (CO2)3.6580.0429304.1

Constants for the pure gases are from the CRC Handbook; the air row is mole-weighted from nitrogen, oxygen and argon and is an estimate for a mixture rather than a measured constant. Note that the van der Waals constants themselves predict the critical temperature, Tc = 8a/(27Rb) — for CO₂ that gives 304 K against a measured 304.13 K.

The four sub-laws that live inside PV = nRT

Hold any two of the four variables constant and the equation collapses to one of the historical gas laws. Each is worth knowing in its named form, and each is a preset or a process in this tool:

Ideal gas law — forms and constants

FormEquationConstant
Standard (moles)PV = nRTR = 8.314462618 J/(mol·K)
Per unit massPV = mRsTRs = R/M (specific gas constant)
Density formP = ρRsTAir: Rs = 287.0 J/(kg·K)
Molecular (kinetic theory)PV = NkBTkB = 1.380649×10⁻²³ J/K
Combined gas lawP1V1/T1 = P2V2/T2Constant n
Real gas (van der Waals)(P + an²/V²)(V − nb) = nRTa, b per gas

Standard conditions and gas properties

GasMolar Mass (g/mol)Rs (J/kg·K)γ (Cp/Cv)vrms at 293 K (m/s)
Air28.97287.01.40502
Nitrogen (N2)28.01296.81.40511
Oxygen (O2)32.00259.81.40478
Carbon Dioxide (CO2)44.01188.91.29408
Helium (He)4.0020771.671352
Hydrogen (H2)2.0241241.411904
Methane (CH4)16.04518.31.31675

STP (standard temperature and pressure) is T = 273.15 K (0 °C) and P = 101.325 kPa, where one mole of an ideal gas occupies 22.414 L. Beware the competing definition: IUPAC has used 100 kPa as standard pressure since 1982, which gives a molar volume of 22.711 L/mol instead. NTP normally means 20 °C and 101.325 kPa, giving 24.055 L/mol. Load the STP and NTP presets and solve for V to see both.

Explore Related Simulators

To deepen your understanding of gas laws, explore our Boyle’s Law Simulator for PV isotherms, the Charles’ Law Simulator for isobaric expansion and absolute zero, the Specific Heat Capacity Simulator comparing Q = mcΔT across materials, the Thermodynamics Cycles Simulator covering Carnot, Otto, and Diesel cycles, and the Rankine Cycle Simulator for steam power plants.

🔒 Solving for P — adjust other variables