Chemistry

Chemical Equation Balancer

Balance any chemical equation exactly, including redox reactions and hydrates. Shows the coefficients, molar masses and an atom-by-atom check.

Real Larzscript running in your browser847 automated checksOpen source · MITNo sign-up · your inputs never leave your device

Enter an unbalanced equation

Balanced equation
—

Coefficients and check

Show the Larzscript program that just ran
Run a calculation to see the exact program.

This is the real program the page sent to the Larzscript interpreter (compiled to WebAssembly) in your browser. The library it imports is the same code the automated tests check.

Balancing by linear algebra

Write the coefficients as unknowns x₁ … xₙ. Every element gives an equation: (atoms in the reactants) − (atoms in the products) = 0. For C₃H₈ + O₂ → CO₂ + H₂O:

C: 3x₁ = x₃   H: 8x₁ = 2x₄   O: 2x₂ = 2x₃ + x₄

Setting x₁ = 1 gives x₃ = 3, x₄ = 4 and x₂ = 5, so C3H8 + 5 O2 -> 3 CO2 + 4 H2O. When fractions appear (for example x₂ = 3/2) the calculator multiplies through by the least common multiple of the denominators, so the result is always the smallest whole numbers.

A harder one

Potassium permanganate and hydrochloric acid — a classic redox equation that is painful by trial — gives 2 KMnO4 + 16 HCl -> 2 KCl + 2 MnCl2 + 8 H2O + 5 Cl2, with all 16 chlorine atoms accounted for (2 in KCl, 4 in MnCl₂, 10 in 5 Cl₂). The check table on this page recounts the atoms of every element on both sides using the formula parser, so you can see the answer really balances.

What is verified

51 equations — from H₂ + O₂ to K₄[Fe(CN)₆] + H₂SO₄ + H₂O — are balanced by the library and, separately, by a Python solver using Gauss–Jordan elimination over exact fractions; the coefficients must be identical. Every answer is also checked by counting atoms with the formula parser, and impossible or ambiguous equations must be refused with the right message.

Limits: neutral formulas only (no ions or charges), one reaction per equation, integer coefficients up to what 64-bit arithmetic holds — far beyond any textbook problem.

Frequently asked questions

How do you balance a chemical equation?

Make the number of atoms of every element equal on both sides by choosing whole-number coefficients (never change subscripts). By trial: for Fe + O₂ → Fe₂O₃, 4 iron and 6 oxygen atoms are needed on both sides: 4 Fe + 3 O2 -> 2 Fe2O3. The calculator does it algebraically, so it works for equations too long to do by trial.

How does the algebraic method work?

Each element gives one linear equation in the unknown coefficients (atoms of that element on the left equal atoms on the right). The coefficients form the null space of the resulting matrix, found by Gauss–Jordan elimination in exact fractions and scaled to the smallest whole numbers. There is no guessing and no rounding error.

Why does it say an equation cannot be balanced?

Either an element appears on only one side (H₂ + O₂ → H₂O + N₂ has nitrogen from nowhere), or a formula is mistyped. Check capital letters: Co is cobalt, CO is carbon monoxide.

Why does it say there is more than one independent balance?

The equation mixes several reactions. H₂ + O₂ → H₂O + H₂O₂ can be balanced as water formation or as peroxide formation, and any combination of the two also balances, so there is no single answer. Split it into separate reactions.

Can it balance redox equations?

Yes, when they are written with neutral formulas: 2 KMnO4 + 16 HCl -> 2 KCl + 2 MnCl2 + 8 H2O + 5 Cl2 balances directly. Equations with ions and charges (Fe³⁺, MnO₄⁻) are not supported yet; write the full salts instead.

Do I have to remove the coefficients I typed?

No: any coefficients you enter are ignored and recomputed.

Does it handle combustion?

Yes: C3H8 + 5 O2 -> 3 CO2 + 4 H2O, and glucose respiration: C6H12O6 + 6 O2 -> 6 CO2 + 6 H2O. Hydrates work too, for instance CuSO4.5H2O → CuSO4 + H2O.

Every number on this page is computed by the open-source larzscript-chem library (balancer, chemistry, elements, physconst, physmath), written in Larzscript, and checked against independent references in its test suite. How it is verified →