Chemistry calculator

Molecular Weight Calculator

Parse a chemical formula and sum atomic weights to find total molar mass.

Molar mass

18.015 g/mol

H × 22.016 g/mol
O × 115.999 g/mol

How the formula parser works

Enter a chemical formula using element symbols, digit subscripts, and parentheses. Element symbols are case-sensitive: C and Ca are both valid, but c is not recognized. The parser reads capital letters optionally followed by a lowercase letter to identify each element, then looks for whole-number subscripts immediately after. Parentheses group atoms together; the number following a closing parenthesis multiplies the entire group. For example, Ca(OH)2 means one calcium, and the (OH) group appears twice, producing one calcium and two oxygen-hydrogen pairs.

The formula field accepts up to 100 characters. The parser rejects formulas with unsupported syntax such as hydrate dots (H2O·5H2O), leading coefficients (2NaCl), charge notation (Na+), isotope notation (C-12), square brackets, fractional subscripts, or elements not in the bundled atomic-weight table. When parsing succeeds, the total molar mass appears in the result field in grams per mole, and each element's contribution is itemized below.

Calculating molar mass of water step by step

Molecular weight = sum of (element atomic weight × subscript count)
H2O: 2 × 1.008 + 1 × 15.999 = 18.015 g/mol

Water's formula is H2O. The hydrogen count is 2, and the oxygen count is 1. From the periodic table, hydrogen's standard atomic weight is 1.008 u and oxygen is 15.999 u. Multiplying each count by its atomic weight: hydrogen contributes 2 × 1.008 = 2.016 g/mol, and oxygen contributes 1 × 15.999 = 15.999 g/mol.

Adding these contributions gives the total molar mass: 2.016 + 15.999 = 18.015 g/mol. The calculator displays this as the main result and shows the per-element row labeled "H × 2" and "O × 1" with their respective masses, making it easy to verify the calculation or identify which atoms contribute most to the total.

Nested groups and complex formulas

Parentheses allow you to express formulas with complex ion structure. Calcium hydroxide, Ca(OH)2, illustrates this pattern. The parser first recognizes Ca as calcium (40.078 u), then encounters (OH), a group containing one oxygen (15.999 u) and one hydrogen (1.008 u), totaling 17.007 u per group. Because the group is followed by 2, the (OH) unit is counted twice: 2 × 17.007 = 34.014 u. The complete molar mass is 40.078 + 34.014 = 74.092 g/mol.

Ammonium sulfate, (NH4)2SO4, demonstrates nesting where the (NH4) group is itself multiplied by 2. The N inside is 14.007 u, H is 1.008 u per atom, and there are 4 hydrogens, giving 14.007 + 4 × 1.008 = 18.039 u per NH4 unit. Multiplied by 2 for the outer subscript, that part totals 36.078 u. Added to S (32.06 u) and 4 × O (4 × 15.999 = 63.996 u), the result is 132.134 g/mol. Nested parentheses ensure that complex ionic compounds are decomposed correctly.

Common formulas and elemental composition

  • Carbon dioxide (CO2): 12.011 + 2 × 15.999 = 44.009 g/mol, showing that even simple gases have measurable atomic contributions.
  • Sodium chloride (NaCl): 22.9898 + 35.45 = 58.4398 g/mol, demonstrating how atomic weights for heavier elements like Na and Cl combine.
  • Glucose (C6H12O6): 6 × 12.011 + 12 × 1.008 + 6 × 15.999 = 180.156 g/mol, illustrating that organic molecules with many atoms require careful counting.
  • Aluminum sulfate (Al2(SO4)3): 2 × 26.9815 + 3 × (32.06 + 4 × 15.999) = 53.963 + 288.168 = 342.131 g/mol, showing how nested groups simplify expression of ionic compound formulas.
  • Sulfuric acid (H2SO4): 2 × 1.008 + 32.06 + 4 × 15.999 = 98.072 g/mol, a strong acid whose molar mass anchors many dilution and titration calculations.

Frequently asked questions

Why are element symbols case-sensitive?

IUPAC notation uses case to distinguish elements. C is carbon, but Ca is calcium. The parser enforces this convention to prevent ambiguous interpretations like CO (carbon + oxygen) being misread as Co (cobalt).

Can I type a formula like 2H2O with a leading coefficient?

No. Leading coefficients belong to the chemical equation, not the formula. Enter H2O alone to get its molar mass, then multiply the result by 2 if the equation requires two water molecules.

What happens if I use an unsupported element?

The parser checks each element symbol against its atomic-weight table. If uranium, tungsten, or other unsupported elements appear, the formula is rejected and the result field shows a dash.

Does the calculator account for isotopes?

No. Standard atomic weights represent averages over natural abundances. Isotope notation and specific isotope masses are outside this calculator's scope.

How precise are the molar masses shown?

The calculator displays up to four decimal places (e.g., 18.015 g/mol or 58.4398 g/mol). This matches the precision of the bundled atomic weights and is sufficient for most laboratory and educational purposes, though specialized high-precision work may require additional decimal places.

Can I calculate molar mass if I only know the formula name?

No, you must write the chemical formula. If you know only the name, convert it to a formula first using a chemical reference, then enter it here.