Percent composition calculator
Water is about 11 % hydrogen and 89 % oxygen by mass: type a formula and see each element's share of the molar mass, with the atoms counted, the atomic weight used and its contribution. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
This percent composition calculator turns a chemical formula into the mass percentage of every element in one formula unit. Percent composition by mass is the classic general-chemistry check that answers how much of a compound’s molar mass comes from each element: for water you expect roughly eleven percent hydrogen and eighty-nine percent oxygen, and for glucose the carbon, hydrogen, and oxygen shares follow the same definition. The engine parses compact formulas with element symbols, integer subscripts, and nested parentheses, multiplies each atom count by a fixed standard atomic weight, divides by the total molar mass, and multiplies by one hundred. Common classroom checks include H2O, CO2, NaCl, C6H12O6, and salts such as Fe2(SO4)3 where parentheses group polyatomic ions. The path is fully deterministic with no network calls, no sampling, and no date-dependent shortcuts.
What percent composition tells you
Percent composition by mass reports how much of a compound’s formula-unit mass is attributable to each element. If a formula unit contains n_E atoms of element E with atomic weight A_E, the mass contribution of E is n_E times A_E, the molar mass M is the sum of those contributions over all elements, and the mass percent of E is one hundred times that contribution divided by M.
That definition is independent of sample size: the same percentages apply whether you weigh one milligram or one kilogram of pure compound, because they are ratios of molar contributions, not absolute masses of a particular sample. Students meet the idea when a textbook asks for the percent by mass of oxygen in a salt, when a lab asks whether an experimental composition matches a formula, or when empirical-formula problems reverse the same arithmetic.
This calculator returns the input formula string, the total molar mass of one formula unit, an elements array ordered by first appearance in the formula, and for each element the symbol, atom count, atomic mass used, mass contribution, and mass percent. There is no approximate CAS path and no live lookup of atomic weights: the engine uses a fixed internal table so results stay reproducible.
Where mass percent composition fits in study, lab work, and software
Students use percent composition when a homework set asks for the mass percent of each element in a named compound, when they check whether a proposed formula matches combustion or elemental-analysis data, or when they convert between empirical and molecular formulas after measuring composition. Teachers can pre-generate answer keys for modest formulas without trusting opaque calculator apps that silently change atomic weights or drop polyatomic groups.
Lab technicians and quality checks use the same ratios when a certificate of analysis lists element mass percents and the theoretical composition must be compared against a known formula unit. Developers call the same contract from scripts to seed deterministic test vectors for chemistry tutors, to normalize user-entered formulas before a lab notebook export, or to satisfy programming-challenge statements that demand mass percent rather than a hand-waved sketch.
What you can do with it
Homework and worksheet keys
Compute mass percent of each element from textbook formulas such as H2O, C6H12O6, or Fe2(SO4)3 before grading.
Lab and tutoring software
Normalize user-entered formulas into element mass percents for interactive lessons and composition checks.
FAQ
What does the percent composition calculator cost?
It is free in your browser on this page.
Which formulas are supported?
Compact formulas with element symbols, integer subscripts, and nested parentheses (for example H2O, Ca(OH)2, Fe2(SO4)3). Spaces and hydrate dots are rejected.
What happens if the formula is invalid?
Unknown symbols, unmatched parentheses, empty formulas, and unsupported characters fail with a clear message.
Are atomic weights looked up online?
No. The calculator uses a fixed internal standard atomic weight table so results stay deterministic and offline-safe.
Does the amount of sample change the percent composition?
No. The percentages are ratios within one formula unit, so they are the same whether you weigh one milligram or one kilogram of the pure compound. Only the formula decides them.
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/percent-composition \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"formula":"H2O"}'const res = await fetch("https://api.kit.forhosting.com/chem/percent-composition", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"formula": "H2O"
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/chem/percent-composition",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"formula": "H2O"
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/chem/percent-composition", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"formula":"H2O"}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"formula":"H2O"}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/chem/percent-composition", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"formula": "H2O"
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "chem.percent_composition",
"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.
Limits
max_formula_len | 200 |
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
What percent composition means and what the response contains
It also returns the precision used, the method tag percent_composition, a short definition string, and a unit hint mass percent. Rejected cases include a missing formula, empty strings, whitespace inside the formula, hydrate dots and other separators, unknown element symbols, unmatched parentheses, zero or missing subscripts written only as invalid tokens, and formulas that do not contain any element symbol.
How formulas are read and how mass percents stay reproducible
A valid formula is a compact string of element symbols (one capital letter, optional lowercase letter), positive integer subscripts, and nested parentheses for groups such as sulfate or hydroxide. Examples that parse cleanly include H2O, CO2, CH4, NaCl, C6H12O6, Ca(OH)2, Fe2(SO4)3, and (NH4)2SO4. Spaces are rejected so a bad paste does not become a silent misread; hydrate notation with a middle dot is also rejected with a clear message rather than partially parsed. Parentheses may nest up to a documented depth, and each closing parenthesis may carry an integer multiplier that scales every atom inside the group. The preferred field is formula, but aliases f, compound, chemical_formula, and expression are accepted so spreadsheets, query strings, and typed forms can reuse the same contract. Each symbol must exist in the built-in standard atomic weight table; unknown tokens fail with invalid_input naming the symbol. An optional precision field, with aliases decimals and dp, chooses how many decimal places to expose for molar mass, atomic masses, mass contributions, and percents, defaulting to ten and capped at fifteen so JSON goldens stay stable. Pair the free browser run on this page with the priced API when you need the identical mathematical result inside an automated pipeline without re-implementing the percent-composition formula yourself.
Where mass percent composition fits in study, lab work, and software
Product and education tools use the endpoint when a learner types a formula and the UI must show a table of element percents with a clear molar mass. On this page the work runs entirely in your browser; through the API each successful lookup costs $0.002, failed validation is not charged, and nothing is stored after the response returns. That split — free interactive exploration and a priced, identical API — matches the rest of the KIT tier-A catalog and lets you move from a classroom demo to an automated pipeline without changing the mathematical result. Pair it with molar concentration or dilution helpers when you need related solution quantities, and with other science endpoints when you are building a small lab of free, deterministic chemistry calculators.
Integration use cases
Deterministic test fixtures
Generate reproducible molar mass and mass-percent tables for unit tests, chemistry tutors, and CI assertions.
Technical questions
How is mass percent defined?
For each element E, %E = 100 × (n_E × A_E) / M, where n_E is the atom count, A_E is the atomic weight, and M is the molar mass of one formula unit.