The basic rule
Molecular weight = the sum of (atomic weight × atom count) for every element in the formula. Water, H2O, has 2 hydrogen atoms (atomic weight about 1.008 each) and 1 oxygen atom (atomic weight about 15.999) — the molecular weight is (2 × 1.008) + (1 × 15.999) ≈ 18.015. Every formula, no matter how complex, reduces to this same sum-of-parts calculation.
Why parentheses need special handling
A subscript after a closing parenthesis multiplies every element grouped inside it, not just the element immediately before the parenthesis. Ca(OH)2 means one calcium atom plus TWO of everything inside the parentheses — 2 oxygen and 2 hydrogen atoms, not 1 oxygen and 2 hydrogen. This gives a molecular weight of about 74.092 (calcium ≈40.078, plus 2×oxygen ≈31.998, plus 2×hydrogen ≈2.016).
A worked example with nested structure
Al2(SO4)3 (aluminum sulfate) has 2 aluminum atoms directly, plus 3 of everything inside the parentheses — 3 sulfur atoms and 3×4=12 oxygen atoms. In total: 2 aluminum + 3 sulfur + 12 oxygen = 17 atoms across 3 distinct elements, with a molecular weight of about 342.132. Getting the parentheses multiplier right is essential here — treating the "3" as applying only to sulfur (rather than to sulfur AND all 4 of its oxygens) would produce a meaningfully wrong result.
A simpler comparison — no parentheses at all
NaCl (table salt) has one sodium atom (≈22.990) and one chlorine atom (≈35.453), summing to a molecular weight of about 58.44 — no parentheses or multi-atom subscripts involved, the simplest possible case of the same underlying rule.
Why this calculation matters beyond a chemistry exercise
Molecular weight is the conversion factor between a substance's molarity (moles per liter, a count of molecules) and its mass concentration (grams or milligrams per liter, an amount of mass) — you can't convert between the two without knowing the molecular weight of the specific substance involved, since a mole of a heavy molecule weighs far more than a mole of a light one. This connection is covered directly in the companion article on molarity vs mass concentration.