GDP calculator
Consumption of 10,000, investment of 3,000, government spending of 2,500, exports of 1,500 and imports of 2,000 give a GDP of 15,000, with net exports of −500. Five published lines become one figure, without a national-accounts workbook. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Consumption
- 10,000
- Investment
- 3,000
- Government spending
- 2,500
- Exports
- 1,500
- Imports
- 2,000
- Net exports
- -500
- Gdp
- 15,000
Gross domestic product measured by the expenditure approach is the sum of consumption, investment, government spending, and net exports. Analysts, students, journalists, and policy desks use that identity to turn five published aggregates into one GDP figure without opening a national-accounts workbook. This GDP calculator takes five finite numbers in one currency — consumption, investment, government spending, exports, and imports — adds the first three, subtracts imports from exports, and returns GDP together with net exports as the intermediate.
How the expenditure approach turns C, I, G, X, and M into GDP
Gross domestic product by the expenditure approach is the value of final goods and services purchased in an economy during a period. Consumption is household final consumption expenditure — the spending of residents on goods and services, including durables, nondurables, and services — in the same currency and period as the other four fields. Investment is gross capital formation: private fixed investment plus inventory change; a destocking year can print a negative investment figure and that is still a finite input, not an error.
Government spending is government final consumption and public investment, not transfer payments, which are not purchases of current production. Exports add domestic output sold abroad; imports subtract foreign output bought at home so that consumption, investment, and government lines that include imported goods are not counted twice as domestic product.
A country with ten thousand of consumption, three thousand of investment, two thousand five hundred of government spending, one thousand five hundred of exports, and two thousand of imports prints net exports of negative five hundred and GDP of fifteen thousand. This calculator does not build a production account, an income account, a chain-weighted volume index, or a per-capita figure, and it does not convert currencies or rebase years.
You supply five finite numbers that already share one period and one currency; the calculator adds them with the textbook sign on imports and rounds GDP and net exports half-up to two decimal places so goldens compare byte-for-byte across runtimes. This is going-in GDP from the five-line expenditure identity, not GNI, not GNP, and not value added by industry.
Where a GDP calculator earns its keep
Students checking a national-accounts problem use a GDP calculator to turn the five published expenditure lines into one figure before they open a textbook appendix. Macro briefings drop last period's consumption, investment, government spending, exports, and imports from a statistical release, pin GDP and net exports, and write the rest of the note around that identity rather than around a headline that already embeds revisions they have not unpacked.
Newsrooms and data desks wire the same contract into a content workflow so a reporter can paste five numbers from a press release and quote GDP without a spreadsheet that silently changes rounding. This is a different search and a different job from a production-approach value-added sum, from an income-approach compensation-plus-surplus identity, from GNI, from GDP per capita, and from a real-GDP chain index: those tools start from different lines and answer different questions. Failed validation does not consume balance.
Keep all five fields finite, pin the rounded GDP in tests, and you get a reproducible expenditure-approach figure for classrooms, LMS plugins, and edge workers without standing up a national-accounts system of your own.
What you can do with it
Classroom national-accounts checks
Turn textbook C, I, G, X, and M into one expenditure-approach GDP figure and verify net exports before opening the appendix.
Macro briefings from a statistical release
Drop last period's five expenditure lines from the release, pin GDP and net exports, and write the note around that identity.
FAQ
How is GDP calculated with the expenditure approach?
Money amounts round half-up to two decimal places.
Why are imports subtracted from GDP?
Consumption, investment, and government spending often include imported goods. Subtracting imports keeps those purchases from being counted as domestic product. Net exports can be negative when imports exceed exports; that is a valid finite result, not an error.
What happens if a field is missing or not a number?
NaN, Infinity, empty strings, and missing fields are rejected and are not billed.
Can a component be zero or negative?
Yes. Destocking can print negative investment, and a large import bill can print negative net exports. Zero and negative finite amounts are accepted; only missing or non-finite inputs are rejected.
Do pensions and other transfer payments count as government spending?
No. Government spending here means public consumption and public investment only. Transfers such as pensions or benefits are not purchases of current production, so they belong outside GDP and should not be entered.
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/fin/gdp \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"consumption":10000,"investment":3000,"government_spending":2500,"exports":1500,"imports":2000}'const res = await fetch("https://api.kit.forhosting.com/fin/gdp", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"consumption": 10000,
"investment": 3000,
"government_spending": 2500,
"exports": 1500,
"imports": 2000
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/fin/gdp",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"consumption": 10000,
"investment": 3000,
"government_spending": 2500,
"exports": 1500,
"imports": 2000
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/fin/gdp", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"consumption":10000,"investment":3000,"government_spending":2500,"exports":1500,"imports":2000}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"consumption":10000,"investment":3000,"government_spending":2500,"exports":1500,"imports":2000}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/fin/gdp", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"consumption": 10000,
"investment": 3000,
"government_spending": 2500,
"exports": 1500,
"imports": 2000
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "fin.gdp",
"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
Any input that is missing, empty, or not a finite number fails with invalid_input and is not billed.
How the expenditure approach turns C, I, G, X, and M into GDP
The identity is gdp equals consumption plus investment plus government_spending plus net exports, and net exports equals exports minus imports.
Input contract, response shape, and error behaviour
Zero and negative amounts are allowed: a destocking year, a statistical revision, or a small open economy with a large import bill still produce a finite GDP rather than an error. Example: ten thousand of consumption, three thousand of investment, two thousand five hundred of government spending, one thousand five hundred of exports, and two thousand of imports yield net exports of negative five hundred and GDP of fifteen thousand. POST a JSON body with five required finite numbers in one currency. consumption is household or private final consumption; aliases c, private_consumption, and household_consumption map to the same field so a worksheet can keep its column names. investment is gross capital formation including inventory change; aliases i, gross_investment, and capital_formation are accepted. government_spending is government final consumption plus public investment, not transfers; aliases g, government, government_consumption, and gov are accepted. exports is goods and services sold abroad; aliases x and export are accepted. imports is goods and services bought from abroad; aliases m and import are accepted. Each numeric field may arrive as a JSON number or a numeric string. Missing fields, empty strings, and non-finite values — NaN, Infinity, or text that does not parse as a number — fail with invalid_input naming the field. Those failures are not billed. On success the body echoes consumption, investment, government_spending, exports, and imports, then reports net_exports as exports minus imports and gdp as consumption plus investment plus government_spending plus net exports, both rounded half-up to two decimal places, plus a formula string restating the identity. Pair the JSON with your own rule for which published series match those five labels — statistical offices sometimes fold inventories or non-profit institutions into neighboring lines — because this endpoint adds the five numbers you send; it does not rebuild the accounts, choose a SNA mapping, or convert currencies.
Integration use cases
Newsroom and pipeline oracles
Paste five published aggregates into a CI fixture or CMS so quoted GDP matches the identity instead of a spreadsheet rounding quirk.
Technical questions
What does the GDP calculator cost?
The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid input is not billed.