Chemistry

Molar Mass Calculator

Type any chemical formula — brackets and hydrates included — and get its molar mass, element-by-element breakdown, and moles and molecules for a sample.

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

Enter a chemical formula

Brackets ( ) [ ] { } and hydrates like CuSO4.5H2O are fine
Gives moles and number of molecules
Molar mass
—
Hill formula
—
Atoms per formula unit
—
Moles in your sample
—
Particles in your sample
—

Element by element

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.

How molar mass is calculated

Read the formula, count every atom (multiplying through brackets and hydrate water), then add up count × atomic weight:

M = Σ (number of atoms of element i) × (atomic weight of element i)

For calcium hydroxide, Ca(OH)2, the bracket doubles the O and the H, giving 1 Ca + 2 O + 2 H: 40.078 + 2 × 15.999 + 2 × 1.008 = 74.092 g/mol. Calcium phosphate, Ca3(PO4)2, contains 13 atoms of 3 elements and weighs 310.174 g/mol.

Hydrates

A dot separates the salt from its water of crystallisation. Copper(II) sulfate pentahydrate, CuSO4·5H2O, is CuSO4 plus five H2O, so its molar mass is 249.677 g/mol, 90.07 g/mol more than the anhydrous salt: the water is 36.1% of the crystal by mass, which is why heating blue crystals drives off so much weight.

From grams to moles to molecules

Moles = grams ÷ molar mass, and particles = moles × 6.02214076 × 1023 (Avogadro's constant, exact since 2019). One mole of table salt is 58.44 g, so 58.44 g contains 6.022 × 10²³ formula units. Change the sample mass above to see any other.

What is verified

Molar masses of 67 formulas — including hydrates, nested brackets and salts such as K4[Fe(CN)6] — are compared with a completely separate parser written in Python that sums 60-digit decimals; Hill formulas and atom counts are compared too. The 118 atomic weights are cross-checked against PubChem's independent table (worst difference 0.2, on lead, which PubChem rounds to 207.0).

Limits: neutral formulas only (no charges, no isotopes such as ¹³C or D), standard atomic weights rather than those of a particular sample.

Frequently asked questions

What is molar mass?

The mass of one mole (6.022 × 1023 particles) of a substance, in grams per mole. You get it by adding the atomic weights of every atom in the formula: water, H₂O, is 2 × 1.008 + 15.999 = 18.015 g/mol.

What is the difference between molar mass, molecular weight and formula weight?

The numbers are the same; the names differ by habit. Molecular weight and formula weight are relative masses (no unit, or in daltons); molar mass is the same number in g/mol. Chemists use "formula weight" for ionic compounds such as NaCl, which have no discrete molecules.

How do I enter a formula with brackets or a hydrate?

Write brackets as in the textbook: Ca(OH)2 gives 74.092 g/mol and K4[Fe(CN)6] works too, to any depth. For a hydrate separate the water with a dot or an asterisk: CuSO4.5H2O is 249.68 g/mol, not the 159.6 of the anhydrous salt.

Why does capitalisation matter?

Because it is how element symbols work: Co is cobalt but CO is carbon monoxide, and Cs is caesium but CS would be a carbon–sulfur formula. The calculator reads a capital letter as the start of a new element and rejects anything that is not a real symbol, so a typo produces an error instead of a wrong mass.

Which atomic weights does it use?

The standard atomic weights from IUPAC as packaged in the periodictable data set (for example C 12.011, H 1.008, Cl 35.45), cross-checked against PubChem's table. Elements with no standard weight (technetium, promethium and everything after bismuth except thorium, protactinium and uranium) use the mass number of their longest-lived isotope and the answer is only approximate.

Does it support ions and charges?

No. Enter the neutral formula unit (NaCl, not Na⁺ and Cl⁻). Electron masses are far below the precision of atomic weights anyway.

How do I convert grams to moles?

Divide the mass by the molar mass. Enter the grams of your sample above: 18 g of water is 0.99917 mol, and 180 g of glucose is 0.99913 mol or 6.017 × 10²³ molecules.

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