How this molar mass calculator works
Type a formula and you get its molar mass, the mass each element contributes, the percent composition, and, if you enter an amount, the conversion between grams, moles and individual molecules. The parser handles what real formulas actually look like: nested brackets in Al2(SO4)3 and K4[Fe(CN)6], the dot in a hydrate like CuSO4·5H2O, a trailing charge on an ion, and subscripts whether you type them as plain numbers or paste them from a document.
Two things here that most molar mass calculators leave out, and they are the reason this page exists. First, it tells you how many of the digits are real: IUPAC publishes an uncertainty alongside every atomic weight, and adding those up tells you where to stop writing decimals. Second, it tells you when your compound contains one of the fourteen elements whose atomic weight is no longer a single number at all. Both are things a chemistry professor will care about and a homework helper will not mention.
The formula
percent of element i = niAi ÷ M × 100
moles = grams ÷ M
molecules = moles × NA
M is the molar mass in grams per mole, ni is how many atoms of element i the formula contains, and Ai is that element's standard atomic weight. NA is Avogadro's constant, which since the 2019 redefinition of the SI is exactly 6.02214076 × 1023 per mole. The mole stopped being defined by a lump of carbon that year and became a defined count, so grams to molecules is now a conversion by definition rather than by measurement.
Worked example
Glucose, C6H12O6. Six carbons at 12.011, twelve hydrogens at 1.008, six oxygens at 15.999: 72.066 + 12.096 + 95.994 = 180.16 g/mol.
The composition falls out of the same three numbers: carbon is 72.066 ÷ 180.156 = 40.00% of the mass, hydrogen 6.71%, oxygen 53.28%. That 40.00% is not a coincidence worth ignoring. Glucose reduces to the empirical formula CH2O, which is one carbon and one water, which is where the word carbohydrate comes from. Notice also that the three rounded percentages add to 99.99 rather than 100.00, which is what rounding does and not an error.
And the uncertainty: 6 × 0.002 for carbon, 12 × 0.0002 for hydrogen, 6 × 0.001 for oxygen gives ±0.02 g/mol. So 180.16 is honest and 180.1559 is not. If you have 5.00 g of glucose, that is 5.00 ÷ 180.156 = 0.027754 mol, or about 1.67 × 1022 molecules.
Capital letters are part of the chemistry
Type CO and you have written carbon monoxide, 28.01 g/mol. Type Co and you have written cobalt, 58.93 g/mol. Type co and you have written nothing at all. That is not a quirk of this page, it is the notation working as designed: a capital letter starts an element symbol and a lowercase letter continues it, which is exactly how a two-letter symbol can sit next to a one-letter one with no separator and still be unambiguous.
This calculator will not silently repair your capitals, and that is deliberate. A tool that uppercases everything before parsing turns Co into CO and hands back a confident wrong answer, which is worse than an error message. When something does not parse, you get told which characters stopped it and what element you may have meant. The same rule explains why Cs is cesium rather than carbon-plus-sulfur, and why NaCl cannot be misread even though N, Na, C and Cl are all real symbols.
Ionic charges get the same treatment, for the same reason. A bare sign is never ambiguous, so Na+ and OH- work exactly as typed and the charge is simply set aside, which is right to about one part in a hundred thousand: an electron does have mass, just not enough to reach the digits anyone prints. But SO42- is genuinely ambiguous. It could be sulfate carrying a 2- charge, or it could be forty-two of something carrying 1-, and those weigh 96.06 and 48.06 g/mol respectively. Rather than pick one and sound certain, this page hands it back and asks you to write SO4^2- or SO4 2-, either of which says exactly what you mean. That is the same position our order of operations calculator takes on 8/2(2+2): when notation is genuinely ambiguous, the useful answer is to name the ambiguity rather than to guess confidently.
The atomic weights are not single numbers any more
Here is the part that surprises people who learned chemistry before about 2010. For fourteen elements, IUPAC no longer publishes a standard atomic weight as one number. It publishes an interval, because the isotopic composition of normal terrestrial material genuinely varies from sample to sample by more than anyone can measure. Carbon is [12.0096, 12.0116]. Sulfur is [32.059, 32.076]. The full list is hydrogen, lithium, boron, carbon, nitrogen, oxygen, magnesium, silicon, sulfur, chlorine, argon, bromine, thallium and lead, and the last two of those joined only in the 2021 report.
Lead is the spectacular one: [206.14, 207.94]. That is a spread of nearly a whole mass unit, 0.87%, and the reason is a genuinely lovely piece of geology. Lead sits at the end of three separate radioactive decay chains, so the mix of lead isotopes in an ore depends on how much uranium and thorium were sitting next to it and for how long. A lead sample carries the history of the rock it came from, and that history shows up in its molar mass. So when this page computes a lead compound and warns you about the digits, it is not being fussy; the number really does depend on which mine the lead came out of.
What this calculator uses, like every periodic table on every classroom wall, is the conventional atomic weight: a single agreed value chosen to represent the interval when a single value is what you need. That is the right choice for teaching, homework and commerce. It is the wrong choice for isotope geochemistry, and the page tells you when your compound is one where the distinction bites.
Molar mass, molecular weight, formula weight: which word is right
These get used interchangeably and they are not the same thing, which matters more in an exam than in a lab. Molar mass is the mass of one mole, and it has units of g/mol. Relative molecular mass (Mr, the thing most people mean when they say molecular weight) is a ratio of the molecule's mass to one twelfth of a carbon-12 atom, so it is dimensionless. The two are numerically identical, which is exactly why nobody notices they are different quantities, and why a marked answer that says "180.16" without units can go either way.
The sharper distinction is formula weight. Sodium chloride has no molecules. Solid NaCl is a lattice in which every sodium ion is surrounded by six chlorides, and there is no group of two atoms you could point at and call a molecule. So "the molecular weight of NaCl" is describing something that does not exist; the correct term is formula weight, the mass of one formula unit. The number is still 58.44, and every result on this page is honest for both cases, but if your professor is the sort to circle it, they are right to.