How molar mass is calculated
Molar mass is the mass of one mole of a substance, in grams per mole (g/mol). For a compound it's the sum of the atomic weights of every atom in its formula: count the atoms of each element, multiply each count by that element's atomic weight, and add the results. The atomic weights come from the periodic table, and an element's molar mass in g/mol has the same number as its atomic weight, so that table is all you need.
Take aluminum sulfate, Al2(SO4)3. The 3 after the bracket multiplies everything inside it, so the formula holds 2 aluminum atoms, 3 sulfur atoms and 4 × 3 = 12 oxygen atoms. Multiply each count by its atomic weight: aluminum 2 × 26.982 = 53.964, sulfur 3 × 32.06 = 96.18, and oxygen 12 × 15.999 = 191.988. Add them up: 53.964 + 96.18 + 191.988 = 342.132 g/mol, or 342.13 g/mol to two decimal places.
The same subtotals give the mass percent composition: divide each one by the molar mass and multiply by 100. Aluminum is 53.964 ÷ 342.132 = 15.77% of aluminum sulfate's mass, sulfur 28.11% and oxygen 56.12%. That answers questions like how much aluminum a kilogram of the salt contains: about 158 g. Rounded percentages don't always add to exactly 100. Glucose, C6H12O6, is 40.00% carbon, 6.71% hydrogen and 53.28% oxygen, which add to 99.99% because each value is rounded on its own. The calculator shows each value correctly rounded and says when the column total drifts, instead of nudging one value to make the column look tidy.
Most wrong answers come from counting, not arithmetic. A subscript belongs only to the element or bracket directly before it, so calcium hydroxide, Ca(OH)2, has 2 oxygen and 2 hydrogen atoms but only 1 calcium: 40.078 + 2 × 15.999 + 2 × 1.0080 = 74.092 g/mol. Other common slips are forgetting a bracket's multiplier, applying it only to the first atom inside, and misreading capitals: CO is carbon monoxide at 28.010 g/mol, while Co is the metal cobalt at 58.933.
Reading brackets, hydrates and charges
Brackets group atoms that travel together, usually a polyatomic ion such as sulfate (SO4), phosphate (PO4) or ammonium (NH4). The number after the closing bracket multiplies every atom inside it, and brackets can nest. In potassium ferrocyanide, K4[Fe(CN)6], the 6 applies to each CN, and the square bracket holds one iron with six cyanides, so the formula has 4 potassium, 1 iron, 6 carbon and 6 nitrogen atoms. For counting atoms, square and curly brackets work like round ones; chemists switch shapes to keep nested groups readable, and square brackets often mark a complex ion.
A hydrate is a salt with water held in its crystals, written with a raised dot. CuSO4·5H2O is copper(II) sulfate with five waters for every CuSO4, and the 5 multiplies the whole water molecule. Work out each part and add them: the CuSO4 is 63.546 + 32.06 + 4 × 15.999 = 159.602, the water is 5 × 18.015 = 90.075, and the total is 249.677 g/mol. Water is 36.08% of that mass, which is why blue copper sulfate crystals lose just over a third of their weight when heated until dry.
On a keyboard, type the dot as *, a full stop or ·; the calculator reads all three, and a number right after the dot counts that part. A number at the very start, like the 2 in 2H2O, multiplies the whole formula, giving 36.030 g: the mass of two moles of water. Charges are ignored, so SO4^2- has the same molar mass as SO4. Electrons are so light, about 0.00055 g/mol each, that chemists use one value for an ion and its neutral formula.
Converting grams, moles and particles
Molar mass is the bridge between the mass you can weigh and the number of particles you can't see. Moles equal grams divided by molar mass (n = m ÷ M), and particles equal moles times the Avogadro constant (N = n × NA). Since the 2019 revision of the SI, the Avogadro constant is fixed at exactly 6.02214076 × 10^23 per mole, and the mole is defined as that many particles rather than by the mass of a sample of carbon-12.
How many molecules are in 10.0 g of water? Water's molar mass is 2 × 1.0080 + 15.999 = 18.015 g/mol, so 10.0 g ÷ 18.015 g/mol = 0.5551 mol. Multiply by the Avogadro constant: 0.5551 × 6.02214076 × 10^23 = 3.343 × 10^23 molecules. Going the other way, from a number of particles to grams, divide by the Avogadro constant first and then multiply by the molar mass.
Round the final answer to the significant figures of your measurement, not of the constants. 10.0 g has three, so the answer to report is 3.34 × 10^23 molecules. The converter shows four significant figures so you can round down yourself, and keeps the unrounded value between steps, which you should do on your calculator too. To typeset the working for a lab report, the LaTeX equation editor handles subscripts and powers of ten.
Why your textbook's answer may differ slightly
Atomic weights aren't fixed constants. They depend on the mix of isotopes in a sample, which varies in nature, so the IUPAC Commission on Isotopic Abundances and Atomic Weights (CIAAW) gives some of them as intervals: hydrogen between 1.00784 and 1.00811, carbon between 12.0096 and 12.0116, chlorine between 35.446 and 35.457. For everyday use the Commission also publishes an abridged table rounded to five significant digits, the form it has recommended since 2013: H 1.0080, C 12.011, Cl 35.45. This calculator uses the current abridged values.
Older books printed values with more digits, such as 1.00794 for hydrogen, 32.065 for sulfur and 35.453 for chlorine. The difference rarely shows before the second decimal place: aluminum sulfate comes to 342.13 g/mol here and 342.15 g/mol with the older values, while sodium chloride is 58.44 g/mol either way. If your course hands out its own table of atomic weights, use it for graded work. The method is the same, and so is the answer to the precision your data supports.
Some elements have no standard atomic weight at all, because nature doesn't give them a characteristic mix of isotopes: technetium, promethium, and everything from polonium onward except thorium, protactinium and uranium. Periodic tables print the mass number of the longest-lived isotope in brackets instead, such as [98] for technetium. This calculator does the same and marks the result as approximate.