Total market surplus calculator
With demand starting at a price of 100 and falling by 2 per unit, and supply starting at 20 and rising by 3, the market clears at 16 units and a price of 68, for a total surplus of 640. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Demand intercept
- 100
- Demand slope
- 2
- Supply intercept
- 20
- Supply slope
- 3
- Equilibrium quantity
- 16
- Equilibrium price
- 68
- Consumer surplus
- 256
- Producer surplus
- 384
Total economic surplus is the classic measure of allocative welfare in a competitive market: the sum of consumer surplus (buyers’ net gain) and producer surplus (sellers’ net gain) at the equilibrium price and quantity. With linear inverse demand P equals a minus bQ and linear inverse supply P equals c plus dQ, equilibrium is a single closed-form point, and each surplus is the area of a right triangle against that price.
Linear demand, linear supply, and equilibrium surplus triangles
Textbook microeconomics writes inverse demand as price equals demand intercept a minus demand slope b times quantity, so willingness to pay falls as more units are sold. Inverse supply is price equals supply intercept c plus supply slope d times quantity, so marginal cost rises as output expands. Competitive equilibrium sets demand price equal to supply price, which rearranges to equilibrium quantity Q-star equals a minus c over b plus d, then equilibrium price P-star equals a minus b times Q-star (equivalently c plus d times Q-star).
Consumer surplus is the triangle between the demand curve and the horizontal line at P-star from quantity zero to Q-star: one-half times Q-star times a minus P-star. Producer surplus is the triangle between the supply curve and that same price line: one-half times Q-star times P-star minus c. Total surplus is their sum, which also equals one-half times Q-star times a minus c—the full vertical gap between intercepts times half the traded quantity.
That total is the standard measure of allocative efficiency for this frictionless market: every unit that buyers value above sellers’ cost is traded, and no further mutually beneficial trade remains. When intercepts or slopes violate the conditions for a positive-quantity crossing, there is no meaningful competitive equilibrium surplus to report, and the calculator rejects the input rather than inventing a negative quantity or a hollow zero.
When total market surplus is useful
Principles and intermediate micro courses use a total market surplus calculator so students can check triangle areas for arbitrary linear schedules without hand arithmetic errors on intercepts and midpoints. LMS and exam generators need a deterministic oracle that marks wrong the case of inverted intercepts or zero slopes instead of silently returning zero surplus that a buggy grader might treat as success.
Policy and consulting notebooks often compare baseline competitive surplus against tax, subsidy, or price-control scenarios; starting from a trusted free-market total surplus baseline keeps later deadweight-loss deltas honest even when those extensions live in other tools. Failed validation does not consume balance. Keep requests small, pin the rounded surplus fields in tests, and you get reproducible welfare numbers for homework, LMS plugins, and edge workers without standing up a full computational-economics stack of your own.
What you can do with it
Classroom equilibrium welfare checks
Let students enter linear demand and supply intercepts and slopes and verify equilibrium quantity, price, consumer surplus, producer surplus, and total surplus against textbook triangle methods.
LMS and exam auto-grading
Mark market-surplus items with a deterministic oracle that rejects non-positive slopes or demand intercept not above supply intercept, and never invents negative quantity.
Policy baseline for DWL notebooks
Compute the frictionless competitive total surplus as a baseline before layering taxes, floors, or ceilings in separate analysis pipelines.
FAQ
How is total market surplus calculated?
With inverse demand P=a−bQ and inverse supply P=c+dQ, Q*=(a−c)/(b+d) and P*=a−bQ*. Consumer surplus is (1/2)Q*(a−P*), producer surplus is (1/2)Q*(P*−c), and total surplus is CS+PS.
What inputs does the total market surplus calculator need?
Optional decimals (0–12, default 6) set half-up rounding.
Why must both slopes be positive?
A positive demand slope parameter b makes inverse demand downward-sloping; a positive supply slope d makes inverse supply upward-sloping. Zero or negative slopes break the standard competitive-market geometry this calculator implements.
What if the demand intercept is not above the supply intercept?
Then the curves do not cross at a positive quantity, so there is no competitive surplus to report. The calculator rejects that input instead of showing a zero or negative surplus that could pass for a real result.
Is there a shortcut for total surplus?
Yes. It equals one half of the equilibrium quantity times the gap between the two price intercepts. In the example, half of 16 times the gap between 100 and 20 gives 640, the same as 256 plus 384.
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/econ/total-surplus-market \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"demand_intercept":100,"demand_slope":2,"supply_intercept":20,"supply_slope":3}'const res = await fetch("https://api.kit.forhosting.com/econ/total-surplus-market", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"demand_intercept": 100,
"demand_slope": 2,
"supply_intercept": 20,
"supply_slope": 3
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/econ/total-surplus-market",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"demand_intercept": 100,
"demand_slope": 2,
"supply_intercept": 20,
"supply_slope": 3
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/econ/total-surplus-market", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"demand_intercept":100,"demand_slope":2,"supply_intercept":20,"supply_slope":3}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"demand_intercept":100,"demand_slope":2,"supply_intercept":20,"supply_slope":3}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/econ/total-surplus-market", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"demand_intercept": 100,
"demand_slope": 2,
"supply_intercept": 20,
"supply_slope": 3
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "econ.total_surplus_market",
"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
Input contract, response fields, and validation rules
Optionally send decimals as an integer from zero through twelve (default six) to control half-up rounding on every computed field. Both slopes must be strictly greater than zero so demand slopes down and supply slopes up. Example: demand intercept one hundred, demand slope two, supply intercept twenty, supply slope three yields Q-star sixteen, P-star sixty-eight, consumer surplus two hundred fifty-six, producer surplus three hundred eighty-four, and total surplus six hundred forty. POST a JSON body with four required finite numbers: demand_intercept (a), demand_slope (b), supply_intercept (c), and supply_slope (d). The demand intercept must be strictly greater than the supply intercept so the curves cross at a positive quantity; equal or inverted intercepts fail with invalid_input naming that rule. Missing fields, empty strings, non-finite values, and non-integer decimals outside the allowed range also fail with invalid_input and are not billed. On success the response echoes the four parameters, then returns equilibrium_quantity, equilibrium_price, consumer_surplus, producer_surplus, total_surplus (all rounded), and a formula string restating Q-star, P-star, and the three surplus identities. Pair the numbers with your own diagram if you need a plotted figure; this endpoint returns the welfare numbers only, not charts or multi-step prose beyond the formula field.
Technical questions
Why must demand_intercept be greater than supply_intercept?
Otherwise the linear curves do not cross at a positive quantity. Without a positive competitive equilibrium, consumer and producer surplus triangles are not defined in the usual way, so the task fails with invalid_input.
What does the total market surplus calculator cost?
The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid input is not billed.