Chemistry

Molar mass calculator

Parses chemical formulas (with parentheses and hydrates) and returns molar mass plus per-element breakdown.

01Inputs
Use proper case (H2O, NaCl, C6H12O6). Parentheses Ca(OH)2 and hydrate dot CuSO4·5H2O are supported.
02Results
Molar mass
Moles per gram
Element Atoms Atomic mass Contribution %
Mass share by element
03How it works

Why this calculation

Computing the molar mass of a compound is the most basic, most-used operation in chemistry. Every stoichiometry calculation, every solution preparation, every titration, every pharmaceutical-dose conversion routes through "given a molecular formula, what is its mass per mole, and what fraction of that mass comes from each element?" Schools teach the procedure — look up atomic masses, multiply by stoichiometric coefficients, sum — but the bookkeeping is tedious for anything past a four-atom molecule. Errors compound when formulas include nested parentheses (Ca(OH)₂, Fe(NO₃)₃·9H₂O) or hydrate dots (CuSO₄·5H₂O). This calculator parses the formula text directly: a small recursive descent over a grammar that accepts symbols, multipliers, parentheses, and hydrate dots, summed against an internal table of standard atomic weights.

The output is the total molar mass, the mass-percent contribution of each element (sorted high to low), and a stacked-bar visual that makes the proportions intuitive at a glance — useful when teaching, useful when sanity-checking a synthesis spreadsheet, and useful for industrial QA where the percent-mass of each element is the spec.

The formula

Molar mass M(compound) = Σ n_i · M_i where n_i is the count of atoms of element i in one formula unit and M_i is the standard atomic mass of element i (IUPAC 2021 conventional values).

The parser handles:

  • Simple formulas: H2O, CO2, NaCl. Element symbol followed by an optional integer count.
  • Multi-letter symbols: Mg, Cl, Cu — capital + optional lower-case. The parser distinguishes "Co" (cobalt) from "CO" (carbon + oxygen) by case.
  • Parentheses: Ca(OH)2, Al2(SO4)3 — sub-formula multiplied by the trailing number. Square brackets [...] are accepted as a synonym.
  • Nested parentheses: K3[Fe(CN)6]. Inner factor first, outer factor second.
  • Hydrate dot: CuSO4·5H2O — a leading integer multiplies the next sub-formula. Both · and . are accepted.
  • Implicit count of 1: H2O (the O has count 1).

Per-element breakdown:

  • contribution_g_per_mol = n_i · M_i.
  • mass_pct = contribution / total · 100.

The "moles per gram" inverse is also reported: n = 1 / M_total.

How to use

Enter the formula in the text box. The case matters: use proper element-symbol case (Na, not na or NA). Use 1, 2, 3 … for stoichiometric counts (not subscript Unicode characters — those are not parsed). Use parentheses for branched groups. Use the dot character · or a regular full-stop . for hydrates.

Press Tab or click outside the field to compute. The result panel shows:

  • Total molar mass in g/mol as the headline KPI.
  • Moles per gram (the reciprocal — useful when you have a fixed-mass sample).
  • A table with one row per element: symbol, count, atomic mass, contribution, mass-percent.
  • A stacked bar where each segment is one element, sized in proportion to its mass-share.

Worked example

Water H₂O.

  • Atoms: H × 2, O × 1.
  • Atomic masses: H = 1.008, O = 15.999.
  • Total: 2 × 1.008 + 15.999 = 18.015 g/mol.
  • O is 88.8 % of the mass; H 11.2 %.

Glucose C₆H₁₂O₆.

  • C × 6, H × 12, O × 6.
  • C = 12.011, H = 1.008, O = 15.999.
  • Total: 72.066 + 12.096 + 95.994 = 180.156 g/mol.
  • Mass-percent: O 53.3 %, C 40.0 %, H 6.7 %.

Copper(II) sulfate pentahydrate CuSO₄·5H₂O.

  • Decomposes as: Cu + S + O × 4 + 5 × (H × 2 + O) = Cu × 1, S × 1, O × 9, H × 10.
  • Atomic masses: Cu = 63.546, S = 32.06, O = 15.999, H = 1.008.
  • Total: 63.546 + 32.06 + 9 × 15.999 + 10 × 1.008 = 63.546 + 32.06 + 143.991 + 10.08 = 249.677 g/mol.

Aluminum sulfate Al₂(SO₄)₃.

  • Al × 2, S × 3, O × 12.
  • Total: 2 × 26.982 + 3 × 32.06 + 12 × 15.999 = 53.964 + 96.18 + 191.988 = 342.132 g/mol.

Pitfalls

Case sensitivity matters more than people expect. "CO" is carbon monoxide; "Co" is cobalt. "CN" is cyanide; "Cn" is copernicium. The parser will not warn you — it will quietly use whatever element matches the case you typed.

Subscript Unicode is not parsed. H₂O looks pretty but H2O is what the parser expects. Copy-pasting from a textbook that uses subscripts will fail with a "syntax error".

Brackets vs braces. The parser accepts () and [] as group delimiters; it does not accept curly braces {}.

Charge / oxidation state. The parser ignores +, , and Roman numerals. "Fe(III)" must be entered as "Fe" — the III is informational, not stoichiometric. Polyatomic ions like SO₄²⁻ are entered as SO4 (the charge is meaningful chemically but invisible in the molar-mass calculation).

Hydrate notation variation. Different texts use ·, ., *, or , as the hydrate separator. The parser accepts · (middle dot) and . (full stop). For other separators, replace before pasting.

Standard vs isotope-specific atomic masses. The table uses 2021 IUPAC standard atomic weights, which are interval-averaged across natural isotopic abundance. For deuterium-labeled or ¹³C-enriched compounds, the calculator under-reports — adjust manually for isotope composition.

Polyatomic-ion shorthand. "Ammonium" written as NH4 works; written as (NH4) works too. But NH₄⁺ won't parse (Unicode + charge).

Common element-symbol gotchas. B (boron) vs Be (beryllium); K (potassium) vs Kr (krypton); Y (yttrium) vs Yb (ytterbium). When in doubt, name the element rather than the symbol and look up.

Anhydrous vs hydrate. CuSO₄ (anhydrous) is 159.6 g/mol; CuSO₄·5H₂O (pentahydrate) is 249.7 g/mol. A 1 g sample of pentahydrate contains only 0.64 g of anhydrous salt. This matters for accurate solution prep — read the label, type the formula that matches.

Significant figures. The calculator returns three or four decimals from a four-significant-figure atomic-mass table. For analytical-chemistry work requiring more precision, look up CODATA atomic masses with their measurement uncertainties.

Free radicals and structural ambiguity. Empirical formula H₂O is unambiguous. Cyclohexane (C₆H₁₂) and 1-hexene (also C₆H₁₂) have the same molar mass — the calculator computes mass, not structure.

Variations

  • Empirical-formula derivation: from elemental-analysis percentages, infer the smallest integer atom ratio.
  • Molarity solution prep: this calc + dilution-calculator together give grams-per-liter for a target molarity.
  • Percent composition lookup: the per-element breakdown is exactly what's needed for combustion-analysis cross-checks.
  • Molecular-vs-formula weight: ionic compounds (NaCl) don't form discrete molecules; the calculator returns the formula weight, which is a per-formula-unit quantity, not a per-molecule one.
  • Average molar mass of polymers: requires a degree-of-polymerization input.

Related calculators