Profit margin calculator
Enter a cost and a selling price to get profit, margin and markup side by side: a cost of 80 sold at 100 is a 20% margin but a 25% markup. Selling below cost shows the loss as a negative margin. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Cost
- 80
- Price
- 100
- Profit
- 20
- Profit margin (%)
- 20
- Markup (%)
- 25
Computes profit, gross margin percentage, and markup percentage from a unit cost and a selling price, distinguishing the two ratios that are often confused.
Profit, margin and markup, and how they differ
From a cost and a price this tool returns three numbers. Profit is simply price - cost. Margin percent is (price - cost) / price * 100, expressing profit as a share of the selling price.
Markup percent is (price - cost) / cost * 100, expressing the same profit as a share of the cost. These two ratios are routinely confused: a cost of 80 sold at 100 yields a 20% margin but a 25% markup, and the tool returns both so you never mix them up. The output echoes the cost and price you supplied so a stored result is self-describing without needing the original request.
Fields, validation and edge cases
Two fields are required: cost, a finite number greater than or equal to 0, and price, a finite number greater than or equal to 0. A price below the cost is allowed and simply produces a negative profit and negative margin, which is the correct signal for a loss-making sale rather than an error. The optional decimals field is an integer from 0 to 8 and defaults to 2, giving finance workflows room for high-precision unit economics.
What you can do with it
Price a product correctly
Enter your landed cost and target price to see the true margin, and avoid the classic mistake of quoting markup as if it were margin.
Model discounts and losses
Test a price below cost to see the negative profit and margin, quantifying exactly how deep a promotional discount cuts.
FAQ
What is the difference between margin and markup?
Margin is profit as a percent of price; markup is the same profit as a percent of cost. Cost 80 at price 100 is a 20% margin but a 25% markup.
Why can't price be zero?
Price is the denominator of the margin percentage, so a zero price would divide by zero.
Can I model a loss?
Yes. A price below cost is allowed and returns a negative profit and negative margin, not an error.
How precise can the output be?
The decimals field accepts 0 to 8 (default 2), rounded half-up.
What happens when the cost is zero?
The margin is 100%, because the whole price is profit. The markup cannot be calculated, since it would mean dividing by zero, so it is left empty instead of showing a misleading number.
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/dev/profit-margin \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"cost":80,"price":100}'const res = await fetch("https://api.kit.forhosting.com/dev/profit-margin", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"cost": 80,
"price": 100
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/dev/profit-margin",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"cost": 80,
"price": 100
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/dev/profit-margin", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"cost":80,"price":100}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"cost":80,"price":100}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/dev/profit-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
{
"cost": 80,
"price": 100
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "dev.profit_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
Profit, margin and markup, and how they differ
When cost is 0 the markup is mathematically undefined (division by zero), so markup_percent is returned as null while margin_percent stays valid at 100.
Fields, validation and edge cases
There is one hard exception: price may not be 0, because it is the denominator of the margin, so a zero price returns the typed error "price no puede ser 0". Every input is checked for type, finiteness and range before any arithmetic, and a violation returns invalid_input naming the field, for example a negative cost or a non-numeric price.
Rounding, determinism and delivery
Rounding uses an explicit half-up rule on the exact IEEE result, applied independently to profit, margin_percent and markup_percent, so a value of 12.345 becomes 12.35 rather than drifting through a locale-dependent formatter. Failed API tasks are never charged; prepaid balance is spent only on successful work at $0.002.
Integration use cases
Audit a catalogue in bulk
Send each SKU's cost and price through the API to flag items whose margin_percent falls below your threshold.
Technical questions
What if cost is zero?
Profit and margin are still valid, but markup is undefined (division by cost), so markup_percent is returned as null.