The anion gap is a one-line calculation from a basic metabolic panel, yet two competent implementations can return answers 4 mEq/L apart for the same patient. The cause is usually not arithmetic. It is a silent convention choice: whether potassium sits on the cation side of the expression. If you are wiring this into software, the convention has to be explicit, because the reference range only makes sense alongside it.
The two expressions
The conventional definition sums the measured cations that are not sodium and subtracts the measured anions that are not chloride or bicarbonate:
AG (without K) = Na+ - (Cl- + HCO3-)
AG (with K) = (Na+ + K+) - (Cl- + HCO3-)
All terms are in mEq/L; for these singly charged ions that is numerically the same as mmol/L. Adding potassium raises the result by exactly the serum potassium concentration. A library that documents only "anion gap = Na - Cl - HCO3" has already picked one convention, and a downstream rule such as "elevated above 12" inherits that choice without saying so.
A small implementation makes the branch impossible to miss:
function anionGap({ na, cl, hco3, k, includeK = false }) {
const cations = includeK ? na + k : na;
return cations - (cl + hco3);
}
// albumin correction, conventionally applied to the K-free gap:
const corrected = gap => gap + 2.5 * (4.0 - albumin);
The albumin term matters because albumin is the largest unmeasured anion. A low albumin lowers the "normal" gap; adding 2.5 mEq/L for every 1 g/dL below 4 g/dL is a common correction, but it is a convention too, not a law.
Worked example
Take Na+ 140, Cl- 104, HCO3- 24, K+ 4.0 mEq/L, albumin 3.0 g/dL.
without K: 140 - (104 + 24) = 140 - 128 = 12 mEq/L
with K: (140 + 4.0) - 128 = 144 - 128 = 16 mEq/L
albumin-corrected (K-free): 12 + 2.5 * (4.0 - 3.0) = 14.5 mEq/L
Three defensible numbers from one panel: 12, 16, and 14.5. The 4 mEq/L spread is precisely the potassium, and the corrected value sits halfway because the albumin is 1 g/dL low. Any interface that displays a single "normal / high" badge must state which of these it used.
Boundary conditions
- Reference intervals are method- and laboratory-specific. A range quoted for the K-free formula is not transferable to the K-inclusive one; hard-code neither without a source.
- The albumin correction assumes the 2.5 coefficient and a 4 g/dL reference. Severe hypokalemia, hyperkalemia, or paraproteinemia break the simple unmeasured-anion picture.
- Unmeasured anions (lactate, ketones, salicylate, sulfate) and unmeasured cations (calcium, magnesium) move the gap; a normal value does not exclude a mixed disorder.
- Round at the end. Inputs are reported to integer or one-decimal precision, so extra digits in the output imply accuracy the panel does not have.
- This is a screening calculation, not a diagnosis. Clinical interpretation depends on history, acid-base status, and the rest of the panel.
For a transparent implementation that exposes the potassium convention and the albumin correction separately, see the anion gap calculator. The accompanying anion gap guide walks through how reference ranges change with the formula convention.
YMYL note: This is educational content about a laboratory calculation, not medical advice. Interpretation of electrolyte results requires a qualified clinician.
Top comments (0)