Enter the chemical formulas for reactants and products to find the stoichiometric coefficients.
Could not balance equation. Please check formulas (e.g., Capitalization: H2O not h2o).
Balanced Chemical Equation:
How to Balance Chemical Reactions
Balancing a chemical equation is the process of ensuring that the Law of Conservation of Mass is respected. This law states that matter cannot be created or destroyed in a chemical reaction. Therefore, the number of atoms for each element must be exactly the same on the reactant side (left) and the product side (right).
Step-by-Step Manual Method:
Write the Unbalanced Equation: List the reactants on the left and products on the right.
Count Atoms: Count how many atoms of each element are present on both sides.
Adjust Coefficients: Change the numbers in front of the molecules (coefficients) to balance the atoms. Never change the subscripts (the small numbers within a formula like the '2' in H₂O).
Check Your Work: Ensure all elements are balanced and the coefficients are in the lowest possible whole-number ratio.
Common Balancing Examples
Reaction Type
Unbalanced
Balanced
Combustion of Methane
CH₄ + O₂ → CO₂ + H₂O
CH₄ + 2O₂ → CO₂ + 2H₂O
Synthesis of Water
H₂ + O₂ → H₂O
2H₂ + O₂ → 2H₂O
Photosynthesis
CO₂ + H₂O → C₆H₁₂O₆ + O₂
6CO₂ + 6H₂O → C₆H₁₂O₆ + 6O₂
Pro Tips for Chemistry Students
When balancing by hand, it is usually easiest to balance elements that appear in only one reactant and one product first. Leave Oxygen and Hydrogen for last, as they often appear in multiple compounds and will often "self-balance" once the other elements are corrected.
function parseFormula(formula) {
var counts = {};
var regex = /([A-Z][a-z]*)(\d*)/g;
var match;
while ((match = regex.exec(formula)) !== null) {
var element = match[1];
var count = parseInt(match[2]) || 1;
counts[element] = (counts[element] || 0) + count;
}
return counts;
}
function calculateBalance() {
var r1 = document.getElementById("react1").value.trim();
var r2 = document.getElementById("react2").value.trim();
var p1 = document.getElementById("prod1").value.trim();
var p2 = document.getElementById("prod2").value.trim();
var errorDiv = document.getElementById("error-msg");
var resultDiv = document.getElementById("result-box");
errorDiv.style.display = "none";
resultDiv.style.display = "none";
if (!r1 || !p1) {
errorDiv.innerText = "Please provide at least one reactant and one product.";
errorDiv.style.display = "block";
return;
}
var r1Map = parseFormula(r1);
var r2Map = r2 ? parseFormula(r2) : {};
var p1Map = parseFormula(p1);
var p2Map = p2 ? parseFormula(p2) : {};
var allElements = new Set([
…Object.keys(r1Map),
…Object.keys(r2Map),
…Object.keys(p1Map),
…Object.keys(p2Map)
]);
var found = false;
var a, b, c, d;
// Brute force solver for coefficients up to 20
// This handles 99% of educational chemistry problems efficiently
outerLoop:
for (a = 1; a <= 20; a++) {
for (b = (r2 ? 1 : 0); b <= (r2 ? 20 : 0); b++) {
for (c = 1; c <= 20; c++) {
for (d = (p2 ? 1 : 0); d 1 ? a : "") + r1;
if (r2) equationStr += " + " + (b > 1 ? b : "") + r2;
equationStr += " → ";
equationStr += (c > 1 ? c : "") + p1;
if (p2) equationStr += " + " + (d > 1 ? d : "") + p2;
document.getElementById("equation-output").innerText = equationStr;
document.getElementById("explanation-output").innerText = "Success! The coefficients " + a + ", " + (r2 ? b : "N/A") + ", " + c + ", " + (p2 ? d : "N/A") + " satisfy the conservation of mass.";
resultDiv.style.display = "block";
} else {
errorDiv.innerText = "Could not find integer coefficients (1-20). Verify formula syntax and element balance.";
errorDiv.style.display = "block";
}
}