Molecular formula calculator
Type an empirical formula such as CH2O and a molar mass of 180.156 g/mol, and get C6H12O6 with the multiplier 6. Atomic weights are added up for you, and a mass that is not a whole multiple is flagged. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Empirical
- CH2O
- Molar mass
- 180.156
- Empirical molar mass
- 30.02598
- Multiplier
- 6
- Molecular formula
- C6H12O6
The molecular formula of a pure compound states how many atoms of each element sit in one molecule, while the empirical formula states only the simplest whole-number ratio of those atoms. When you already know the empirical formula and you measure or look up the compound molar mass in grams per mole, the classical bridge is a single division: n equals the molecular molar mass divided by the empirical formula mass. If n is a positive whole number, every empirical subscript is multiplied by n to recover the molecular formula. Students meet this step after percent-composition work on glucose, hydrogen peroxide, benzene, and many laboratory unknowns. This calculator parses a plain empirical formula string, sums standard atomic weights, checks that the mass ratio is an integer within a small numerical tolerance, and returns the molecular formula together with the multiplier, both element maps, unit labels, and the defining formula string.
How empirical mass and the multiplier n recover a molecular formula
Begin with a valid empirical formula written as ordinary element symbols with optional integer subscripts, for example CH2O for a carbohydrate building block, HO for the peroxide ratio, or CH for an aromatic hydrocarbon ratio. The service expands that string into counts per element and multiplies each count by the conventional atomic weight from a fixed internal table to obtain the empirical formula molar mass in grams per mole. Divide the supplied compound molar mass by that empirical mass to obtain the ratio n.
In the ideal textbook case n is exactly an integer such as two, three, or six; in real homework data the molar mass is often rounded, so the calculator accepts a small absolute tolerance around the nearest integer and then locks n to that integer. On success every empirical subscript is multiplied by n and the molecular formula string is rebuilt in the same element order as the empirical input, so CH2O with n equals six becomes C6H12O6 and HO with n equals two becomes H2O2.
Parentheses, hydrate dots, and unknown element symbols are rejected up front so callers fix the notation instead of silently mis-counting atoms.
Where molecular formula calculators show up in real work
Secondary-school and introductory university chemistry courses assign the empirical-to-molecular step after combustion analysis and percent composition, and instructors need a single oracle that either returns a clean formula string or rejects a non-integer mass ratio without hand-waving. Laboratory teaching assistants grade unknown organic solids where students measure melting behavior and molar mass by freezing-point depression or mass spectrometry and must scale the empirical ratio they already found.
Process and analytical chemists sometimes re-check supplier certificates that list an empirical-style ratio alongside a molecular weight and need a fast whole-multiple gate before accepting a batch identity claim. If you later need percent composition to empirical formula, reaction balancing, molar mass from a molecular formula alone, or hydrate coefficient parsing, treat those as separate search intents and landings rather than overloading this molecular formula calculator page.
What you can do with it
Homework and exam answer keys
Scale empirical formulas by the integer n = M / M_empirical so teachers and auto-graders share one ground truth molecular formula string.
Lab unknowns and molar-mass checks
Verify that a measured compound molar mass is a whole multiple of the empirical mass before reporting the molecular formula on a lab sheet.
FAQ
What is the difference between empirical and molecular formulas?
The empirical formula is the simplest whole-number ratio of atoms (for example CH2O). The molecular formula is an integer multiple of that ratio (for example C6H12O6) and matches the true molar mass of the molecule.
What happens if the molar mass is not a whole multiple?
A non-integer ratio means the molar mass and empirical formula are inconsistent, so no molecular formula is returned.
Which formula formats are accepted?
Plain strings of element symbols with optional integer subscripts such as CH2O, HO, or Fe2O3. Parentheses, hydrate dots, and unknown element symbols are rejected.
What does it cost?
The browser tool is free and runs locally.
Do I have to calculate the empirical formula mass myself?
No. The calculator adds up standard atomic weights for every element in the formula you type, so CH2O comes to 30.02598 g/mol. It then divides your molar mass by that value to find the multiplier.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/chem/molecular-formula \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"empirical_formula":"CH2O","molar_mass":180.156}'const res = await fetch("https://api.kit.forhosting.com/chem/molecular-formula", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"empirical_formula": "CH2O",
"molar_mass": 180.156
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/chem/molecular-formula",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"empirical_formula": "CH2O",
"molar_mass": 180.156
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/chem/molecular-formula", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"empirical_formula":"CH2O","molar_mass":180.156}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"empirical_formula":"CH2O","molar_mass":180.156}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/chem/molecular-formula", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"empirical_formula": "CH2O",
"molar_mass": 180.156
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "chem.molecular_formula",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
When the molar mass is not a whole multiple of the empirical mass, the request fails with a clear validation error instead of inventing a fractional molecule.
How empirical mass and the multiplier n recover a molecular formula
If the nearest integer is less than one, or if the residual beyond the tolerance is still large, the molar mass is treated as not a whole multiple of the empirical mass and the call fails with invalid_input rather than emitting a fractional molecule. The pipeline is pure deterministic floating-point arithmetic: no random seeds, no wall-clock timestamps, no network lookups of live tables, and no model drift, so identical inputs always produce identical JSON.
What you send and what you get back
The formula string may include spaces that are stripped, but it must not contain parentheses, hydrate dots, or decimal subscripts. Each token must be a recognized chemical symbol such as C, H, O, Fe, or Cl followed by an optional positive integer subscript; a missing subscript means one atom of that element in the empirical unit. Classic checks include CH2O with molar mass about one hundred eighty point one five six giving C6H12O6, HO with molar mass about thirty-four point zero one five giving H2O2, and a deliberately non-multiple molar mass that must error. Send two required fields: empirical_formula as a string and molar_mass as a finite positive number in grams per mole. Missing fields, empty strings, non-numeric molar mass, NaN, Infinity, non-positive molar mass, unknown symbols, and unparseable tails fail with invalid_input and are not charged. On success the response echoes a normalized empirical_formula, the cleaned molar_mass, the computed empirical_molar_mass, the integer multiplier, the molecular_formula string, empirical_elements and elements maps, a units object labeling both masses as grams per mole, method set to empirical_to_molecular_by_mass_ratio, and formula set to n equals M_molecular over M_empirical with molecular equals n times empirical. Pricing for successful API calls is the published base of $0.002 per item; validation failures do not consume prepaid balance.
Where molecular formula calculators show up in real work
Because this capability is a pure parse engine, API pricing is the published base of $0.002 per successful item and failed validation does not consume balance.
Integration use cases
Curriculum and LMS fixtures
Generate stable JSON fixtures for interactive chemistry lessons that teach empirical versus molecular formulas without non-determinism.
Technical questions
How does this molecular formula calculator work?
It parses the empirical formula, sums standard atomic weights to get M_empirical, computes n = molar_mass / M_empirical, requires n to be a positive whole number within a small tolerance, and multiplies every subscript by n.