Grams to moles calculator
36.03 grams of water at 18.015 g/mol is exactly 2 moles: the amount of substance is the mass divided by the molar mass. Enter grams and grams per mole to get moles with the formula shown. 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
- Moles
- 1
Amount of substance follows from the definition that links sample mass to formula weight: divide the mass of a pure substance by its molar mass to obtain moles. Laboratory notebooks, homework sets, and process recipes all ask the same question in different words—how many moles are present when I know grams and grams per mole—and the closed form n equals m over M is the answer. This calculator accepts mass in grams and molar mass in grams per mole, returns the amount of substance in moles with unit labels and the formula string for audit, and rejects zero or negative molar mass so a division by zero or non-physical denominator never becomes a silent bad number. Students first meet the relation when converting grams of water or sodium chloride into moles for stoichiometry tables; analysts use it when sizing pure solids for stock solutions; engineers use it when checking batch inventories of reagents.
How moles relate to mass and molar mass
Start from the formal definition used in general and analytical chemistry: the amount of substance n measured in moles equals the mass m of a pure sample divided by the molar mass M of that substance. Keep mass on the gram scale and molar mass on the grams-per-mole scale so the quotient lands in moles without hidden conversion factors. Negative mass is rejected because a negative sample mass is not a physical weighing for amount-of-substance work.
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.
Where grams-to-moles calculators show up in real work
Secondary-school and introductory university chemistry courses assign mass-to-moles drills that convert grams of pure solid or liquid into moles for limiting-reagent, percent-yield, and gas-law tables; a single trusted oracle speeds grading and demo setup without hand-waving floating-point noise. Analytical labs size pure reagents when a protocol specifies grams of solid and a known molar mass, then need moles for stock-solution prep or equivalence calculations.
Process chemists and chemical engineers check batch inventories when a drum or bottle holds a known mass of reagent and the next step consumes a fixed mole amount. If you later need mass from moles, moles from molarity and volume, molality from solvent mass, mole fraction from component moles, or automatic molar-mass lookup from a chemical formula, treat those as separate search intents and landings rather than overloading this grams-to-moles calculator page.
What you can do with it
Homework and lab answer keys
Compute moles n = m / M from sample mass in grams and molar mass so students and auto-graders share one closed-form ground truth.
Stock solution and reagent prep
Convert weighed grams of pure solid into moles of solute before dissolving to a target molarity or equivalence.
Batch inventory checks
Estimate moles of reagent available from a known mass on the bottle and the substance molar mass in g/mol.
FAQ
How do I convert grams to moles?
Divide the mass m in grams by the molar mass M in g/mol: n = m / M. The result is the amount of substance in moles.
What happens if molar mass is zero or negative?
Zero or negative molar mass makes n = m / M undefined or non-physical and is rejected instead of returning Infinity or NaN.
Do I enter mass in milligrams or grams?
Grams. Convert milligrams to grams by dividing by 1000 (or kilograms by multiplying by 1000) before calling so the result matches the SI-compatible mole quotient.
What does it cost?
The browser tool is free and runs locally.
Can I enter a chemical formula instead of the molar mass?
No. The calculator does not work out molar masses from formulas. Look up or calculate the molar mass in grams per mole first, then enter it next to the mass of your sample.
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/grams-to-moles \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"mass_g":18.015,"molar_mass":18.015}'const res = await fetch("https://api.kit.forhosting.com/chem/grams-to-moles", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"mass_g": 18.015,
"molar_mass": 18.015
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/chem/grams-to-moles",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"mass_g": 18.015,
"molar_mass": 18.015
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/chem/grams-to-moles", 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}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"mass_g":18.015,"molar_mass":18.015}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/chem/grams-to-moles", 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
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "chem.grams_to_moles",
"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
No network, no random seeds, and no wall-clock timestamps: identical inputs always produce identical JSON.
How moles relate to mass and molar mass
Zero or negative molar mass makes n equals m over M undefined or non-physical, so those cases fail validation with a clear invalid_input message rather than Infinity or a silent NaN. This capability evaluates the closed form 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, convert milligrams for you, invert the relation to mass from moles, or compute moles from molarity and volume, molality, mole fraction, or stoichiometric product moles; 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 giving one mole, thirty-six point zero three grams of water at the same molar mass giving two moles, and fifty-eight point four four grams of sodium chloride at molar mass fifty-eight point four four giving one mole. Keep mass on the gram scale across multi-step lab pipelines: if you weigh in milligrams, convert first so the numeric quotient still matches the mole amount your report claims. Send two required finite numbers under the fields mass_g and molar_mass. mass_g is the mass of the substance 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 the quotient is undefined or non-physical. Missing fields, non-numeric strings, NaN, Infinity, negative mass, and non-positive molar mass fail with invalid_input and are not charged. On success the response echoes cleaned mass_g and molar_mass, provides moles as the primary result in moles, includes a units hint object naming grams, grams per mole, and moles, sets method to grams_to_moles, and formula to n equals m over M 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 grams-to-moles 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.
Technical questions
Is zero mass allowed?
Yes. Zero mass yields moles = 0, which is a valid empty-sample boundary case for worksheets and tests. Negative mass is rejected.