Molecular Formula Calculator
Find the molecular formula from percent composition, from the empirical formula and molar mass, from combustion analysis, or from an exact mass measured by mass spectrometry. Every answer shows the steps, the empirical formula, the multiplier, the composition and four charts.
⚡ 0. Quick Answer
To calculate a molecular formula, find the empirical formula, divide the molar mass by the empirical formula mass, and multiply every subscript by that whole number. A compound that is 40.0% C, 6.71% H and 53.3% O with a molar mass of 180.16 g/mol:
Rule of thumb: the empirical formula gives the ratio of atoms; only the molar mass gives the actual number. Formaldehyde (CH2O), acetic acid (C2H4O2) and glucose (C6H12O6) all have the empirical formula CH2O.
🔑 Key Takeaways
- A molecular formula is a whole-number multiple of the empirical formula: n = M ÷ Mempirical.
- From percent composition: assume 100 g, convert grams to moles, divide by the smallest, round to whole numbers, then multiply by n.
- C 40.0%, H 6.71%, O 53.3% gives CH2O (30.026 g/mol); with M = 180.16 g/mol, n = 6 and the molecular formula is C6H12O6.
- Combustion analysis gives C and H from the CO2 and H2O formed; oxygen comes by difference. Vitamin C works out as C6H8O6.
- An exact mass from mass spectrometry narrows the formula: caffeine’s [M+H]+ at 195.0877 fits only C8H10N4O2 within 5 ppm.
📚 1. What Is a Molecular Formula, and How Does a Molecular Formula Calculator Work?
A molecular formula gives the actual number of atoms of each element in one molecule: glucose is C6H12O6. An empirical formula gives only the simplest whole-number ratio of those atoms: CH2O. The molecular formula is always the empirical formula multiplied by a whole number n, and n is the molar mass divided by the empirical formula mass.
A molecular formula calculator does this work from whatever data you have. Elemental analysis gives percent composition or the masses of CO2 and H2O from burning a sample; that gives the empirical formula. A molar mass from a gas density, a freezing-point measurement or a mass spectrum gives n. A high-resolution mass spectrometer gives a mass so exact that it can pick out the formula directly. This calculator handles all of these, and the reverse: molecular formula to empirical formula and molecular weight.
A worked one-liner: benzene has the empirical formula CH (13.019 g/mol) and a molar mass of 78.11 g/mol. 78.11 ÷ 13.019 = 6.00, so its molecular formula is C6H6.
Who uses it: CBSE and ISC students meet empirical and molecular formulas in NCERT Class 11 (“Some Basic Concepts of Chemistry”) and JEE and NEET set them every year; GCSE, A level, AP Chemistry and IB courses include combustion analysis. In research labs, accurate-mass formula assignment is the first step in identifying an unknown from an LC-MS or GC-MS run.
| Compound | Empirical formula | n | Molecular formula | Molar mass (g/mol) |
|---|---|---|---|---|
| Glucose | CH2O | 6 | C6H12O6 | 180.156 |
| Benzene | CH | 6 | C6H6 | 78.114 |
| Hydrogen peroxide | HO | 2 | H2O2 | 34.014 |
| Dinitrogen tetroxide | NO2 | 2 | N2O4 | 92.010 |
| Water | H2O | 1 | H2O | 18.015 |
What this free molecular formula calculator solves
One tool covers every empirical and molecular formula calculation in a typical course, plus accurate-mass formula finding. It works as an empirical to molecular formula calculator, a percent composition to molecular formula calculator, a molar mass to molecular formula calculator, a molecular formula calculator from exact mass for mass spectrometry, and a molecular to empirical formula calculator that also gives the molecular weight. Press Try it to load an example into the calculator, then press the button to see the full working.
| Problem | What it works out | Example | |
|---|---|---|---|
| Molecular formula from percent composition | Empirical formula, then the molecular formula from M | C 40.0, H 6.71, O 53.3% → C6H12O6 | |
| Empirical to molecular formula | n = M ÷ Me, then multiply | CH + 78.11 g/mol → C6H6 | |
| Combustion analysis | C from CO2, H from H2O, O by difference | Vitamin C → C6H8O6 | |
| Four elements | C, H, N and O percentages | Caffeine → C8H10N4O2 | |
| Formula from an exact mass | Every formula within a ppm window, with RDBE and isotope pattern | m/z 195.0877 [M+H]+ → C8H10N4O2 | |
| Halogens in mass spectrometry | Cl and Br, with their M+2 peaks | m/z 112.0074 → C6H5Cl | |
| Formula candidates from a molar mass | Shows why a molar mass alone is not enough | 180.16 g/mol → 19 candidates | |
| Molecular to empirical formula | Divide by the greatest common divisor; molecular weight | C8H10N4O2 → C4H5N2O |
Free, with no sign-up. Everything runs in your browser: nothing you type is sent to a server or stored.
En español: ¿cómo se calcula la fórmula molecular? Calcula la fórmula empírica, divide la masa molar entre la masa de la fórmula empírica y multiplica cada subíndice por ese número entero: (CH2O) × 6 = C6H12O6.
How accurate is this molecular formula calculator?
Moles are calculated with the CIAAW 2024 standard atomic weights (Prohaska et al., 2022), or rounded exam values if you choose them. Exact-mass searches use monoisotopic masses (C = 12 exactly, H = 1.007825, N = 14.003074, O = 15.994915). Every answer is checked before it gets the Verified badge: the formula must reproduce your percentages within one percentage point, its molar mass must match the value you gave, or it must lie inside your mass window with a whole-number ring-plus-double-bond count. The R and Python scripts in Sections 10 and 11 return the same CH2O and C6H12O6 for the headline problem.
Studies of how students solve formula problems find the hard part is rounding the mole ratio correctly, not the arithmetic (Schmidt & Jignéus, 2003; Pekdağ & Azizoğlu, 2013). That is why the results show the ratio before and after rounding, and chart 2 draws them side by side.
🧮 2. Enter Your Data in the Molecular Formula Calculator
1. What data do you have?
2. Composition by mass
3. Molar mass
Press Enter in any box to calculate. Nothing is calculated until you press the button.
📊 3. Your Results: Molecular Formula Calculator with Steps
🧠 4. What Does Your Molecular Formula Mean?
4.1 Empirical formula vs molecular formula
The empirical formula tells you the ratio of atoms; the molecular formula tells you how many atoms are in one molecule. They share the same percent composition, so elemental analysis alone can never tell them apart. CH2O is 40.00% carbon whether it is formaldehyde, acetic acid or glucose. Only a molar mass (or an exact mass) fixes n.
4.2 Reading the multiplier n
n = M ÷ Me should come out within a few percent of a whole number. For glucose, 180.16 ÷ 30.026 = 6.000. A ratio such as 3.33 means the molar mass or the empirical formula is wrong: CH2O with M = 100 g/mol gives 3.33, so the calculator stops rather than guess. When n = 1, the empirical and molecular formulas are the same, as for water and methane.
4.3 Rounding the mole ratio
Experimental percentages are rounded, so the mole ratios come out close to, not exactly on, whole numbers. Treat 0.98 to 1.02 as 1. A ratio near 1.5 means multiply everything by 2; near 1.33 or 1.67 means × 3; near 1.25 or 1.75 means × 4. Never round 1.5 to 2. Vitamin C’s ratio C 1 : H 1.33 : O 1 becomes C3H4O3 after multiplying by 3.
| Ratio ends in about | Multiply by | Example |
|---|---|---|
| .00 (0.98 to 1.02) | 1 | 2.01 → 2 |
| .50 | 2 | 1.50 → 3 |
| .33 or .67 | 3 | 1.33 → 4 |
| .25 or .75 | 4 | 2.25 → 9 |
| .20, .40, .60, .80 | 5 | 1.20 → 6 |
4.4 Exact mass, ppm error and why it matters
A high-resolution mass spectrometer measures masses to a few parts per million (ppm). Because every isotope has a slightly different mass, formulas with the same nominal mass separate: CO (27.99491) and N2 (28.00615) differ by 0.011 u, which is 400 ppm. The error column shows how far each candidate is from your measurement; the closer to zero, the better, but at higher masses many formulas fit even a 5 ppm window.
4.5 Rings plus double bonds (RDBE) and the nitrogen rule
RDBE = C − H/2 + N/2 + 1 (with halogens counted like H) counts rings and π bonds. A real neutral molecule must give a whole number of zero or more. Caffeine, C8H10N4O2, has RDBE = 8 − 5 + 2 + 1 = 6. A half-number result means an odd-electron species, which is how the nitrogen rule removes impossible formulas: a neutral molecule with an odd number of nitrogen atoms has an odd nominal mass.
4.6 The isotope pattern
Natural carbon is 1.07% 13C, so a molecule with 6 carbons shows an M+1 peak about 6.5% of the main peak from carbon alone (glucose, counting its H and O too, 6.9%). Nitrogen adds 0.37% per atom: caffeine, with 8 C and 4 N, shows M+1 at 10.3%. Chlorine (24% 37Cl) gives an M+2 peak about one third of M; bromine gives M and M+2 almost equal. The calculator predicts this pattern for the top candidate so you can compare it with your spectrum.
4.7 Why a molar mass alone is not enough
Searching only an average molar mass of 180.16 g/mol, within ± 0.05 g/mol and with C, H, N and O allowed, returns 19 chemically valid formulas, including glucose (C6H12O6, 180.156) and aspirin (C9H8O4, 180.159). That is why textbooks combine the empirical formula from elemental analysis with the molar mass, and why research labs use exact masses and isotope patterns.
4.8 A field note on where these problems go wrong
In marking empirical and molecular formula work, the same errors appear again and again: rounding 1.5 to 2, dividing by the largest number of moles instead of the smallest, forgetting oxygen when the percentages do not add to 100, and using 16 g/mol for hydrogen in water calculations. Research on problem solving in chemistry finds students often follow the algorithm without checking that the answer makes sense (Nurrenbern & Pickering, 1987; Nakhleh, 1992). The calculator therefore checks that the formula reproduces your data.
4.9 What comes next
A molecular formula lists atoms, not how they are joined. C2H6O can be ethanol or dimethyl ether. The next step is structure: infrared and NMR spectroscopy, and the RDBE as a first clue. The formula’s molar mass then feeds every quantitative calculation: grams to moles, stoichiometry, concentrations and yields.
✍ 5. How to Write a Molecular Formula Answer
📌 Conventions examiners look for
- Show the table: element, mass, moles, ratio, whole number.
- Write the empirical formula mass, then n, then the molecular formula.
- Show the rounding step if you multiplied by 2, 3 or 4.
📌 Conventions
- Write organic formulas in Hill order: C first, then H, then the rest alphabetically.
- Use subscripts: C6H12O6.
📌 Conventions
- For accurate mass, give calculated and found m/z and the error in ppm, for example: HRMS (ESI) m/z [M+H]+ calcd for C8H11N4O2 195.0877, found 195.0877.
- For combustion analysis, give calculated and found percentages.
📌 Conventions
- Accept rounded atomic weights; the formula does not change.
- Use the Batch tab to make a whole worksheet answer key.
📌 Conventions
- Write subscripts as plain digits: C6H12O6.
∑ 6. Formulas for Calculating the Molecular Formula and Molecular Weight
The formula for calculating a molecular formula is n = M ÷ Me, then molecular formula = (empirical formula) × n. The formula to calculate molecular weight is M = Σ (atoms × atomic weight). Every formula the calculator uses is below, each with a worked number.
🔀 7. How to Calculate the Molecular Formula: Flowchart, Step by Step
This flowchart shows how to calculate empirical and molecular formulas, on the same problem used in the Excel, R, Python and by-hand sections: a compound is 40.0% C, 6.71% H and 53.3% O, and its molar mass is 180.16 g/mol. What is its molecular formula?
Check any box yourself: the Excel sheet in Section 9, the R script in Section 10 and the Python script in Section 11 all return CH2O and C6H12O6 for this problem.
📝 8. How to Use This Molecular Formula Calculator
- Choose the data you have. Pick percent composition, an empirical formula, combustion analysis, an exact or average mass, or a molecular formula to reduce.
- Type the percentages or grams. Write each element and its value, for example C 40.0, H 6.71, O 53.3. Tick the box to add oxygen by difference.
- Or type the empirical formula. Write it as CH2O, or tap a common empirical formula.
- Or enter the combustion data. Give the sample mass and the masses of CO2 and H2O, and nitrogen percent if you have it.
- Add the molar mass. Type it in g/mol to get the molecular formula; leave it empty to stop at the empirical formula.
- For mass spectrometry, set the search. Enter the m/z, the ion type, the ppm tolerance and the elements allowed, and optionally the M+1 peak height.
- Choose the atomic weights. Keep CIAAW 2024 values or switch to rounded exam values.
- Press the button. Nothing is calculated before you press it, and changing any input clears the old answer.
- Read the steps, the ratio chart and the check. The Verified badge means the formula reproduces your data.
- Copy, share or batch. Copy the answer, share a link, download a report, or solve a whole worksheet on the Batch tab.
📈 9. How to Calculate Empirical and Molecular Formulas in Excel
Excel handles the whole method in one small table: one row per element with its percentage and atomic weight, then columns for moles, the ratio and the whole number. Two more cells give the empirical formula mass and n. The sheet below uses the headline problem, so it must return CH2O and n = 6, the same as the molecular formula calculator above.
=ROUND(C7/C6,0) gives n. Multiply each whole number by n for the molecular formula.9.1 The functions you need
| You want | Excel formula | Note |
|---|---|---|
| Moles of each element | =B2/C2 | Grams (or %) ÷ atomic weight |
| Ratio to the smallest | =D2/MIN($D$2:$D$4) | Lock the range with $ |
| Whole number | =ROUND(E2*$H$1,0) | H1 holds the multiplier (1, 2, 3 or 4) |
| Empirical formula mass | =SUMPRODUCT(F2:F4,C2:C4) | Whole numbers × atomic weights |
| n | =ROUND(C7/C6,0) | Also show =C7/C6 to see how close it is |
| Molecular subscripts | =F2*$C$8 | Whole number × n |
| Formula as text | ="C"&G2&"H"&G3&"O"&G4 | Builds C6H12O6 |
9.2 Step by step
1 Percent to moles
Type each element in A, its percentage in B and its atomic weight in C. In D2 divide and fill down.
Moles in 100 g: 3.3303 C, 6.6567 H, 3.3315 O.
2 Ratio and whole numbers
Divide each by the smallest in column E, then round in column F.
=D2/MIN($D$2:$D$4) =ROUND(E2*$H$1,0)
Ratio 1.000 : 1.999 : 1.000, so the empirical formula is CH2O.
3 Empirical formula mass and n
SUMPRODUCT gives the empirical formula mass; divide the molar mass by it.
=SUMPRODUCT(F2:F4,C2:C4) =ROUND(C7/C6,0)
Me = 30.026; 180.16 ÷ 30.026 = 6.000, so n = 6.
4 A whole worksheet of empirical to molecular formulas
For a list, keep the empirical formula mass in B and the molar mass in C, and n in D with =ROUND(C2/B2,0).
Five empirical formulas and their multipliers in one column.
9.3 Awkward cases
- Oxygen by difference. Put
=100-SUM(B2:B3)in the O row when only C and H are given. - Combustion data. Make B2
=CO2_mass*12.011/44.009and B3=H2O_mass*2.016/18.015, and O by difference from the sample mass. - Ratios like 1.33. Set H1 to 3 and check every row in column E × 3 is near a whole number.
9.4 Why your Excel answer might differ
| Situation | What happens | Fix |
|---|---|---|
| Formula is twice too big | A ratio of 1.5 rounded up to 2 | Set the multiplier to 2 |
| n is 5.98 or 6.02 | Rounded data | That is 6; within a few percent is fine |
| n is 3.33 | Wrong molar mass or empirical formula | Recheck both |
| Slightly different moles | Exam atomic weights (C 12, O 16) | The formula is the same |
| Tool | n |
|---|---|
| Excel / Google Sheets | =ROUND(C7/C6,0) |
| R | round(molar_mass / M_emp) |
| Python | round(molar_mass / M_emp) |
| Casio fx-991EX | 180.16 ÷ (12.011 + 2 × 1.008 + 15.999) = |
9.5 Charting in Excel
- Select the elements, the whole numbers and the molecular subscripts (A2:A4, F2:G4).
- Insert → Charts → Clustered Column to compare the empirical and molecular formulas, as in Chart 2 above.
9.6 Excel errors you will probably hit
| Excel shows | Why | Fix |
|---|---|---|
#DIV/0! | An atomic weight cell is empty | Fill column C |
#VALUE! | A % sign or unit typed in a number cell | Numbers only |
| Ratios all 1 | MIN range not locked, so each row divides by itself | Use $D$2:$D$4 |
📈 10. How to Calculate the Molecular Formula in R
This base R script turns percent composition into the empirical formula, tries multipliers 1 to 8 until every ratio is within 0.1 of a whole number, finds n from the molar mass, checks that the molecular formula reproduces the percentages, and saves one 300 dpi chart. For the headline data it prints CH2O and C6H12O6, matching the molecular formula calculator on this page.
Rscript molecular_formula.R. Change only the percent and molar_mass lines.10.1 The complete script
R, base only, saves molecular_formula.png
# ============================================================
# Molecular formula calculator in R:
# percent composition -> empirical formula -> molecular formula
# StatsUnlock - https://statsunlock.com/molecular-formula-calculator/
# Base R only. No packages to install.
# ============================================================
# ---- 1. Your data --------------------------------------------------
percent <- c(C = 40.0, H = 6.71, O = 53.3) # % by mass (or grams)
molar_mass <- 180.16 # g/mol, or NA for the empirical formula only
# CIAAW 2024 standard atomic weights (g/mol); add any element you need
W <- c(H = 1.008, C = 12.011, N = 14.007, O = 15.999, F = 18.998, Na = 22.990,
Mg = 24.305, Al = 26.982, Si = 28.085, P = 30.974, S = 32.06,
Cl = 35.45, K = 39.098, Ca = 40.078, Fe = 55.845, Cu = 63.546, Br = 79.904)
# Hill order: C, then H, then the rest alphabetically
hill <- function(counts) {
k <- sort(names(counts))
if ("C" %in% k) k <- c("C", intersect("H", k), setdiff(k, c("C", "H")))
paste0(k, ifelse(counts[k] == 1, "", counts[k]), collapse = "")
}
# ---- 2. Grams -> moles -> ratio --------------------------------------
moles <- percent / W[names(percent)]
ratio <- moles / min(moles)
print(data.frame(element = names(percent), grams = as.vector(percent),
moles = round(as.vector(moles), 4), ratio = round(as.vector(ratio), 3)))
# ---- 3. Multiply until every ratio is within 0.1 of a whole number ----
k <- 1
while (k <= 8 && any(abs(ratio * k - round(ratio * k)) > 0.1)) k <- k + 1
if (k > 8) stop("No whole-number ratio up to x8: check the data")
empirical <- round(ratio * k)
M_emp <- sum(empirical * W[names(empirical)])
cat(sprintf("Empirical formula %s (x%d), M = %.3f g/mol\n", hill(empirical), k, M_emp))
# ---- 4. Molecular formula from the molar mass -----------------------
if (!is.na(molar_mass)) {
n_raw <- molar_mass / M_emp; n <- round(n_raw)
stopifnot(abs(n_raw - n) <= 0.05 * n)
molecular <- empirical * n
M_mol <- sum(molecular * W[names(molecular)])
cat(sprintf("n = %.2f / %.3f = %.3f -> %d\n", molar_mass, M_emp, n_raw, n))
cat(sprintf("Molecular formula %s, M = %.3f g/mol\n", hill(molecular), M_mol))
# ---- 5. Check: the formula reproduces the percentages ----------
pct <- 100 * molecular * W[names(molecular)] / M_mol
stopifnot(all(abs(pct - 100 * percent / sum(percent)) < 1))
cat("Verdict: Verified\n")
# ---- 6. One 300 dpi figure: empirical vs molecular atoms -------
png("molecular_formula.png", width = 2100, height = 1350, res = 300)
par(mar = c(4.5, 5, 3, 1))
barplot(rbind(empirical, molecular), beside = TRUE, names.arg = names(molecular), las = 1, border = NA,
col = c("#94a3b8", "#2563eb"), ylab = "Atoms per formula",
legend.text = c(hill(empirical), hill(molecular)),
main = sprintf("(%s) x %d = %s", hill(empirical), n, hill(molecular)))
invisible(dev.off())
cat("Saved molecular_formula.png\n")
}Output: Empirical formula CH2O (x1), M = 30.026 g/mol, n = 180.16 / 30.026 = 6.000 -> 6, Molecular formula C6H12O6, M = 180.156 g/mol, Verdict: Verified. With caffeine’s percentages and 194.2 it prints C8H10N4O2.
10.2 R traps
round(2.5)gives 2 in R (round half to even). It does not matter here because ratios are never exactly .5 after multiplying, but use care elsewhere.- Named vectors must match:
W[names(percent)]picks the right weight for each element. - The
whileloop stops at 8; if it reaches 9, the data are inconsistent.
10.3 What each part does
| Part | What it does |
|---|---|
moles <- percent / W[...] | Grams to moles |
ratio <- moles / min(moles) | Divide by the smallest |
while (... > 0.1) k <- k + 1 | Finds the multiplier for whole numbers |
round(molar_mass / M_emp) | n |
stopifnot(...) | The checks |
10.4 Packages for exact masses
For mass spectrometry, the enviPat package calculates isotope patterns and the Rdisop package decomposes an exact mass into candidate formulas, the same search the exact-mass mode of this calculator runs.
10.5 The figure
The script saves molecular_formula.png at 2100 × 1350 pixels and 300 dpi: grouped bars comparing the atoms in the empirical formula with those in the molecular formula.
🐍 11. How to Calculate the Molecular Formula in Python
This script does the same job in plain Python: moles, ratio, the multiplier search, the empirical formula, n from the molar mass, the molecular formula in Hill order, a check against your percentages and a 300 dpi chart. It is the same method the molecular formula calculator runs in your browser.
Install once: pip install matplotlib
11.1 The complete script
Python, saves molecular_formula.png
# ============================================================
# Molecular formula calculator in Python:
# percent composition -> empirical formula -> molecular formula
# StatsUnlock - https://statsunlock.com/molecular-formula-calculator/
# pip install matplotlib
# ============================================================
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
# ---- 1. Your data --------------------------------------------------
percent = {"C": 40.0, "H": 6.71, "O": 53.3} # % by mass (or grams)
molar_mass = 180.16 # g/mol, or None for the empirical formula only
# CIAAW 2024 standard atomic weights (g/mol); add any element you need
W = {"H": 1.008, "C": 12.011, "N": 14.007, "O": 15.999, "F": 18.998, "Na": 22.990,
"Mg": 24.305, "Al": 26.982, "Si": 28.085, "P": 30.974, "S": 32.06,
"Cl": 35.45, "K": 39.098, "Ca": 40.078, "Fe": 55.845, "Cu": 63.546, "Br": 79.904}
def hill(counts):
"""Write a formula in Hill order: C, then H, then the rest alphabetically."""
keys = sorted(counts)
if "C" in counts:
keys = ["C"] + (["H"] if "H" in counts else []) + [k for k in keys if k not in ("C", "H")]
return "".join(k + ("" if counts[k] == 1 else str(counts[k])) for k in keys)
# ---- 2. Grams -> moles -> ratio --------------------------------------
moles = {e: g / W[e] for e, g in percent.items()}
smallest = min(moles.values())
ratio = {e: n / smallest for e, n in moles.items()}
for e in percent:
print(f"{e}: {percent[e]} g / {W[e]} = {moles[e]:.4f} mol ratio {ratio[e]:.3f}")
# ---- 3. Multiply until every ratio is within 0.1 of a whole number ----
for k in range(1, 9):
if all(abs(r * k - round(r * k)) <= 0.1 for r in ratio.values()):
break
else:
raise SystemExit("No whole-number ratio up to x8: check the data")
empirical = {e: round(r * k) for e, r in ratio.items()}
M_emp = sum(n * W[e] for e, n in empirical.items())
print(f"Empirical formula {hill(empirical)} (x{k}), M = {M_emp:.3f} g/mol")
# ---- 4. Molecular formula from the molar mass -----------------------
if molar_mass:
n = molar_mass / M_emp
assert abs(n - round(n)) <= 0.05 * round(n), f"M / Me = {n:.3f} is not a whole number"
n = round(n)
molecular = {e: c * n for e, c in empirical.items()}
M_mol = sum(c * W[e] for e, c in molecular.items())
print(f"n = {molar_mass} / {M_emp:.3f} = {molar_mass / M_emp:.3f} -> {n}")
print(f"Molecular formula {hill(molecular)}, M = {M_mol:.3f} g/mol")
# ---- 5. Check: the formula reproduces the percentages ----------
for e, c in molecular.items():
pct = 100 * c * W[e] / M_mol
print(f" {e}: {pct:.2f}% (data {percent[e]}%)")
assert abs(pct - 100 * percent[e] / sum(percent.values())) < 1, "formula does not fit the data"
print("Verdict: Verified")
# ---- 6. One 300 dpi figure: empirical vs molecular atoms -------
els = list(molecular)
fig, ax = plt.subplots(figsize=(7, 4.5))
x = range(len(els))
ax.bar([i - 0.2 for i in x], [empirical[e] for e in els], 0.4, label=hill(empirical), color="#94a3b8")
ax.bar([i + 0.2 for i in x], [molecular[e] for e in els], 0.4, label=hill(molecular), color="#2563eb")
ax.set_xticks(list(x), els)
ax.set_ylabel("Atoms per formula")
ax.set_title(f"({hill(empirical)}) x {n} = {hill(molecular)}")
ax.legend()
fig.tight_layout()
fig.savefig("molecular_formula.png", dpi=300)
print("Saved molecular_formula.png")Output: C: 40.0 g / 12.011 = 3.3303 mol ratio 1.000, Empirical formula CH2O (x1), M = 30.026 g/mol, Molecular formula C6H12O6, M = 180.156 g/mol, Verdict: Verified.
11.2 Python traps
round()rounds half to even; ratios are compared with a 0.1 tolerance instead.- Dictionary keys are case sensitive:
"Co"is cobalt,"CO"is not an element. - The
for ... elseblock runs only when no multiplier from 1 to 8 works.
11.3 Packages
pip install pyteomics gives mass.calculate_mass(formula="C8H10N4O2") for monoisotopic masses, and molmass gives average masses, compositions and isotope spectra for any formula.
11.4 What each part does
| Part | What it does |
|---|---|
moles = {e: g / W[e] ...} | Grams to moles |
for k in range(1, 9) | Multiplier search |
n = molar_mass / M_emp | The multiplier for the molecular formula |
hill() | Writes the formula in standard order |
assert ... | The checks |
11.5 The figure
The script saves molecular_formula.png at 300 dpi with the empirical and molecular atom counts side by side.
📋 12. Empirical and Molecular Formula Tables and Worksheet
12.1 Common compounds: empirical formula, molecular formula and n
Each row was computed by the same engine as the molecular formula calculator.
| Compound | Molecular formula | Empirical formula | n | Molar mass (g/mol) | Empirical mass (g/mol) | RDBE |
|---|---|---|---|---|---|---|
| Glucose | C6H12O6 | CH2O | 6 | 180.156 | 30.026 | 1 |
| Fructose | C6H12O6 | CH2O | 6 | 180.156 | 30.026 | 1 |
| Acetic acid | C2H4O2 | CH2O | 2 | 60.052 | 30.026 | 1 |
| Formaldehyde | CH2O | CH2O | 1 | 30.026 | 30.026 | 1 |
| Lactic acid | C3H6O3 | CH2O | 3 | 90.078 | 30.026 | 1 |
| Benzene | C6H6 | CH | 6 | 78.114 | 13.019 | 4 |
| Acetylene (ethyne) | C2H2 | CH | 2 | 26.038 | 13.019 | 2 |
| Ethene | C2H4 | CH2 | 2 | 28.054 | 14.027 | 1 |
| Cyclohexane | C6H12 | CH2 | 6 | 84.162 | 14.027 | 1 |
| Butane | C4H10 | C2H5 | 2 | 58.124 | 29.062 | 0 |
| Octane | C8H18 | C4H9 | 2 | 114.232 | 57.116 | 0 |
| Hydrogen peroxide | H2O2 | HO | 2 | 34.014 | 17.007 | 0 |
| Dinitrogen tetroxide | N2O4 | NO2 | 2 | 92.010 | 46.005 | 2 |
| Phosphorus(V) oxide | P4O10 | P2O5 | 2 | 283.886 | 141.943 | 3 |
| Hydrazine | N2H4 | NH2 | 2 | 32.046 | 16.023 | 0 |
| Caffeine | C8H10N4O2 | C4H5N2O | 2 | 194.194 | 97.097 | 6 |
| Vitamin C | C6H8O6 | C3H4O3 | 2 | 176.124 | 88.062 | 3 |
| Aspirin | C9H8O4 | C9H8O4 | 1 | 180.159 | 180.159 | 6 |
| Sucrose | C12H22O11 | C12H22O11 | 1 | 342.297 | 342.297 | 2 |
| Naphthalene | C10H8 | C5H4 | 2 | 128.174 | 64.087 | 7 |
| Oxalic acid | C2H2O4 | CHO2 | 2 | 90.034 | 45.017 | 2 |
| Water | H2O | H2O | 1 | 18.015 | 18.015 | 0 |
| Methane | CH4 | CH4 | 1 | 16.043 | 16.043 | 0 |
| Ethanol | C2H6O | C2H6O | 1 | 46.069 | 46.069 | 0 |
12.2 Monoisotopic masses for mass spectrometry
| Element | Most abundant isotope | Monoisotopic mass (u) | Standard atomic weight | Main heavier isotope |
|---|---|---|---|---|
| Hydrogen | 1H | 1.007825 | 1.0080 | 2H 0.0115% |
| Carbon | 12C | 12 (exact) | 12.011 | 13C 1.07% |
| Nitrogen | 14N | 14.003074 | 14.007 | 15N 0.364% |
| Oxygen | 16O | 15.994915 | 15.999 | 18O 0.205% |
| Fluorine | 19F | 18.998403 | 18.998 | none |
| Sodium | 23Na | 22.989769 | 22.990 | none |
| Silicon | 28Si | 27.976927 | 28.085 | 29Si 4.69%, 30Si 3.09% |
| Phosphorus | 31P | 30.973762 | 30.974 | none |
| Sulfur | 32S | 31.972071 | 32.06 | 34S 4.25% |
| Chlorine | 35Cl | 34.968853 | 35.45 | 37Cl 24.24% |
| Potassium | 39K | 38.963706 | 39.098 | 41K 6.73% |
| Bromine | 79Br | 78.918338 | 79.904 | 81Br 49.31% |
| Iodine | 127I | 126.904472 | 126.90 | none |
Monoisotopic masses from the 2020 Atomic Mass Evaluation as tabulated by NIST; abundances are representative natural values. The proton is 1.007276 u and the electron 0.000549 u.
12.3 Exact masses of common molecules and ions
| Compound | Formula | Monoisotopic M (u) | [M+H]+ | [M+Na]+ | [M−H]− |
|---|---|---|---|---|---|
| Water | H2O | 18.01056 | 19.01784 | 40.99979 | 17.00329 |
| Glucose | C6H12O6 | 180.06339 | 181.07066 | 203.05261 | 179.05611 |
| Caffeine | C8H10N4O2 | 194.08038 | 195.08765 | 217.06960 | 193.07310 |
| Paracetamol | C8H9NO2 | 151.06333 | 152.07061 | 174.05255 | 150.05605 |
| Aspirin | C9H8O4 | 180.04226 | 181.04954 | 203.03148 | 179.03498 |
| Ibuprofen | C13H18O2 | 206.13068 | 207.13796 | 229.11990 | 205.12340 |
| Nicotine | C10H14N2 | 162.11570 | 163.12297 | 185.10492 | 161.10842 |
| Cholesterol | C27H46O | 386.35487 | 387.36214 | 409.34409 | 385.34759 |
| Adenine | C5H5N5 | 135.05450 | 136.06177 | 158.04372 | 134.04722 |
| Chlorobenzene | C6H5Cl | 112.00798 | 113.01525 | 134.99720 | 111.00070 |
12.4 Calculating empirical and molecular formulas: worksheet with answers
Twenty-five problems in three groups: empirical to molecular formula, percent composition to the molecular formula, and molecular to empirical formula. Every answer was checked by the calculator engine. Cover the last column and try them first.
Free printable empirical and molecular formula worksheet with answers.
| # | Question | Working | Answer |
|---|---|---|---|
| 1 | The empirical formula is CH2O and the molar mass is 180.16 g/mol. What is the molecular formula? | n = 180.16 ÷ 30.026 = 6 | C6H12O6 |
| 2 | The empirical formula is CH and the molar mass is 78.11 g/mol. What is the molecular formula? | n = 78.11 ÷ 13.019 = 6 | C6H6 |
| 3 | The empirical formula is CH2 and the molar mass is 70.13 g/mol. What is the molecular formula? | n = 70.13 ÷ 14.027 = 5 | C5H10 |
| 4 | The empirical formula is C2H5 and the molar mass is 58.12 g/mol. What is the molecular formula? | n = 58.12 ÷ 29.062 = 2 | C4H10 |
| 5 | The empirical formula is NO2 and the molar mass is 92.01 g/mol. What is the molecular formula? | n = 92.01 ÷ 46.005 = 2 | N2O4 |
| 6 | The empirical formula is HO and the molar mass is 34.01 g/mol. What is the molecular formula? | n = 34.01 ÷ 17.007 = 2 | H2O2 |
| 7 | The empirical formula is P2O5 and the molar mass is 283.89 g/mol. What is the molecular formula? | n = 283.89 ÷ 141.943 = 2 | P4O10 |
| 8 | The empirical formula is C3H4O3 and the molar mass is 176.12 g/mol. What is the molecular formula? | n = 176.12 ÷ 88.062 = 2 | C6H8O6 |
| 9 | The empirical formula is C4H5N2O and the molar mass is 194.19 g/mol. What is the molecular formula? | n = 194.19 ÷ 97.097 = 2 | C8H10N4O2 |
| 10 | The empirical formula is CH2O and the molar mass is 60.05 g/mol. What is the molecular formula? | n = 60.05 ÷ 30.026 = 2 | C2H4O2 |
| 11 | A compound is 92.3% C, 7.7% H, with M = 78.1 g/mol. Find its empirical and molecular formulas. | empirical CH, n = 6 | C6H6 |
| 12 | A compound is 85.6% C, 14.4% H, with M = 56.1 g/mol. Find its empirical and molecular formulas. | empirical CH2, n = 4 | C4H8 |
| 13 | A compound is 40.0% C, 6.71% H, 53.3% O, with M = 60.05 g/mol. Find its empirical and molecular formulas. | empirical CH2O, n = 2 | C2H4O2 |
| 14 | A compound is 49.5% C, 5.20% H, 28.9% N, 16.5% O, with M = 194.2 g/mol. Find its empirical and molecular formulas. | empirical C4H5N2O, n = 2 | C8H10N4O2 |
| 15 | A compound is 40.9% C, 4.58% H, 54.5% O, with M = 176.12 g/mol. Find its empirical and molecular formulas. | empirical C3H4O3, n = 2 | C6H8O6 |
| 16 | A compound is 30.4% N, 69.6% O, with M = 92.0 g/mol. Find its empirical and molecular formulas. | empirical NO2, n = 2 | N2O4 |
| 17 | A compound is 26.7% C, 2.24% H, 71.1% O, with M = 90.04 g/mol. Find its empirical and molecular formulas. | empirical CHO2, n = 2 | C2H2O4 |
| 18 | A compound is 54.5% C, 9.15% H, 36.3% O, with M = 88.1 g/mol. Find its empirical and molecular formulas. | empirical C2H4O, n = 2 | C4H8O2 |
| 19 | A compound is 69.9% Fe, 30.1% O. Find its empirical formula. | empirical Fe2O3 | Fe2O3 |
| 20 | A compound is 32.4% Na, 22.6% S, 45.0% O. Find its empirical formula. | empirical Na2SO4 | Na2SO4 |
| 21 | What is the empirical formula of C6H12O6, and its molecular weight? | ÷ 6 | CH2O; 180.156 g/mol |
| 22 | What is the empirical formula of C8H10N4O2, and its molecular weight? | ÷ 2 | C4H5N2O; 194.194 g/mol |
| 23 | What is the empirical formula of C2H4O2, and its molecular weight? | ÷ 2 | CH2O; 60.052 g/mol |
| 24 | What is the empirical formula of N2O4, and its molecular weight? | ÷ 2 | NO2; 92.010 g/mol |
| 25 | What is the empirical formula of C9H8O4, and its molecular weight? | ÷ 1 | C9H8O4; 180.159 g/mol |
📈 13. Molecular Formula Calculation Examples
Eight examples run through the calculator, from glucose to an accurate-mass assignment. Each figure is drawn from the computed numbers: the grey bars are the empirical formula, the blue bars the molecular formula.
Glucose from percent composition
The classic empirical to molecular formula problem.
A sugar is 40.0% C, 6.71% H and 53.3% O by mass, and its molar mass is 180.16 g/mol. Find its molecular formula.
| Element | Empirical | Molecular | Atomic weight | % by mass |
|---|---|---|---|---|
| C | 1 | 6 | 12.011 | 40.00% |
| H | 2 | 12 | 1.008 | 6.71% |
| O | 1 | 6 | 15.999 | 53.28% |
| Formula | CH2O | C6H12O6 | 180.156 g/mol |
What it means: Moles in 100 g: C 3.330, H 6.657, O 3.331, a ratio of 1 : 2 : 1, so the empirical formula is CH2O (30.026 g/mol). 180.16 ÷ 30.026 = 6, giving C6H12O6.
How to write it: Empirical CH2O; n = 180.16 ÷ 30.026 = 6; molecular formula C6H12O6
Benzene from CH
One carbon, one hydrogen, six times over.
Benzene has the empirical formula CH and a molar mass of 78.11 g/mol. What is its molecular formula?
| Element | Empirical | Molecular | Atomic weight | % by mass |
|---|---|---|---|---|
| C | 1 | 6 | 12.011 | 92.26% |
| H | 1 | 6 | 1.008 | 7.74% |
| Formula | CH | C6H6 | 78.114 g/mol |
What it means: M(CH) = 13.019 g/mol; 78.11 ÷ 13.019 = 6.000 ≈ 6. C6H6 has RDBE 4: one ring and three double bonds. Acetylene, C2H2, has the same empirical formula with n = 2.
How to write it: n = 78.11 ÷ 13.019 = 6; molecular formula C6H6
Vitamin C from CO2 and H2O
Oxygen by difference, and a ratio that needs ×3.
Burning 1.000 g of vitamin C gives 1.500 g of CO2 and 0.405 g of H2O. Its molar mass is 176.12 g/mol. Find the molecular formula.
| Element | Empirical | Molecular | Atomic weight | % by mass |
|---|---|---|---|---|
| C | 3 | 6 | 12.011 | 40.92% |
| H | 4 | 8 | 1.008 | 4.58% |
| O | 3 | 6 | 15.999 | 54.50% |
| Formula | C3H4O3 | C6H8O6 | 176.124 g/mol |
What it means: C = 0.4094 g, H = 0.04532 g, O by difference = 0.5453 g. The ratio C 1 : H 1.319 : O 1 must be multiplied by 3, giving C3H4O3. With n = 2 the molecular formula is C6H8O6 (ascorbic acid).
How to write it: Empirical C3H4O3 (88.062 g/mol); n = 2; molecular formula C6H8O6
Caffeine from C, H, N and O
Nitrogen-rich, and an empirical formula that is half the molecule.
Caffeine is 49.5% C, 5.20% H, 28.9% N and 16.5% O, with M = 194.2 g/mol. Find its molecular formula.
| Element | Empirical | Molecular | Atomic weight | % by mass |
|---|---|---|---|---|
| C | 4 | 8 | 12.011 | 49.48% |
| H | 5 | 10 | 1.008 | 5.19% |
| N | 2 | 4 | 14.007 | 28.85% |
| O | 1 | 2 | 15.999 | 16.48% |
| Formula | C4H5N2O | C8H10N4O2 | 194.194 g/mol |
What it means: The ratio is 4 : 5 : 2 : 1, so the empirical formula is C4H5N2O (97.097 g/mol) and n = 2: C8H10N4O2. Its RDBE of 6 fits the two fused rings and four double bonds of caffeine.
How to write it: Empirical C4H5N2O; n = 194.2 ÷ 97.097 = 2; molecular formula C8H10N4O2
Oxalic acid
A small empirical formula, CHO2.
A dicarboxylic acid is 26.7% C, 2.24% H and 71.1% O, with M = 90.04 g/mol. Find its molecular formula.
| Element | Empirical | Molecular | Atomic weight | % by mass |
|---|---|---|---|---|
| C | 1 | 2 | 12.011 | 26.68% |
| H | 1 | 2 | 1.008 | 2.24% |
| O | 2 | 4 | 15.999 | 71.08% |
| Formula | CHO2 | C2H2O4 | 90.034 g/mol |
What it means: The mole ratio is 1 : 1 : 2, so the empirical formula is CHO2 (45.017 g/mol). 90.04 ÷ 45.017 = 2, giving C2H2O4, oxalic acid.
How to write it: Empirical CHO2; n = 2; molecular formula C2H2O4
Butane from C2H5
An empirical formula need not be a real molecule.
A gas has the empirical formula C2H5 and a molar mass of 58.12 g/mol. What is it?
| Element | Empirical | Molecular | Atomic weight | % by mass |
|---|---|---|---|---|
| C | 2 | 4 | 12.011 | 82.66% |
| H | 5 | 10 | 1.008 | 17.34% |
| Formula | C2H5 | C4H10 | 58.124 g/mol |
What it means: C2H5 = 29.062 g/mol cannot exist as a stable molecule (it has an odd number of H). n = 2 gives C4H10, butane.
How to write it: n = 58.12 ÷ 29.062 = 2; molecular formula C4H10
Phosphorus(V) oxide
Named after its empirical formula, built as a dimer.
Phosphorus(V) oxide has the empirical formula P2O5 and a molar mass of 283.89 g/mol. Find its molecular formula.
| Element | Empirical | Molecular | Atomic weight | % by mass |
|---|---|---|---|---|
| P | 2 | 4 | 30.974 | 43.64% |
| O | 5 | 10 | 15.999 | 56.36% |
| Formula | P2O5 | P4O10 | 283.886 g/mol |
What it means: M(P2O5) = 141.943 g/mol, n = 2, so the molecule is P4O10. The name “phosphorus pentoxide” comes from the empirical formula.
How to write it: n = 283.89 ÷ 141.943 = 2; molecular formula P4O10
Caffeine from its exact mass
Five parts per million leaves one formula.
An LC-MS peak shows [M+H]+ at m/z 195.0877. Which formula fits within 5 ppm (C, H, N, O allowed)?
| Element | Empirical | Molecular | Atomic weight | % by mass |
|---|---|---|---|---|
| C | 4 | 8 | 12.011 | 49.48% |
| H | 5 | 10 | 1.008 | 5.19% |
| N | 2 | 4 | 14.007 | 28.85% |
| O | 1 | 2 | 15.999 | 16.48% |
| Formula | C4H5N2O | C8H10N4O2 | 194.194 g/mol |
What it means: Subtracting a proton gives M = 194.0804. Only 1 formula fits: C8H10N4O2, error -0.25 ppm, RDBE 6. Its predicted M+1 of 10.3% confirms 8 carbons and 4 nitrogens.
How to write it: HRMS (ESI) m/z [M+H]+ calcd for C8H11N4O2 195.0877, found 195.0877
✏️ 14. How to Calculate Empirical and Molecular Formulas by Hand
This is the written method examiners expect, on the same problem as Sections 7, 9, 10 and 11: 40.0% C, 6.71% H, 53.3% O, molar mass 180.16 g/mol.
14.1 How to calculate molecular formula from percent composition, step by step
- Assume 100 g. C 40.0 g, H 6.71 g, O 53.3 g.
- Convert to moles. C 40.0 ÷ 12.011 = 3.330; H 6.71 ÷ 1.008 = 6.657; O 53.3 ÷ 15.999 = 3.331.
- Divide by the smallest (3.330). C 1.000, H 1.999, O 1.000.
- Round, or multiply first if needed. 1 : 2 : 1, so the empirical formula is CH2O.
- Empirical formula mass. 12.011 + 2 × 1.008 + 15.999 = 30.026 g/mol.
- Find n. 180.16 ÷ 30.026 = 6.00.
- Multiply. (CH2O)6 = C6H12O6.
- Check. M(C6H12O6) = 180.156 g/mol, and its percentages, 40.00% C, 6.71% H and 53.28% O, match the data.
14.2 How to calculate the molecular formula from the empirical formula
If the empirical formula is given, start at step 5. Example: the empirical formula of a compound is C2H5 and its molar mass is 58.12 g/mol. Me = 2 × 12.011 + 5 × 1.008 = 29.062 g/mol; n = 58.12 ÷ 29.062 = 2.00; the molecular formula is C4H10 (butane).
14.3 How to calculate the molecular formula from combustion analysis
Burning 1.000 g of vitamin C gives 1.500 g CO2 and 0.405 g H2O. Carbon: 1.500 × 12.011 ÷ 44.009 = 0.4094 g; hydrogen: 0.405 × 2.016 ÷ 18.015 = 0.04532 g; oxygen by difference: 1.000 − 0.4094 − 0.0453 = 0.5453 g. Moles: C 0.03408, H 0.04496, O 0.03408; ratio 1 : 1.319 : 1; × 3 gives C3H4O3 (88.062 g/mol). With M = 176.12 g/mol, n = 2 and the molecular formula is C6H8O6.
14.4 How to calculate the empirical formula from the molecular formula
Divide every subscript by their greatest common divisor. C6H12O6: gcd(6, 12, 6) = 6, giving CH2O. C8H10N4O2: gcd = 2, giving C4H5N2O. If the gcd is 1, as for C9H8O4, the two formulas are the same.
14.5 How to calculate the molecular mass from the empirical formula
Multiply the empirical formula mass by n: M = n × Me. For (NO2)2, M = 2 × 46.005 = 92.010 g/mol. To find n you still need one experimental value: a molar mass, a gas density or an exact mass.
14.6 On a scientific calculator
On a Casio fx-991EX or fx-82MS: 40 ÷ 12.011 = gives 3.330 (store it with STO A). Repeat for H and O. For n: 180.16 ÷ ( 12.011 + 2 × 1.008 + 15.999 ) = gives 6.0001.
Keep four significant figures in the moles and ratios; rounding to two figures too early can turn 1.33 into 1.3 and hide the × 3. Key names differ between models; check your manual.
14.7 Do it in the lab: the empirical formula of magnesium oxide
Burning magnesium ribbon in a crucible
- Weigh a clean, dry crucible and lid. Add about 0.25 g of cleaned magnesium ribbon, coiled, and weigh again.
- Heat strongly with the lid on, lifting it slightly now and then with tongs to let air in without losing white smoke.
- When the magnesium no longer glows, heat for 2 minutes more with the lid off, let it cool and weigh. Reheat to constant mass.
- Mass of oxygen = final mass − mass of crucible and magnesium. Convert both masses to moles and find the ratio.
Hazards: burning magnesium gives an intense white light; do not look directly at it. The crucible and pipeclay triangle get very hot: use tongs and a heatproof mat. Wear eye protection and follow your school’s risk assessment.
Main errors: losing white MgO smoke (oxygen too low), unreacted magnesium (oxygen too low), and magnesium reacting with nitrogen to form Mg3N2 (adding a few drops of water and reheating converts it).
| Measurement | Mass (g) | Moles |
|---|---|---|
| Crucible and lid | 25.000 | |
| Crucible, lid and magnesium | 25.240 | |
| After heating to constant mass | 25.398 | |
| Magnesium | 0.240 | 0.00987 mol (÷ 24.305) |
| Oxygen gained | 0.158 | 0.00988 mol (÷ 15.999) |
Example data. Ratio O : Mg = 0.00988 ÷ 0.00987 = 1.000, so the empirical formula is MgO. A ratio below about 0.9 usually means magnesium oxide smoke escaped or some magnesium was not burned.
14.8 Molecular formula practice problems with answers
Ten practice problems, easy to hard. Open each one to see the answer.
1. The empirical formula of a compound is CH2 and its molar mass is 70.13 g/mol. Find the molecular formula.
M(CH2) = 12.011 + 2 × 1.008 = 14.027 g/mol; n = 70.13 ÷ 14.027 = 5.000 ≈ 5; (CH2) × 5 = C5H10. Answer: C5H10
2. A compound is 92.3% C and 7.7% H with M = 78.1 g/mol. Find its empirical and molecular formulas.
C 92.30 g, H 7.700 g; C: 92.30 ÷ 12.011 = 7.6846 mol; H: 7.700 ÷ 1.008 = 7.6389 mol; C: 1.006; H: 1.000; CH; M(CH) = 12.011 + 1.008 = 13.019 g/mol; n = 78.1 ÷ 13.019 = 5.999 ≈ 6; (CH) × 6 = C6H6. Answer: C6H6
3. A compound is 30.4% N and 69.6% O; its molar mass is 92.0 g/mol. Find its molecular formula.
N 30.40 g, O 69.60 g; N: 30.40 ÷ 14.007 = 2.1703 mol; O: 69.60 ÷ 15.999 = 4.3503 mol; N: 1.000; O: 2.004; NO2; M(NO2) = 14.007 + 2 × 15.999 = 46.005 g/mol; n = 92.0 ÷ 46.005 = 2.000 ≈ 2; (NO2) × 2 = N2O4. Answer: N2O4
4. Ethyl acetate is 54.5% C, 9.15% H and 36.3% O with M = 88.1 g/mol. Find its molecular formula.
C 54.50 g, H 9.150 g, O 36.30 g; C: 54.50 ÷ 12.011 = 4.5375 mol; H: 9.150 ÷ 1.008 = 9.0774 mol; O: 36.30 ÷ 15.999 = 2.2689 mol; C: 2.000; H: 4.001; O: 1.000; C2H4O; M(C2H4O) = 2 × 12.011 + 4 × 1.008 + 15.999 = 44.053 g/mol; n = 88.1 ÷ 44.053 = 2.000 ≈ 2; (C2H4O) × 2 = C4H8O2. Answer: C4H8O2
5. A compound contains 40.0% C and 6.71% H; the rest is oxygen. M = 60.05 g/mol. Find its molecular formula.
C 40.00 g, H 6.710 g, O 53.29 g; O = 100 − 46.71 = 53.29%; C: 40.00 ÷ 12.011 = 3.3303 mol; H: 6.710 ÷ 1.008 = 6.6567 mol; O: 53.29 ÷ 15.999 = 3.3308 mol; C: 1.000; H: 1.999; O: 1.000; CH2O; M(CH2O) = 12.011 + 2 × 1.008 + 15.999 = 30.026 g/mol; n = 60.05 ÷ 30.026 = 2.000 ≈ 2; (CH2O) × 2 = C2H4O2. Answer: C2H4O2
6. Burning 0.250 g of a hydrocarbon gives 0.785 g CO2 and 0.321 g H2O. Find its empirical formula.
m(C) = 0.785 g × 12.011 ÷ 44.009 = 0.21424 g; m(H) = 0.321 g × 2 × 1.008 ÷ 18.015 = 0.035922 g; C: 0.2142 ÷ 12.011 = 0.0178 mol; H: 0.03592 ÷ 1.008 = 0.0356 mol; C: 1.000; H: 1.998; CH2. Answer: CH2
7. What is the empirical formula of C6H12O6, and its molecular weight?
C 6, H 12, O 6; gcd(6, 12, 6) = 6; C6H12O6 ÷ 6 = CH2O; M(C6H12O6) = 6 × 12.011 + 12 × 1.008 + 6 × 15.999 = 180.156 g/mol; Me = 30.026 g/mol. Answer: CH2O, 180.156 g/mol
8. Iron oxide is 69.9% Fe and 30.1% O. Find its empirical formula.
Fe 69.90 g, O 30.10 g; Fe: 69.90 ÷ 55.845 = 1.2517 mol; O: 30.10 ÷ 15.999 = 1.8814 mol; Fe: 1.000; O: 1.503; × 2: Fe 2.00, O 3.01; Fe2O3. Answer: Fe2O3
9. An [M+H]+ ion is at m/z 152.0706. Which formula (C, H, N, O) fits within 5 ppm?
M = 152.0706 − 1.007276 = 151.06332 u; C 0–40, N 0–6, O 0–12, H 0–80; window ± 5 ppm (± 0.76 mDa); 1 formula passes; C8H9NO2: 151.06333 u, error +0.03 ppm, RDBE 5. Answer: C8H9NO2
10. A compound with the empirical formula CH2O has M = 100 g/mol. What is wrong?
n = 100 ÷ 30.026 = 3.33, which is not a whole number. A molecular formula must be a whole multiple of the empirical formula, so either M or the empirical formula is wrong. The calculator stops with this message rather than guess.
Want more practice on paper? Print the worksheet and check your answers.
14.9 Mistakes that lose marks
Research on chemistry problem solving finds students often apply an algorithm correctly but cannot say why each step works, so errors go unnoticed (Nurrenbern & Pickering, 1987; Gabel & Sherwood, 1984).
- Rounding 1.5 to 2 instead of multiplying everything by 2.
- Dividing by the largest number of moles instead of the smallest.
- Forgetting oxygen when the percentages add to less than 100.
- Using the percentages directly as a ratio without dividing by atomic weights.
- Rounding the moles to two figures before taking the ratio.
- Giving the empirical formula when the question asks for the molecular formula.
- Writing C6H12O6 as 6CH2O: a coefficient is not a subscript.
✅ 15. When Should You Use a Molecular Formula Calculator?
- You have elemental analysis or combustion data for an unknown compound.
- You know the empirical formula and a molar mass.
- You have an accurate mass from a mass spectrum.
- You need the empirical formula or molecular weight of a known formula.
- How the atoms are joined (isomers share a formula): use IR and NMR.
- The molecular formula from percentages alone: you also need M.
- The formula of an ionic solid, which has no molecules: its empirical formula is its formula.
- Which of several candidates is right from an average molar mass alone.
Four real examples
| Situation | Data | Result |
|---|---|---|
| A white sugar from a lab analysis | C 40.0%, H 6.71%, O 53.3%; M = 180.16 | C6H12O6 |
| Combustion analysis of vitamin C | 1.000 g → 1.500 g CO2 + 0.405 g H2O; M = 176.12 | C6H8O6 |
| An LC-MS peak | [M+H]+ 195.0877, ± 5 ppm | C8H10N4O2 (caffeine) |
| Burning magnesium in a crucible | 0.240 g Mg gains 0.158 g O | MgO |
Decision tree
- Do you have percentages or element masses? Yes: percent composition mode. No: go on.
- Do you have masses of CO2 and H2O from burning? Yes: combustion mode.
- Do you have an empirical formula? Yes: add the molar mass in the empirical mode.
- Do you have only a mass spectrum? Yes: exact-mass mode, then confirm with the isotope pattern.
🔧 16. Molecular Formula Calculator Troubleshooting
"Not close to a whole number"
Cause: the molar mass is not a whole multiple of the empirical formula mass. Fix: check both. CH2O with M = 100 gives 3.33; either the molar mass or the empirical formula is wrong.
"No whole-number ratio up to ×8"
Cause: percentages rounded too much, or an element missing. Fix: use at least three significant figures, and tick “the rest is oxygen” if the percentages add to less than 100.
"The percentages add to more than 100"
Cause: a typing error or the same element twice. Fix: check each value; the total should be 99.5 to 100.5.
My formula has twice the atoms I expected
Cause: the molar mass you used belongs to a dimer, or the ratio was multiplied. Fix: check the source of M; in the empirical mode the calculator shows n and the multiples in chart 3.
"The carbon and hydrogen weigh more than the sample"
Cause: the CO2 and H2O masses were swapped or include water absorbed from the air. Fix: recheck the absorber masses.
No formula fits my exact mass
Cause: the wrong ion type, a narrow tolerance, or an element not allowed. Fix: try [M+Na]+ as well as [M+H]+, widen to 10 ppm, and allow S, Cl or Br if the isotope pattern suggests them.
Too many formulas fit my mass
Cause: a wide window or a high mass. Fix: narrow the ppm tolerance, limit the elements, and enter the observed M+1 height to rank candidates by carbon number.
"Element symbols start with a capital letter"
Cause: a lowercase formula such as ch2o. Fix: press the suggested formula, or type CH2O.
The empirical formula looks odd, such as C2H5
Cause: nothing: empirical formulas need not be real molecules. Fix: add the molar mass. C2H5 with M = 58.12 is butane, C4H10.
My textbook answer uses different atomic weights
Cause: rounded exam values. Fix: switch atomic weights; the moles change slightly but the formula does not.
⚖️ 17. Assumptions and Limitations of the Molecular Formula Calculator
| Assumption | What it requires | How to check | If it fails |
|---|---|---|---|
| Pure sample | Only the compound was analysed | Melting point, chromatography | Percentages are a mix of compounds and the ratio will not round cleanly |
| Complete combustion | All C becomes CO2 and all H becomes H2O | Excess oxygen, a catalyst | Carbon is too low |
| Accurate molar mass | Within a few percent | Repeat measurements | n cannot be found reliably |
| Even-electron neutral molecule (mass mode) | Whole-number RDBE | Ion type chosen correctly | Radicals and unusual ions are rejected |
| Natural isotope abundance | No labelling | Sample history | Isotope patterns and exact masses differ |
Limitations. A molecular formula calculator gives the number of each atom, never the structure: C2H6O is both ethanol and dimethyl ether. The exact-mass search lists every formula that fits; the right one must be confirmed with the isotope pattern, fragmentation or NMR. The ratio search tries multipliers up to 8 with a tolerance of 0.1.
🎯 18. Conclusion
What the answer is
The molecular formula is the empirical formula multiplied by n = M ÷ Me. For 40.0% C, 6.71% H, 53.3% O and M = 180.16 g/mol, that is (CH2O) × 6 = C6H12O6.
What it means chemically
The formula fixes how many atoms of each element are in one molecule, and so its molar mass, its unsaturation (RDBE) and its isotope pattern. It does not fix the structure.
Watch out for
Divide by the smallest number of moles, multiply instead of rounding ratios like 1.5 or 1.33, add oxygen by difference when it is missing, and never skip the molar mass when the question asks for the molecular formula.
Next steps
Practise with the worksheet in Section 12.4 and the ten problems in Section 14.8, then use the molar mass of your formula for grams-to-moles and stoichiometry calculations.
❓ 19. Frequently Asked Questions
What is a molecular formula calculator?
A molecular formula calculator finds the actual number of atoms of each element in a molecule from experimental data: percent composition, combustion analysis, an empirical formula with a molar mass, or an exact mass from mass spectrometry. This one shows every step and checks that the formula reproduces your data.
How do you calculate a molecular formula in chemistry?
Find the empirical formula, work out its mass, divide the molar mass by that mass to get a whole number n, and multiply every subscript by n. For CH2O (30.026 g/mol) and M = 180.16 g/mol, n = 6 and the molecular formula is C6H12O6.
How do you calculate the molecular formula from the empirical formula?
Divide the molar mass by the empirical formula mass and multiply the empirical formula by the result. Benzene: CH is 13.019 g/mol, 78.11 / 13.019 = 6, so the molecular formula is C6H6.
How do you calculate the molecular formula from percent composition?
Assume 100 g so each percentage is grams, divide each by its atomic weight to get moles, divide by the smallest, round (or multiply first) to whole numbers for the empirical formula, then multiply by n = M / empirical mass. 40.0% C, 6.71% H and 53.3% O with M = 180.16 g/mol gives C6H12O6.
How do you calculate the molecular formula from molar mass?
You need the empirical formula as well. Divide the molar mass by the empirical formula mass, round to a whole number n, and multiply. A molar mass on its own fits many formulas: 180.16 g/mol matches 19 C, H, N, O formulas within 0.05 g/mol.
How do you calculate empirical and molecular formulas?
The empirical formula comes from the mole ratio of the elements (percentages divided by atomic weights, then by the smallest). The molecular formula is the empirical formula multiplied by n = molar mass / empirical formula mass.
How do you calculate the empirical formula from the molecular formula?
Divide every subscript by their greatest common divisor. C6H12O6 becomes CH2O, and C8H10N4O2 becomes C4H5N2O. If the subscripts share no factor, the two formulas are the same.
How do you calculate a molecular formula from combustion analysis?
Carbon = mass of CO2 x 12.011 / 44.009, hydrogen = mass of H2O x 2.016 / 18.015, oxygen = sample mass minus C and H. Then find the empirical formula and multiply by n. Burning 1.000 g of vitamin C gives 1.500 g CO2 and 0.405 g H2O, which leads to C3H4O3 and, with M = 176.12, C6H8O6.
What do you do when the mole ratio is 1.5 or 1.33?
Multiply every ratio by the same whole number before rounding: by 2 for 1.5, by 3 for 1.33 or 1.67, by 4 for 1.25 or 1.75. Never round 1.5 up to 2.
How do you find a molecular formula from an exact mass (mass spectrometry)?
Convert the ion m/z to the neutral mass (for [M+H]+ subtract 1.007276), then search every combination of C, H, N, O and any other allowed elements whose monoisotopic mass lies within a few ppm, keeping only formulas with a whole-number RDBE of zero or more. Caffeine's [M+H]+ at 195.0877 fits only C8H10N4O2 within 5 ppm.
What is the difference between molecular mass and exact mass?
Molecular mass (molar mass) uses average atomic weights: caffeine is 194.194 g/mol. Exact (monoisotopic) mass uses the most abundant isotope of each element: caffeine is 194.08038 u. Mass spectrometers measure the exact mass of each isotope peak.
What is the formula for calculating molecular weight?
Molecular weight = sum of (number of atoms x atomic weight) over every element in the formula. For C6H12O6: 6 x 12.011 + 12 x 1.008 + 6 x 15.999 = 180.156 g/mol. It is also n times the empirical formula mass.
How do you calculate the molecular mass from the empirical formula?
Multiply the empirical formula mass by n: M = n x Me. You still need one experimental value to know n. For (NO2)2, M = 2 x 46.005 = 92.010 g/mol.
What is RDBE (rings plus double bonds)?
RDBE = C - H/2 - X/2 + N/2 + 1, where X is the number of halogen atoms. It counts rings and pi bonds and must be a whole number of zero or more for a neutral molecule. Benzene, C6H6, has RDBE 4: one ring and three double bonds.
How does the isotope pattern help confirm a formula?
Each carbon adds about 1.1% to the M+1 peak, so 8 carbons give about 8.7%; caffeine, which also has 4 nitrogens, shows M+1 at 10.3% of M. One chlorine gives an M+2 peak about one third of M, and one bromine gives M+2 about equal to M. Matching the predicted pattern removes most wrong candidates.
Can two compounds have the same molecular formula?
Yes. Isomers share a molecular formula but differ in structure: C2H6O is ethanol and dimethyl ether, and C6H12O6 is glucose, fructose and galactose. Spectroscopy, not the formula, tells them apart.
Can the empirical and molecular formulas be the same?
Yes, when n = 1. Water (H2O), methane (CH4), carbon dioxide (CO2) and aspirin (C9H8O4) all have identical empirical and molecular formulas.
How do you calculate a molecular formula in Excel?
Put each element's percentage and atomic weight in two columns, use =B2/C2 for moles, =D2/MIN($D$2:$D$4) for the ratio and =ROUND(E2,0) for whole numbers, then =SUMPRODUCT for the empirical formula mass and =ROUND(M/Me,0) for n. Section 9 shows the sheet.
How do you calculate a molecular formula in Python or R?
Divide the percentages by atomic weights, divide by the smallest, try multipliers 1 to 8 until every ratio is within 0.1 of a whole number, then multiply by round(M / Me). Sections 10 and 11 have complete, tested scripts that print CH2O and C6H12O6 for the headline problem.
Where can I find empirical and molecular formula worksheet answers?
Section 12.4 has a 25-question worksheet with answers in three groups: empirical to molecular formula, percent composition to the molecular formula, and molecular to empirical formula. Section 14.8 has ten more worked problems, and the Batch tab solves a whole list at once.
📑 20. Cite This Tool
StatsUnlock Team. (2026). Molecular formula calculator [Interactive chemistry tool]. StatsUnlock. https://statsunlock.com/molecular-formula-calculator/@misc{statsunlock_molformula_2026, title={Molecular Formula Calculator}, author={{StatsUnlock Team}}, year={2026}, note={Interactive chemistry tool}, url={https://statsunlock.com/molecular-formula-calculator/}}Molecular formulas were determined with the StatsUnlock Molecular Formula Calculator (2026) from elemental composition and molar mass, using CIAAW 2024 standard atomic weights.🔗 21. Related Tools
Quick arithmetic for moles and ratios.
Open tool →Solve n = M ÷ Me or rearrange any formula.
Open tool →Test whether measured percentages differ from a formula.
Open tool →How many repeat analyses an experiment needs.
Open tool →How big a difference between two methods is.
Open tool →Check an experiment can detect the change you expect.
Open tool →The chance of a false positive or a missed real effect.
Open tool →How much variation in an ANOVA your treatment explains.
Open tool →Finding n is algebra, and deciding whether a measured percentage really differs from the formula’s is statistics; these tools cover both.
📖 22. Glossary of Formula Terms
| Term | Plain-English meaning |
|---|---|
| Adduct ion | An ion formed by adding H+, Na+ or NH4+ to a molecule in a mass spectrometer. |
| Combustion analysis | Burning a sample and weighing the CO2 and H2O to find its carbon and hydrogen. |
| Elemental analysis | Measuring the percent by mass of each element in a compound. |
| Empirical formula | The simplest whole-number ratio of atoms, such as CH2O. |
| Empirical formula mass (Me) | The sum of the atomic weights in the empirical formula. |
| Exact (monoisotopic) mass | The mass using the most abundant isotope of each element. |
| Hill order | C first, H second, then the other elements alphabetically. |
| Isomer | A compound with the same molecular formula as another but a different structure. |
| Isotope pattern | The set of M, M+1, M+2 peaks caused by heavier isotopes. |
| m/z | Mass-to-charge ratio, the quantity a mass spectrometer measures. |
| Molar mass (M) | The mass of one mole of a substance, in g/mol. |
| Mole ratio | The ratio of moles of each element in a compound. |
| Molecular formula | The actual number of atoms of each element in a molecule. |
| Molecular weight | Another name for molar mass, or relative molecular mass with no unit. |
| Multiplier (n) | M ÷ Me, the number of empirical units in one molecule. |
| Nitrogen rule | A neutral molecule with an odd number of N atoms has an odd nominal mass. |
| Percent composition | The percentage by mass of each element. |
| ppm (mass error) | Parts per million: (measured − calculated) ÷ calculated × 106. |
| RDBE | Rings plus double bonds: the degree of unsaturation. |
| Structural formula | A formula that shows how the atoms are joined. |
📚 23. References
Peer-reviewed sources for the methods and data used in this molecular formula calculator: standard atomic weights, the mole, accurate-mass formula assignment, and research on how students learn formulas and the mole concept.
- Dori, Y. J., & Hameiri, M. (2003). Multidimensional analysis system for quantitative chemistry problems: Symbol, macro, micro, and process aspects. Journal of Research in Science Teaching, 40(3), 278–302. https://doi.org/10.1002/tea.10077
- Furió, C., Azcona, R., & Guisasola, J. (2002). The learning and teaching of the concepts ‘amount of substance’ and ‘mole’: A review of the literature. Chemistry Education Research and Practice, 3(3), 277–292. https://doi.org/10.1039/B2RP90023H
- Güttler, B., Bettin, H., Brown, R. J. C., Davis, R. S., Mester, Z., Milton, M. J. T., ... Stock, M. (2019). Amount of substance – the Avogadro constant and the SI unit “mole”. Metrologia, 56(4), 044002. https://doi.org/10.1088/1681-7575/ab1fae
- Gabel, D. L., & Sherwood, R. D. (1984). Analyzing difficulties with mole-concept tasks by using familiar analog tasks. Journal of Research in Science Teaching, 21(8), 843–851. https://doi.org/10.1002/tea.3660210806
- Kind, T., & Fiehn, O. (2007). Seven Golden Rules for heuristic filtering of molecular formulas obtained by accurate mass spectrometry. BMC Bioinformatics, 8, 105. https://doi.org/10.1186/1471-2105-8-105
- Krishnan, S. R., & Howe, A. C. (1994). The mole concept: Developing an instrument to assess conceptual understanding. Journal of Chemical Education, 71(8), 653–655. https://doi.org/10.1021/ed071p653
- Marquardt, R., Meija, J., Mester, Z., Towns, M., Weir, R., Davis, R., & Stohner, J. (2018). Definition of the mole (IUPAC Recommendation 2017). Pure and Applied Chemistry, 90(1), 175–180. https://doi.org/10.1515/pac-2017-0106
- Meija, J., Coplen, T. B., Berglund, M., Brand, W. A., De Bièvre, P., Gröning, M., ... Prohaska, T. (2016). Atomic weights of the elements 2013 (IUPAC Technical Report). Pure and Applied Chemistry, 88(3), 265–291. https://doi.org/10.1515/pac-2015-0305
- Mills, I. M., Mohr, P. J., Quinn, T. J., Taylor, B. N., & Williams, E. R. (2006). Redefinition of the kilogram, ampere, kelvin and mole: A proposed approach to implementing CIPM recommendation 1 (CI-2005). Metrologia, 43(3), 227–246. https://doi.org/10.1088/0026-1394/43/3/006
- Nakhleh, M. B. (1992). Why some students don’t learn chemistry: Chemical misconceptions. Journal of Chemical Education, 69(3), 191–196. https://doi.org/10.1021/ed069p191
- Newell, D. B., Cabiati, F., Fischer, J., Fujii, K., Karshenboim, S. G., Margolis, H. S., ... Ullrich, J. N. (2018). The CODATA 2017 values of h, e, k, and NA for the revision of the SI. Metrologia, 55(1), L13–L16. https://doi.org/10.1088/1681-7575/aa950a
- Nurrenbern, S. C., & Pickering, M. (1987). Concept learning versus problem solving: Is there a difference? Journal of Chemical Education, 64(6), 508–510. https://doi.org/10.1021/ed064p508
- Pekdağ, B., & Azizoğlu, N. (2013). Semantic mistakes and didactic difficulties in teaching the “amount of substance” concept: A useful model. Chemistry Education Research and Practice, 14(1), 117–129. https://doi.org/10.1039/C2RP20132A
- Prohaska, T., Irrgeher, J., Benefield, J., Böhlke, J. K., Chesson, L. A., Coplen, T. B., ... Zhu, X. (2022). Standard atomic weights of the elements 2021 (IUPAC Technical Report). Pure and Applied Chemistry, 94(5), 573–600. https://doi.org/10.1515/pac-2019-0603
- Sanger, M. J. (2005). Evaluating students’ conceptual understanding of balanced equations and stoichiometric ratios using a particulate drawing. Journal of Chemical Education, 82(1), 131–134. https://doi.org/10.1021/ed082p131
- Schmidt, H.-J., & Jignéus, C. (2003). Students’ strategies in solving algorithmic stoichiometry problems. Chemistry Education Research and Practice, 4(3), 305–317. https://doi.org/10.1039/B3RP90018E
- Staver, J. R., & Lumpe, A. T. (1995). Two investigations of students’ understanding of the mole concept and its use in problem solving. Journal of Research in Science Teaching, 32(2), 177–193. https://doi.org/10.1002/tea.3660320206
- Tiesinga, E., Mohr, P. J., Newell, D. B., & Taylor, B. N. (2021). CODATA recommended values of the fundamental physical constants: 2018. Reviews of Modern Physics, 93(2), 025010. https://doi.org/10.1103/RevModPhys.93.025010
- Wang, M., Huang, W. J., Kondev, F. G., Audi, G., & Naimi, S. (2021). The AME 2020 atomic mass evaluation (II). Tables, graphs and references. Chinese Physics C, 45(3), 030003. https://doi.org/10.1088/1674-1137/abddaf
- Yarroch, W. L. (1985). Student understanding of chemical equation balancing. Journal of Research in Science Teaching, 22(5), 449–459. https://doi.org/10.1002/tea.3660220507





