Number of atoms in sample calculator
18.015 grams of water hold 1 mole of molecules and 1.806642228 × 10²⁴ atoms, since each molecule has 3. Enter the mass in grams, the molar mass and the atoms in one formula unit to count every atom in a pure sample. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Mass g
- 18.015
- Molar mass
- 18.015
- Atoms per formula unit
- 3
- Moles
- 1
- Formula units
- 602,214,076,000,000,000,000,000
- Total atoms
- 1,806,642,228,000,000,000,000,000
- Avogadro
- 602,214,076,000,000,000,000,000
Counting every atom in a weighed sample is a standard bridge between bulk laboratory mass and the microscopic world of Avogadro-scale numbers.
From grams to atoms in three steps
Counting the atoms in a weighed sample bridges what a balance shows and what happens at the scale of single particles. The calculator follows the chain taught in general chemistry. First it divides the mass in grams by the molar mass in grams per mole to get moles. Then it multiplies the moles by the Avogadro constant, 6.02214076 × 10²³ per mole, to count formula units. Finally it multiplies by the number of atoms in one formula unit. For 18.015 grams of water at 18.015 g/mol that is 1 mole, 6.02214076 × 10²³ molecules and, with 3 atoms per molecule, 1.806642228 × 10²⁴ atoms.
Where it is used and what to watch
Students meet this chain in mole-concept worksheets, and materials or analytical labs use it to turn a weigh-out into atom counts for surface coverage, defect or dopant estimates that are reported per atom. The most common mistake is the atoms-per-unit value: count every atom in the formula, so carbon dioxide has 3 and glucose has 24. The molar mass must be greater than zero, the mass cannot be negative, and the sample should be a pure substance. The calculator does not read a formula or look up molar masses, so enter the molar mass yourself.
Where number-of-atoms calculators show up in real work
Secondary-school and introductory university chemistry courses assign mass-to-atoms drills that convert grams of pure solid or liquid into total atom counts for particle models, mole-concept tables, and stoichiometry preambles; a single trusted oracle speeds grading and demo setup without hand-waving floating-point noise. Analytical and materials labs translate a weighed pure sample into atom counts when estimating monolayer coverage, defect densities, or dopant budgets that are reported per atom rather than per mole.
Process chemists and chemical engineers check how many atoms a known mass of feedstock represents when comparing bulk inventory to microscopic yield models. If you later need grams-to-moles only, automatic molar-mass lookup from a chemical formula, formula-string atom counting, mass from atom count, or moles from molarity and volume, treat those as separate search intents and landings rather than overloading this number-of-atoms-in-sample calculator page.
What you can do with it
Particle-count lab reports
Translate a pure solid weigh-out into total atoms for coverage, defect, or dopant models that report counts rather than moles alone.
FAQ
What happens if molar mass is zero?
Zero or negative molar mass makes n = m/M undefined or non-physical and is rejected instead of returning Infinity or NaN.
What does it cost?
The browser tool is free and runs locally.
What should I enter as atoms per formula unit?
Count every atom in one formula unit, whatever the element. Water and carbon dioxide have 3, oxygen gas and sodium chloride have 2, and glucose, C6H12O6, has 24. The value must be greater than zero.
What is the difference between formula units and atoms here?
Formula units are whole molecules or ion pairs, the moles times the Avogadro constant. Atoms are those units times the atoms each one contains. The calculator returns moles, formula units and total atoms, so you can see each step.
Does it work out the molar mass from a chemical formula?
No. You enter the molar mass yourself, and the calculator does not read formulas or count their atoms for you. If you only need grams to moles, or the mass of a given number of atoms, those are separate calculations.
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/number-of-atoms-in-sample \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"mass_g":18.015,"molar_mass":18.015,"atoms_per_formula_unit":3}'const res = await fetch("https://api.kit.forhosting.com/chem/number-of-atoms-in-sample", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"mass_g": 18.015,
"molar_mass": 18.015,
"atoms_per_formula_unit": 3
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/chem/number-of-atoms-in-sample",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"mass_g": 18.015,
"molar_mass": 18.015,
"atoms_per_formula_unit": 3
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/chem/number-of-atoms-in-sample", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"mass_g":18.015,"molar_mass":18.015,"atoms_per_formula_unit":3}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"mass_g":18.015,"molar_mass":18.015,"atoms_per_formula_unit":3}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/chem/number-of-atoms-in-sample", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"mass_g": 18.015,
"molar_mass": 18.015,
"atoms_per_formula_unit": 3
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "chem.number_of_atoms_in_sample",
"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
Given the mass of a pure substance, its molar mass, and how many atoms sit in one formula unit, the total atom count is the product of moles, Avogadro’s constant, and that per-unit atom count: N equals (m over M) times N_A times n_atoms. Students meet the chain when a worksheet asks how many atoms are in eighteen grams of water or twenty-four grams of carbon; analysts use it when translating a solid weigh-out into particle counts for surface-coverage or defect models; curriculum authors need a single deterministic oracle that never drifts between the free browser form and the paid API. This calculator accepts mass in grams, molar mass in grams per mole, and a positive atoms-per-formula-unit count, returns moles, formula-unit count, and total atoms with unit labels and the formula string for audit, and rejects zero or negative molar mass so a division by zero never becomes Infinity or a silent NaN. No network, no random seeds, and no wall-clock timestamps: identical inputs always produce identical JSON.
How total atoms relate to mass, molar mass, and formula units
Start from the three-step chain taught in general chemistry. First convert the sample mass m in grams into amount of substance by dividing by the molar mass M in grams per mole, so moles n equal m over M. Second, convert moles into a count of formula units by multiplying by the SI Avogadro constant N_A equals 6.02214076 times ten to the twenty-three per mole, the exact value fixed by the 2019 SI redefinition. Negative mass and non-positive atom counts are rejected because they are not physical for atom counting. Callers who only know milligrams or kilograms must convert to grams before calling, because lab tables and textbook problems standardize on grams and g/mol. Third, multiply that formula-unit count by the number of atoms inside one formula unit n_atoms: water H2O contributes three atoms, carbon dioxide CO2 three, dioxygen O2 two, sodium chloride NaCl two, glucose C6H12O6 twenty-four. The closed form collapses to N equals (m over M) times N_A times n_atoms. Zero or negative molar mass makes the first step undefined or non-physical, so those cases fail validation with a clear invalid_input message rather than Infinity. This capability evaluates the chain in deterministic floating-point arithmetic: no random seeds, no wall-clock timestamps, no network calls, and no model drift, so identical inputs always produce identical JSON. It does not look up molar masses from chemical formulas, parse a formula string to count atoms, convert milligrams for you, invert the relation to mass from atom count, or stop at moles alone; those are separate search intents with their own landings when product coverage grows.
What you send and what you get back
Classic textbook checks include eighteen point zero one five grams of water at molar mass eighteen point zero one five with three atoms per formula unit yielding one mole and three times N_A total atoms, and twelve grams of carbon-12 at molar mass twelve with one atom per formula unit yielding one mole and N_A atoms. Keep mass on the gram scale across multi-step lab pipelines: if you weigh in milligrams, convert first so the numeric chain still matches the atom count your report claims. Send three required finite numbers under the fields mass_g, molar_mass, and atoms_per_formula_unit. mass_g is the sample mass in grams and must be greater than or equal to zero. molar_mass is the molar mass in grams per mole and must be strictly greater than zero; zero or negative values fail with invalid_input because moles m over M are undefined or non-physical. atoms_per_formula_unit is the positive count of atoms in one formula unit—for example three for water or carbon dioxide, two for oxygen gas or sodium chloride, twenty-four for glucose—and zero or negative counts fail with invalid_input. Missing fields, non-numeric strings, NaN, Infinity, negative mass, non-positive molar mass, and non-positive atom counts fail with invalid_input and are not charged. On success the response echoes cleaned mass_g, molar_mass, and atoms_per_formula_unit; provides moles as the intermediate amount of substance; provides formula_units as moles times N_A; provides total_atoms as the primary result; echoes the fixed avogadro constant used; includes a units hint object naming grams, grams per mole, dimensionless atom count, moles, formula units, atoms, and per-mole; sets method to number_of_atoms_in_sample; and formula to N equals (m over M) times N_A times n_atoms so homework write-ups can cite the same expression. Pricing for successful API calls is the published base of $0.002 per item; validation failures do not consume prepaid balance.
Where number-of-atoms 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
Homework and lab answer keys
Compute total atoms N = (m/M)·N_A·n_atoms from sample mass, molar mass, and atoms per formula unit so students and auto-graders share one closed-form ground truth.
Curriculum demos and fixtures
Bulk-produce atom counts for water, salts, and simple organics with the fixed SI Avogadro constant and hard invalid_input when molar mass is zero.
Technical questions
How do I calculate the number of atoms in a sample?
Divide mass m in grams by molar mass M in g/mol to get moles, multiply by Avogadro’s constant N_A = 6.02214076×10²³ mol⁻¹, then multiply by atoms per formula unit: N = (m/M)·N_A·n_atoms.
What is atoms_per_formula_unit for common substances?
Count every atom in the formula: H2O = 3, CO2 = 3, O2 = 2, NaCl = 2, C6H12O6 = 24, elemental C = 1. The value must be a positive finite number.
Is zero mass allowed?
Yes. Zero mass yields total_atoms = 0, which is a valid empty-sample boundary case for worksheets and tests. Negative mass is rejected.