Balancing chemical equations
Type a reaction and this page finds whole-number coefficients that make the atoms (and the charge) match on both sides. It does it with exact integer linear algebra, then recounts the atoms to check itself. It does not know whether the reaction can happen: it only checks the bookkeeping. Where the method gives no answer, or more than one, it says so. Made by Claude, an AI model.
How it balances
Give every species an unknown whole-number coefficient. Each element must have the same total on both sides, and so must the charge. That is one linear equation per element: the sum over species of (atoms of that element in the species) times (its coefficient), with reactants counted as plus and products as minus, must be zero. Stacking those equations gives a matrix A with one row per element (and one for charge) and one column per species, and the balancings are the vectors x with A x = 0: the null space of A.
The page row-reduces A using exact fractions (BigInt, no decimals, so no rounding), reads off a basis of the null space, and scales each basis vector to the smallest whole numbers. The dimension of the null space (the number of species minus the rank of A) decides what kind of answer there is:
- 0: the only solution is all zeros. No balancing exists.
- 1: every solution is a multiple of one vector. If its entries all have the same sign, that is the answer, and dividing out the common factor makes it the smallest.
- 2 or more: there are infinitely many balancings. There is no single “smallest”; the page lists the elementary ones (those using as few species as possible) and one that uses everything.
A positive answer also needs every coefficient to come out the same sign, so a solution can exist for the matrix and still not be a valid reading of the equation as written.
Where the method fails, or says too much
Each card runs the same code as the box above. The outcome line is computed by the page when it loads.
Self-test
Running
The reference coefficients below were typed in by hand from standard textbook answers and from the matching atom counts; they are not produced by the page's own algorithm. The parser is shared by the solver and the atom recount, so a mistake in reading a formula would not be caught by the recount alone; the parser was checked separately against hand-counted formulas in the README's test run.
What this does not do
- It does not judge chemistry.
Na + Cl2 -> NaCl2balances perfectly and is not a real compound; the arithmetic cannot tell. - It does not know which species are really present, which side an ion belongs on, or whether the reaction runs at all.
- It reads one step with each species once. It does not use oxidation numbers or half-reactions; for redox, charge is balanced because charge is one more row of the matrix.
- Formulas are read by a small parser: elements are checked against the 118 symbols, brackets and a hydrate dot are handled, and anything else is rejected with a message. Isotopes, states (aq, s) and structural formulas are not supported.
- No atomic masses are used or needed. Nothing is fetched; everything runs in your browser.