Ideal-gas pressure, volume, amount or temperature, at a reference too
calc_gas_law
Works out the missing one of pressure, volume, amount and temperature by pV = nRT for an ideal, dry gas.
- Runs
- On the server
- Level
- Checked against a reference: NIST CODATA 2022 molar volumes of an ideal gas reproduced to every printed digit; exact rational arithmetic, against a second implementation in Python by a separate agent of the same model family
What it is
Returns the one of pressure, volume, amount and temperature not given, by pV = nRT for an ideal, dry gas. Use when converting litres of a gas to moles, or a gas volume to a reference condition you name or state. A bare STP or NTP is not accepted, and a gauge pressure needs the ambient pressure. Not for a pressure or volume unit alone: use `calc_unit_conversion`.
Field: Solutions and bench arithmetic.
What it does
You give
absolutePressure: Absolute pressure of the gas; or give gaugePressure with ambientPressure. Optional.gaugePressure: Gauge pressure, above (or below) the ambient pressure; needs ambientPressure. Optional.ambientPressure: Ambient (barometric) pressure, for a gauge pressure; never assumed; zero or above. Must be at least 0 Pa. Optional.volume: Gas volume. Must be above 0 L. Optional.amount: Amount of gas. Must be above 0 mol. Optional.temperature: Temperature of the gas. Must be above 0 K. Optional.
and 3 more, listed below
No request is recorded for this tool.
Limits
- Bench arithmetic on solutions you describe.
- Research and education software: it does not look up densities, check that a label is right, or assess hazards.
- Ideal-gas arithmetic on the pressure, volume, amount and temperature you give.
- The gas is taken as ideal and dry: no compressibility correction is made and no water vapour is subtracted.
- Pressure is absolute; a gauge pressure needs the ambient pressure, which is never assumed.
- A reference condition, when wanted, is named from the list or stated as a temperature and a pressure; a bare STP or NTP, or a mass-flow controller's standard litre, is not accepted, because the conditions they mean vary.
- Every computed number a reply returns, other than an integer or an exact decimal, is rounded once to 12 significant figures: to the nearest, a change of at most 5 × 10⁻¹² of its value, except that a lower bound is rounded down and an upper bound up, a change of less than 1 × 10⁻¹¹; the method computes, and decides any pass or fail, on the unrounded value.
It will not answer when
- not exactly three of pressure, volume, amount and temperature are given.
- both an absolute and a gauge pressure are given, or an ambient pressure without a gauge pressure.
- a gauge pressure is given without the ambient pressure, which is never defaulted.
- the absolute pressure, given or formed as gauge plus ambient, or a stated reference pressure, is zero or below.
Every input, with its units9 inputs
absolutePressure: Absolute pressure of the gas; or give gaugePressure with ambientPressure. Optional.gaugePressure: Gauge pressure, above (or below) the ambient pressure; needs ambientPressure. Optional.ambientPressure: Ambient (barometric) pressure, for a gauge pressure; never assumed; zero or above. Must be at least 0 Pa. Optional.volume: Gas volume. Must be above 0 L. Optional.amount: Amount of gas. Must be above 0 mol. Optional.temperature: Temperature of the gas. Must be above 0 K. Optional.referenceCondition: A named reference condition; the reply prints its temperature and pressure. A bare STP or NTP is not a choice. Optional.referenceTemperature: A stated reference temperature, with referencePressure, instead of a named condition. Must be above 0 K. Optional.referencePressure: A stated reference pressure, with referenceTemperature. Optional.
Every refusal, with its code5 refusals
| Code | When |
|---|---|
STATE_COUNT | not exactly three of pressure, volume, amount and temperature are given. |
PRESSURE_ARGUMENTS | both an absolute and a gauge pressure are given, or an ambient pressure without a gauge pressure. |
GAUGE_WITHOUT_AMBIENT | a gauge pressure is given without the ambient pressure, which is never defaulted. |
PRESSURE_NOT_POSITIVE | the absolute pressure, given or formed as gauge plus ambient, or a stated reference pressure, is zero or below. |
REFERENCE_ARGUMENTS | a reference condition is both named and stated, or a stated one lacks its temperature or pressure. |
The calculation
The method's equations, constants and worked example.
Equation 1
p·V = n·R·T, solved for whichever of p, V, n and T is not given
| Symbol | Meaning |
|---|---|
p | absolute pressure (given, or a gauge pressure plus the stated ambient pressure); 1 atm = 101325 Pa and 1 bar = 100 kPa exactly, kPa |
V | gas volume, L |
n | amount of gas, mol |
R | molar gas constant, J/(mol·K) |
T | thermodynamic temperature, K |
Source 1.
Equation 2
the volume at the reference V_ref = n·V_m
| Symbol | Meaning |
|---|---|
V_m | molar volume of an ideal gas at the reference condition, L/mol |
T_ref | reference temperature, K |
p_ref | reference pressure, kPa |
V_ref | the gas's volume at the reference condition, L |
Source 1.
| Constant | Value | From |
|---|---|---|
molar gas constant, R = N_A·k exactly (the listing prints R truncated) R | 8.31446261815324 J/(mol·K) | Source 1 |
A definition, not a model: the equation states what the quantity means. A different convention gives a different number.
Worked example
Worked example: one case of calc-gas-law@1.0.1, from its inputs through each step to the answer. Values are written as a person writes them; the working carries more digits, so your own figure may differ in the last digit shown.
Inputs
- amount = 0.5 mol
- volume = 10 L
- temperature = 300 K
Steps
- R = 8.3144626 J/(mol·K), by equation 1.
- p = 124.71694 kPa, from amount, temperature, volume, R; by equation 1; gives absolutePressure.
The working, as the case writes it:
R = N_A·k = 6.02214076e23 × 1.380649e-23 = 8.31446261815324 J/(mol·K)
p = nRT/V = 0.5 mol × 8.31446261815324 × 300 K / 0.010 m³ = 124716.94 Pa = 124.71694 kPa.
Answer
absolutePressure = 124.71694 kPa
Where these values came from: our own exact-arithmetic script and a hand-worked case; worked by hand, and in exact rationals.
At build the tool returned this answer within the tolerance the file states: relative 1e-15 on every number (absolute 1e-21 below 1e-6, in its own unit); statuses, codes and units exact.
Sources
NIST, CODATA Internationally recommended 2022 values of the Fundamental Physical Constants: complete listing (allascii.txt)
Used for: Ideal-gas pressure, volume, amount or temperature, and a gas volume at a named reference condition. At: row molar volume of ideal gas (273.15 K, 100 kPa) and (273.15 K, 101.325 kPa): V_m = RT/p, of which pV = nRT is n times; row molar volume of ideal gas (273.15 K, 100 kPa) and (273.15 K, 101.325 kPa); row Avogadro constant (6.022 140 76 e23 mol^-1, exact) and Boltzmann constant (1.380 649 e-23 J K^-1, exact); molar gas constant.
Read in full, 11 November 2026
How it is checked
- Level
Checked against a reference.
- Checked against
Our own exact-arithmetic script and a hand-worked case; a reference program this project wrote itself, second implementation (Python 3.13), 2026-11-14, exact rationals (Python fractions) on the exact value of each input double, each output rounded once to the nearest double; not an outside program.
- Cases
No case set is linked to this version.
- Not checked
Real-gas behaviour and compressibility; humid gas and water vapour; mass-flow controllers' own 'standard' conditions beyond the four named and a stated one; gas mixtures' partial pressures.
Changes to its methods1 change
- 14 November 2026, calc-gas-law@1.0.1: In 1.0.1 a stated reference pressure of zero or below is invalid-input PRESSURE_NOT_POSITIVE, an ambient pressure below zero is invalid-input OUT_OF_RANGE (zero, a vacuum, is read), and a result whose exact value is not zero but rounds to zero is refused whole as RESULT_OUTSIDE_DOUBLE_RANGE, as the kit refuses one beyond the double range. No published case's number moved.