# Moles to Grams Calculator

> Converts between mass in grams and amount in moles using the molar mass (from a formula or given directly), and reports the number of molecules or formula units from the Avogadro constant. Any two of molar mass, mass and moles give the third.

- Calculator id: `moles-mass` · Category: Chemistry (`chemistry`) · Tool name: `convert_moles_and_mass`
- Canonical page: https://tttkmbb.com/chemistry/moles-mass · This document: https://tttkmbb.com/chemistry/moles-mass.md · JSON definition: https://tttkmbb.com/chemistry/moles-mass.json

## Purpose

Converts between mass in grams and amount in moles using the molar mass (from a formula or given directly), and reports the number of molecules or formula units from the Avogadro constant. Any two of molar mass, mass and moles give the third.

**Use when:** You need to convert grams to moles or moles to grams for a substance, count the molecules in a sample, or back out a molar mass from a measured mass and amount.

**Do not use when:** You only need the molar mass of a formula (use molar-mass), or you want a concentration in mol/L (use molarity).

## Input

| Parameter | Type | Unit | Required | Description |
| --- | --- | --- | --- | --- |
| `formula` | string |  | optional | Chemical formula, e.g. NaCl, C6H12O6, Ca(OH)2 or CuSO4·5H2O (case-sensitive element symbols). Alternative to molar_mass_g_mol. |
| `molar_mass_g_mol` | number | g/mol | optional | Molar mass of the substance; use instead of formula when it is already known. (> 0, max 10000000) |
| `mass_g` | number | g | optional | Mass of the sample in grams. Leave empty to solve for it. (> 0) |
| `moles` | number | mol | optional | Amount in moles. Leave empty to solve for it. (> 0) |

## Output

| Field | Type | Unit | Description |
| --- | --- | --- | --- |
| `molar_mass_g_mol` | number | g/mol | Molar mass used or derived (mass_g / moles). |
| `mass_g` | number | g | Mass of the sample. |
| `moles` | number | mol | Amount of substance. |
| `millimoles` | number | mmol | Amount in millimoles. |
| `molecules` | number |  | moles × 6.02214076×10²³ (molecules for molecular substances, formula units for ionic compounds, atoms for elements). |
| `molecules_scientific` | string |  | The same count in scientific notation. |
| `solved_for` | string |  | Which quantity was computed: mass_g, moles or molar_mass_g_mol. |

## Formula

`moles = mass_g / molar_mass_g_mol; mass_g = moles × molar_mass_g_mol; molecules = moles × N_A (N_A = 6.02214076×10²³ mol⁻¹)`

## Data Sources

- NIST – CODATA internationally recommended values of the fundamental physical constants (Avogadro constant N_A = 6.02214076×10²³ mol⁻¹, exact) — https://physics.nist.gov/cuu/Constants/index.html (standard, retrieved 2026-09-23)
- IUPAC – Atomic Weights of the Elements (2021 table with 2023 revisions, Queen Mary University of London mirror) — https://iupac.qmul.ac.uk/AtWt/ (standard, retrieved 2026-09-23)
- OpenStax Chemistry 2e – 3.1 Formula Mass and the Mole Concept — https://openstax.org/books/chemistry-2e/pages/3-1-formula-mass-and-the-mole-concept (textbook, retrieved 2026-09-23)

Data freshness: `static`. Deterministic formula with fixed constants; results never go stale. Inputs supplied by the caller determine the output.

## API

- `GET https://tttkmbb.com/api/v1/calculate/moles-mass?`
- `POST https://tttkmbb.com/api/v1/calculate/moles-mass` with JSON body `{"inputs": {…}}`
- Response: unified envelope (`success`, `request`, `result.values`, `result.units`, `sources`, `freshness`, `timestamp`, `next_actions`, `links`); see https://tttkmbb.com/docs/response-format.md
- Schema: https://tttkmbb.com/api/v1/calculators/moles-mass · OpenAPI operationId `convert_moles_and_mass` in https://tttkmbb.com/openapi.json
- Authentication: none. Rate limit: fair use, see https://tttkmbb.com/docs/rate-limits.md.

## MCP

- Server: `https://tttkmbb.com/mcp` (Streamable HTTP, JSON-RPC 2.0, no auth)
- Tool:  `run_calculator` with `{"calculator_id": "moles-mass", "inputs": {…}}`

## Example

- 36.03 g of water: inputs `{"formula":"H2O","mass_g":36.03}` → `{"molar_mass_g_mol":18.015,"moles":2,"millimoles":2000,"molecules":1.204428152e+24,"solved_for":"moles"}`
- 0.5 mol of CO2: inputs `{"formula":"CO2","moles":0.5}` → `{"molar_mass_g_mol":44.009,"mass_g":22.0045,"molecules":3.01107038e+23,"solved_for":"mass_g"}`

```
GET https://tttkmbb.com/api/v1/calculate/moles-mass?formula=H2O&mass_g=36.03
```

## Limitations

You only need the molar mass of a formula (use molar-mass), or you want a concentration in mol/L (use molarity). All values are computed from the formula above; no measurement or live data is involved.

## FAQ

**How do I get the molar mass without a formula?**

Give molar_mass_g_mol directly, or give both mass_g and moles and the calculator returns molar_mass_g_mol = mass_g / moles (useful for identifying an unknown).

**Does 'molecules' apply to ionic compounds?**

For NaCl or CaCO3 the count is formula units rather than discrete molecules; for a monatomic element it is the number of atoms.

## Related

- [Molar Mass Calculator](https://tttkmbb.com/chemistry/molar-mass.md) — Look up or check the molar mass and composition of the formula.
- [Molarity Calculator](https://tttkmbb.com/chemistry/molarity.md) — Use the moles to compute a solution concentration.
- [Ideal Gas Law Calculator](https://tttkmbb.com/chemistry/ideal-gas-law.md) — Relate moles of a gas to its pressure, volume and temperature.
