Gross margin calculator
Revenue of 100,000 with 60,000 of cost of goods sold leaves a gross profit of 40,000, a 40% gross margin. Enter a period's net sales and cost of goods sold to compare product lines, stores or months before overhead, interest and tax. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Revenue
- 100,000
- Cogs
- 60,000
- Gross profit
- 40,000
- Gross margin percent
- 40
Gross margin is the first profitability line on an income statement: what remains after subtracting cost of goods sold from revenue, both as a currency amount and as a percentage of sales. Operators, merchandisers, lenders, and equity analysts use that pair of figures to compare product lines, store formats, and reporting periods without mixing in overhead, interest, or tax. This gross margin calculator takes two finite numbers in one currency — revenue and cost of goods sold — subtracts COGS from revenue, divides the difference by revenue, and returns the margin amount together with the margin percent.
How gross margin turns revenue and cost of goods sold into amount and percent
Gross margin is the merchandising profit that sits above operating expenses, interest, and tax. Revenue is net sales for the period in one currency — the top line after returns and allowances, not a unit price and not a collection of invoices still sitting in accounts receivable. Subtracting COGS from revenue is the gross-profit amount; dividing that amount by revenue is the gross-margin percentage people search for when they type gross margin calculator.
A one-hundred-thousand revenue and sixty-thousand COGS print a gross profit of forty thousand and a margin of forty percent. Zero COGS is a legitimate outcome and is not an error: a digital good with no inventory cost still has a gross margin of one hundred percent. When COGS exceeds revenue the amount and the percent are negative — a gross loss — which this calculator reports instead of hiding behind an absolute value.
Revenue that is zero or negative is rejected: dividing by a zero top line is undefined, and a negative top line is not the gross-margin percentage a close pack or a merchandising review is asking for. This calculator does not compute operating margin, net profit margin, or markup on cost. It does not split selling, general, and administrative expense from COGS, does not convert currencies, and does not rebuild a full income statement.
You supply two finite numbers that already share one period and one currency; the calculator subtracts them, divides, and rounds the amount half-up to two decimal places and the percent half-up to six so goldens compare byte-for-byte across runtimes.
Where a gross margin calculator earns its keep
Merchandisers screening a weekly flash use a gross margin calculator to turn last period's net sales and cost of goods sold into one amount and one percent before they open a full income-statement model. Retail operators pin that pair next to category mix and promotional depth so a price cut that moved units is not mistaken for a healthy margin.
Lenders and credit analysts re-run the same two fields when a year closes or a borrowing-base pack asks for gross profit, then sit that figure next to inventory turns rather than next to operating profit that already embeds rent and payroll. Equity desks drop revenue from the filing and COGS from the notes, and they compare that gross margin with a contribution-margin case and an operating-margin case rather than treating any one of those as a substitute.
This is a different search and a different job from a profit-margin calculator that starts from selling price and a lumped cost, from a markup-to-margin converter that never sees revenue, and from an EBIT identity that subtracts operating expenses and depreciation: those tools start from different lines and answer different questions. Failed validation does not consume balance.
Keep revenue strictly positive, keep both fields finite, pin the rounded amount and percent in tests, and you get a reproducible gross-margin figure for teasers, LMS plugins, and edge workers without standing up a general ledger of your own.
What you can do with it
Weekly merchandising flash
Turn last period's net sales and cost of goods sold into one gross-profit amount and one margin percent before you open a full income-statement model.
Retail category mix reviews
Pin gross margin next to promotional depth so a price cut that moved units is not mistaken for a healthy merchandising margin.
Lender packs and inventory turns
Drop filing revenue and notes COGS into one going-in gross profit beside inventory turns, separate from operating profit that already embeds rent.
FAQ
How is gross margin calculated?
The amount rounds half-up to two decimal places and the percent rounds half-up to six.
Why is zero or negative revenue rejected?
A zero top line would divide by zero. A negative top line is not a gross-margin percentage a close pack is asking for. Zero COGS is allowed and prints a 100% margin.
What happens if a field is missing or not a number?
NaN, Infinity, empty strings, and missing fields are rejected and are not billed.
Is this the same as profit margin, operating margin, or markup?
No. Gross margin is revenue minus cost of goods sold, as an amount and as a percent of revenue. Profit margin often lumps all costs against price. Operating margin subtracts opex and D&A. Markup is profit as a percent of cost, not of sales.
What should count as cost of goods sold?
The cost of the inventory or direct service that produced the period's sales: purchases adjusted for opening and closing stock, or the standard cost of the units sold. Rent, salaries in head office and other overheads stay out of it.
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/gross-margin \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"revenue":100000,"cogs":60000}'const res = await fetch("https://api.kit.forhosting.com/fin/gross-margin", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"revenue": 100000,
"cogs": 60000
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/fin/gross-margin",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"revenue": 100000,
"cogs": 60000
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/fin/gross-margin", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"revenue":100000,"cogs":60000}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"revenue":100000,"cogs":60000}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/fin/gross-margin", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"revenue": 100000,
"cogs": 60000
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "fin.gross_margin",
"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
Revenue that is zero or negative fails with invalid_input and is not billed, because a non-positive top line makes the percentage undefined or meaningless.
How gross margin turns revenue and cost of goods sold into amount and percent
The identity this calculator uses is gross_profit equals revenue minus cogs, and gross_margin_percent equals that difference divided by revenue times one hundred. Cost of goods sold is the period cost of the inventory or direct service that produced those sales: purchases adjusted for opening and closing stock, or the standard cost rolled through units sold.
Input contract, response shape, and error behaviour
Zero COGS is allowed and prints a one-hundred-percent margin. Negative COGS is allowed as a finite credit or inventory reversal; the difference follows that sign. Example: one hundred thousand of revenue and sixty thousand of COGS yield a gross profit of forty thousand and a gross margin of forty percent. Example: eighty thousand of revenue and ninety-five thousand of COGS yield a gross loss of fifteen thousand and a margin of minus eighteen point seven five percent. POST a JSON body with two required finite numbers in one currency. revenue is the period top line and must be strictly greater than zero; aliases sales, total_revenue, turnover, and net_sales map to the same field so a worksheet can keep its column names. cogs is the period cost of goods sold; aliases cost_of_goods_sold, cost_of_sales, and cost_of_revenue 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. Zero or negative revenue also fails with invalid_input, because the percentage would be undefined or meaningless. On success the body echoes revenue and cogs, then reports gross_profit as revenue minus cogs rounded half-up to two decimal places, gross_margin_percent as that raw difference divided by revenue times one hundred rounded half-up to six decimal places, plus a formula string restating the identity. Pair the JSON with your own rule for which COGS definition matches the revenue you send — inventory, standard cost, or cost of sales on the face of the statement — because this endpoint subtracts the two numbers you send; it does not rebuild the ledger, choose a costing convention, or convert currencies. Pricing is a flat $0.002 per successful request.
Technical questions
What does the gross margin calculator cost?
The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid input is not billed.