Chemistry & Chemical Engineering Stoichiometry & Reaction Yield Conservation of mass (Lavoisier) solved as a linear null-space problem

Chemical Equation Balancer

Type an unbalanced equation such as C3H8 + O2 = CO2 + H2O and this returns the smallest set of whole-number coefficients that conserves every element. It does not guess or try combinations: it writes one linear equation per element, solves the resulting system for its null space, and scales the answer to the smallest integers. An element-by-element check appears underneath so you can confirm both sides carry the same atoms.

Calculator

This calculator runs in your browser. Enable JavaScript for live results — the inputs, formula and worked example below remain fully readable without it.

Inputs this calculator takes, with typical values
InputWhat to enterExample
Unbalanced equationSeparate species with + and the two sides with =, -> or an arrow. Any coefficients you type are ignored.C3H8 + O2 = CO2 + H2O
Show the element balance checkAdds a table counting the atoms of each element on both sides of the balanced equation.Yes

It returns

  • Balanced equation — The smallest whole-number coefficients, with a coefficient of 1 left unwritten.
  • Coefficients in order
  • Sum of the coefficients
  • Atoms on each side — Equal by construction once the equation balances — a quick sanity check on the result.
  • Species in the equation
  • Distinct elements

The formula

jnaijxj=0

In plain text: A·x = 0, x > 0 and integral — one row of A per element, one column per species

  • aᵢⱼAtoms of element i in species j, positive for reactants and negative for products (count)
  • xⱼStoichiometric coefficient of species j (count)
  • nNumber of species in the equation (count)
  • mNumber of distinct elements, and so the number of equations (count)

Because the system is homogeneous, its solutions form a subspace. A chemically sensible equation has exactly one free variable, which is why the balanced coefficients are unique up to an overall multiple — and why we take the smallest positive integer set.

Updated Category Stoichiometry & Reaction Yield Verified against published test cases Reading time 9 min

What balancing an equation actually asserts

A balanced equation says that atoms are neither created nor destroyed. Every atom that enters a reaction leaves it, possibly in a different compound, so the count of each element must be identical on both sides. The coefficients in front of the formulas are the only thing you may change — subscripts are part of the compound's identity, and altering one changes the substance rather than the bookkeeping.

That single constraint is enough to determine the coefficients almost uniquely. Write one equation per element, and you get a homogeneous system of linear equations whose solutions form a line through the origin. Any point on that line balances; the convention is to take the smallest set of positive whole numbers, which is why 2 H₂ + O₂ → 2 H₂O is the accepted form rather than the equally valid 4 H₂ + 2 O₂ → 4 H₂O.

Balancing is also the gate for everything quantitative. The coefficients are the mole ratio, and without them you cannot compute a theoretical yield, identify a limiting reagent, or convert between species with the mole-ratio calculator. An unbalanced equation is not a small error — it makes every downstream number wrong.

The matrix method, and why inspection eventually fails

Most courses teach balancing by inspection: start with the element that appears in the fewest species, adjust, move on, and clean up oxygen and hydrogen last. That works well for combustion and simple displacement reactions, and it is worth being fluent in it. It fails on redox equations with five or six species, where the adjustments chase each other in circles.

The systematic method treats it as algebra. Assign an unknown coefficient to each species: a·C₃H₈ + b·O₂ → c·CO₂ + d·H₂O. Then write conservation for each element:

  • Carbon: 3a = c
  • Hydrogen: 8a = 2d
  • Oxygen: 2b = 2c + d

Three equations, four unknowns. The system is underdetermined by exactly one, which is the mathematical statement that the equation is fixed only up to an overall scale factor. Set one unknown to 1, solve the rest, then clear the fractions.

This calculator does exactly that in matrix form. It builds a table with one row per element and one column per species, signs the product columns negative, and reduces it to row echelon form. The column left without a pivot is the free variable; setting it to 1 and back-substituting gives the ratios, and multiplying by the smallest common denominator gives whole numbers. Dividing by any common factor at the end guarantees the smallest set.

If the reduction leaves more than one free column, the equation genuinely has more than one independent solution — which in practice means two different reactions have been written as one. The calculator returns a valid balance and says so, but the right response is to split the equation.

Worked example: burning propane

