Calculate profit margin percentage
Revenue of 250,000 with a cost of goods sold of 150,000 leaves a gross profit of 100,000 and a gross margin of 40%. Use it to check a product line against your target before changing prices. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Revenue
- 250,000
- Cogs
- 150,000
- Gross profit
- 100,000
- Gross margin percent
- 40
Given total revenue and the cost of goods sold (COGS), this calculator returns the gross profit and the gross margin percentage, the two figures that describe how much of each sales dollar survives the direct cost of producing what was sold.
What gross profit and gross margin percentage mean
Gross profit is revenue minus the cost of goods sold: the money left after paying for the materials, labor, and direct expenses of the units sold, before rent, marketing, taxes, or any other overhead. Gross margin percentage expresses that same profit as a share of revenue, computed as (revenue - COGS) / revenue * 100. The two numbers answer different questions.
Gross profit is an absolute amount, useful for covering fixed costs and measuring the raw contribution of a period or a product line. Gross margin percentage is a ratio, useful for comparing products, periods, or companies of very different sizes on an equal footing. For example, a revenue of 250000 with a COGS of 150000 yields a gross profit of 100000 and a gross margin of 40 percent: forty cents of every sales dollar remains after direct costs.
The output echoes the revenue and COGS you supplied alongside the computed figures, so a stored result is self-describing and can be audited without recovering the original request. Both fields are always present and finite.
Inputs, validation, and edge cases
A COGS of zero is valid and yields a 100 percent margin, which correctly describes a business with no direct costs. A COGS above revenue is also valid: it produces a negative gross profit and a negative margin percentage, which is the correct signal for goods sold below their direct cost, not an error condition. The optional decimals field is an integer from 0 to 8 and defaults to 2, giving high-precision unit economics room when needed.
Strings, nulls, missing fields, NaN, and infinities are all rejected before any arithmetic happens, each with a message that identifies the offending field and the expectation it violated.
What you can do with it
Check the health of a product line
Enter the period revenue and the direct cost of a product line to see its gross margin percentage, and compare it against your target before deciding on pricing changes.
Quantify loss-making sales
Test a COGS above revenue to see the exact negative gross profit and margin, measuring how deep a discount or cost overrun cuts into each sale.
FAQ
How is the gross margin percentage calculated?
Gross margin percent is (revenue - COGS) / revenue * 100. With revenue 250000 and COGS 150000, the margin is 40 percent.
Why does revenue have to be positive?
Revenue is the denominator of the margin percentage, so zero or negative revenue cannot produce a meaningful ratio.
Can COGS be zero?
Yes. A zero COGS is valid and produces a 100 percent gross margin, which describes a business with no direct costs.
What if the cost of goods sold is higher than revenue?
That is valid and gives a negative gross profit and a negative margin, which is the correct signal for goods sold below their direct cost. It shows exactly how deep a discount or a cost overrun cuts into each sale.
What is the difference between gross profit and gross margin?
Gross profit is an amount: 250,000 in revenue minus 150,000 in direct costs leaves 100,000. Gross margin is that profit as a share of revenue, 40%, which lets you compare products or periods of very different sizes.
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/biz/profit-margin-calc \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"revenue":250000,"cogs":150000}'const res = await fetch("https://api.kit.forhosting.com/biz/profit-margin-calc", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"revenue": 250000,
"cogs": 150000
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/biz/profit-margin-calc",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"revenue": 250000,
"cogs": 150000
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/biz/profit-margin-calc", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"revenue":250000,"cogs":150000}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"revenue":250000,"cogs":150000}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/biz/profit-margin-calc", 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": 250000,
"cogs": 150000
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "biz.profit_margin_calc",
"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
It validates every input, rejects non-positive revenue with a typed error, and rounds with an explicit deterministic half-up rule so the same numbers always produce the same output.
Inputs, validation, and edge cases
Two fields are required. revenue is a finite number strictly greater than zero; because revenue is the denominator of the margin percentage, a zero or negative revenue cannot produce a meaningful ratio and is rejected with a typed invalid_input error that names the field, rather than returning a division by zero or a misleading figure. cogs is a finite number greater than or equal to zero.
Rounding, determinism, and how to consume the result
Rounding uses an explicit half-up rule on the exact IEEE 754 result, applied independently to gross_profit and gross_margin_percent, so a raw value of 12.345 becomes 12.35 instead of drifting through a locale-dependent formatter. To integrate, POST a JSON body with revenue and cogs and read gross_profit and gross_margin_percent from the response; no authentication scope beyond a standard API key is required, and the contract is stable across the eight translated landings that surround it.
Integration use cases
Audit margins in bulk
Send each SKU's revenue and COGS through the API and flag every item whose gross_margin_percent falls below your profitability threshold.
Technical questions
What happens if COGS is higher than revenue?
The tool returns a negative gross_profit and a negative gross_margin_percent, which correctly signals a loss-making sale. It is a valid result, not an error.
How much does the API cost?
Each successful call costs $0.002. Failed calls, including validation errors, are never charged.