Balance C₃H₈ + O₂ → CO₂ + H₂O by hand, then check it against the calculator.

  1. Assign unknowns. a·C₃H₈ + b·O₂ → c·CO₂ + d·H₂O.
  2. Carbon. Each propane supplies 3 carbons, each carbon dioxide takes 1, so 3a = c.
  3. Hydrogen. Each propane supplies 8 hydrogens, each water takes 2, so 8a = 2d, that is d = 4a.
  4. Oxygen. Each O₂ supplies 2, each CO₂ takes 2 and each H₂O takes 1: 2b = 2c + d.
  5. Set a = 1. Then c = 3 and d = 4, so 2b = 6 + 4 = 10 and b = 5.
  6. Read off. C₃H₈ + 5 O₂ → 3 CO₂ + 4 H₂O. All four coefficients are already whole numbers with no common factor, so this is the smallest set.

Now check the atoms rather than trusting the algebra. Left: 3 C, 8 H, 10 O — twenty-one atoms. Right: 3 C from the carbon dioxide, 8 H from the four waters, and 6 + 4 = 10 O. Twenty-one atoms, element by element. That check is what the table under the result performs automatically.

The coefficients are immediately usable. Burning one mole of propane, 44.10 g, consumes five moles of oxygen and produces three moles of carbon dioxide, 132.03 g. Feed those ratios into the mole-ratio calculator to convert any mass of fuel into any product mass.

How to check the answer is right

Count the atoms yourself, at least once per new equation. The balance table lists each element with its total on each side and the difference, and every difference must be zero. This catches the one failure mode the algebra cannot: a mistyped formula. If you write CO instead of CO₂, the system still solves — it just solves a different, correct-looking reaction.

Look at the size of the coefficients. Ordinary reactions balance with single-digit numbers. Redox reactions in acid can legitimately reach the twenties or thirties, and a few classic permanganate and dichromate equations go higher. But a coefficient in the hundreds almost always signals a subscript typed wrongly, because a small change in one formula can force a large common multiple.

Watch for the multiple-solution warning. If the reduction leaves two free variables, the coefficients returned are one balance among infinitely many independent ones. That happens when an equation combines separate reactions — for example a combustion and an unrelated precipitation written on one line — and the fix is to balance them separately.

Reference: equations worth recognising balanced

Standard forms, with the sum of the coefficients as a quick check.
ReactionBalanced equationCoefficient sum
Formation of water2 H₂ + O₂ → 2 H₂O5
Ammonia synthesis (Haber)N₂ + 3 H₂ → 2 NH₃6
Methane combustionCH₄ + 2 O₂ → CO₂ + 2 H₂O6
Propane combustionC₃H₈ + 5 O₂ → 3 CO₂ + 4 H₂O13
Octane combustion2 C₈H₁₈ + 25 O₂ → 16 CO₂ + 18 H₂O61
Rusting of iron4 Fe + 3 O₂ → 2 Fe₂O₃9
Aluminium with hydrochloric acid2 Al + 6 HCl → 2 AlCl₃ + 3 H₂13
Thermal decomposition of limestoneCaCO₃ → CaO + CO₂3
Neutralisation of sulfuric acidH₂SO₄ + 2 NaOH → Na₂SO₄ + 2 H₂O6
Photosynthesis (overall)6 CO₂ + 6 H₂O → C₆H₁₂O₆ + 6 O₂19

Every one of these is reproduced by typing the unbalanced skeleton into the field above.

Rules and traps

  • Never change a subscript to balance. Changing H₂O to H₂O₂ balances the oxygen and turns water into hydrogen peroxide. Only coefficients may move.
  • A coefficient multiplies the whole formula. 3 Ca(NO₃)₂ contains 3 calcium, 6 nitrogen and 18 oxygen atoms.
  • Case matters in every symbol. Co is cobalt and CO is carbon monoxide; the balancer treats them as different species and will happily balance the one you did not mean.
  • Balance polyatomic ions as units when they survive intact. If sulfate appears unchanged on both sides, treating SO₄ as one item is faster and less error-prone than counting sulfur and oxygen separately.
  • Charge must balance too in ionic equations. This calculator conserves atoms only. For a net ionic or half-reaction equation, add electrons and check the total charge on each side by hand.
  • An equation that will not balance usually has a wrong formula. Before assuming the reaction is impossible, check the oxidation states and the formulas of the products.

Redox, half-reactions and what balancing does not tell you

Redox equations in aqueous solution need more than atom conservation, because water, protons and hydroxide participate as sources of oxygen and hydrogen. The standard approach is the half-reaction method: split the reaction into an oxidation and a reduction, balance each for atoms other than O and H, add H₂O to balance oxygen, add H⁺ to balance hydrogen, add electrons to balance charge, scale the two halves to equal electron counts, and recombine. In basic solution, finish by adding hydroxide to both sides to convert protons to water.

This calculator will balance many redox skeletons directly, provided you have written every species that changes, including the water and the acid. If you omit them, the atom count cannot close and no solution exists — which is exactly what a chemically incomplete equation deserves.

Two things a balanced equation never tells you. It says nothing about whether the reaction happens: thermodynamics decides that, through the Gibbs energy change, and kinetics decides how fast. And it says nothing about mechanism — the coefficients are an overall accounting, not a description of what collides with what. A balanced equation with a coefficient of 5 does not imply five molecules meeting at once, which would be vanishingly improbable.

What it does give you is the mole ratio, and that is the foundation of every quantitative calculation downstream: the limiting reagent, the theoretical yield, and the percent yield you compare your real isolated product against. Historically, this all rests on Lavoisier's demonstration in the 1770s that mass is conserved in closed-vessel combustion — the observation that turned chemistry into a quantitative science.

Frequently asked questions

How do I balance a chemical equation?

Adjust only the coefficients in front of each formula until every element has the same atom count on both sides. By inspection, start with the element appearing in the fewest species and leave oxygen and hydrogen until last. Algebraically, assign a letter to each coefficient, write one conservation equation per element, set one letter to 1, solve and clear fractions. Never alter a subscript.

Why can I not change the subscripts?

Because subscripts define what the substance is. Water is H₂O; writing H₂O₂ to make the oxygen work gives hydrogen peroxide, a different compound with different properties. Coefficients say how many formula units take part, which is the only quantity a balancing exercise is allowed to determine.

What separator should I use between the two sides?

Any of =, -> or a right arrow character. Species are separated by plus signs. Whitespace is ignored, so C3H8+O2=CO2+H2O and C3H8 + O2 -> CO2 + H2O parse identically. Any coefficients you happen to type are stripped and re-derived, so you can paste a partly balanced equation without confusing the result.

Why does the calculator say my equation cannot be balanced?

Almost always because a formula is mistyped or a species is missing. Check capitalisation first — Co and CO are different substances. Then check that every element appearing on one side also appears on the other: an equation that produces oxygen with no oxygen among the reactants has no solution, and no amount of coefficient adjustment will create one.

Can it balance redox equations?

Yes, as long as every participating species is written, including water and the acid or base that supplies oxygen and hydrogen. It conserves atoms, not charge, so for a half-reaction or a net ionic equation you must add the electrons and confirm the charge balance yourself. For full molecular redox equations in acid, atom conservation alone is usually sufficient.

What does it mean if there is more than one solution?

It means the system has two or more independent null-space directions, which almost always signals that two separate reactions have been written on one line. The coefficients returned are a genuine balance, but not the only one, and using them for stoichiometry would be meaningless. Split the equation into the individual reactions and balance each.

Are the coefficients always the smallest whole numbers?

Yes. The calculator scales the ratios up by the smallest denominator that clears all fractions, then divides through by the greatest common divisor. That is why you get 2 H₂ + O₂ → 2 H₂O rather than the equally correct 4 H₂ + 2 O₂ → 4 H₂O. The one conventional exception is a half-reaction quoted per electron, which is deliberately fractional.

Does a balanced equation mean the reaction will actually happen?

No. Balancing is bookkeeping about atoms and says nothing about thermodynamic favourability or rate. You can balance the conversion of nitrogen and oxygen to nitric oxide perfectly well, but at room temperature the reaction is negligibly slow. Use the balanced equation for quantities, and thermodynamic and kinetic data for whether and how fast.

References

  • Nomenclature of Inorganic Chemistry (the IUPAC Red Book), 2005 recommendations — IUPAC / RSC Publishing
  • Chemical Principles: The Quest for Insight, 7th edition — W. H. Freeman
  • Antoine Lavoisier, Traité élémentaire de chimie (1789) — statement of conservation of mass — Cuchet, Paris