To calculate margin from cost, you need one more number: your selling price. The formula is (Selling Price − Cost) ÷ Selling Price × 100. If you pay $60 for a product and sell it for $100, your margin is ($100 − $60) ÷ $100 × 100 = 40%. The key detail that trips people up is that margin is always expressed as a percentage of the selling price, not the cost.
The Margin Formula Step by Step
Margin measures how much of each dollar of revenue you actually keep after covering the direct cost of whatever you sold. Here’s the formula:
Margin % = (Selling Price − Cost) ÷ Selling Price × 100
Walk through it with a real example. Say you buy inventory for $25 per unit and sell each unit for $40:
- Subtract cost from price: $40 − $25 = $15 (this is your gross profit per unit)
- Divide by the selling price: $15 ÷ $40 = 0.375
- Multiply by 100: 0.375 × 100 = 37.5% margin
That 37.5% means you keep 37.5 cents of every dollar in revenue after paying for the product itself. The remaining 62.5 cents covers the cost of the item.
When businesses talk about “gross margin,” they’re using the same math on a bigger scale. A company with $200,000 in revenue and $100,000 in cost of goods sold has a gross margin of 50%, calculated as ($200,000 − $100,000) ÷ $200,000.
Why Margin and Markup Are Not the Same
This is the single biggest source of confusion in pricing math. Margin and markup use the same two numbers (cost and selling price) but divide by different bases. Margin divides profit by the selling price. Markup divides profit by the cost.
Take a product that costs $70 to make and sells for $100. The gross profit is $30 either way. But the percentages look different:
- Margin: $30 ÷ $100 = 30%
- Markup: $30 ÷ $70 = 42.9%
A 30% margin and a 42.9% markup describe the exact same $30 of profit. The numbers just answer different questions. Margin tells you what share of revenue is profit. Markup tells you how much you added on top of cost. Mixing them up when setting prices can shrink your profits significantly. If you intend a 30% margin but accidentally apply a 30% markup to a $70 item, you’d price it at $91 instead of $100, losing $9 per sale.
Converting Between Margin and Markup
If you know one, you can find the other without going back to dollar amounts. These two conversion formulas save time when you’re toggling between pricing and accounting perspectives:
- Margin to markup: Markup % = Margin % ÷ (1 − Margin %)
- Markup to margin: Margin % = Markup % ÷ (1 + Markup %)
For example, if your margin is 40% (expressed as 0.40), your markup is 0.40 ÷ (1 − 0.40) = 0.40 ÷ 0.60 = 0.667, or 66.7%. And if someone tells you they use a 50% markup, the corresponding margin is 0.50 ÷ 1.50 = 0.333, or 33.3%.
A quick reference: a 50% margin equals a 100% markup (you doubled the cost). A 25% margin equals a 33.3% markup. The higher the numbers go, the wider the gap between the two percentages, which is why the distinction matters more for higher-margin products.
Finding a Selling Price From a Target Margin
Often you know your cost and the margin you want, and you need to figure out what price to charge. Rearranging the margin formula gives you:
Selling Price = Cost ÷ (1 − Target Margin %)
Express the margin as a decimal. If your cost is $45 and you want a 40% margin:
- Convert the margin: 40% = 0.40
- Subtract from 1: 1 − 0.40 = 0.60
- Divide cost by the result: $45 ÷ 0.60 = $75
Verify it: ($75 − $45) ÷ $75 = 40%. The math checks out.
This formula is especially useful when you’re quoting prices for services or setting wholesale terms. You plug in your all-in cost (materials, labor, shipping) and the margin your business needs, and the required price falls right out.
What “Cost” Should Include
The margin formula is only as useful as the cost figure you feed into it. In accounting terms, cost of goods sold (COGS) includes the direct expenses tied to producing or acquiring what you sell: raw materials, manufacturing labor, shipping to your warehouse, and packaging. It does not include rent, marketing, salaries for your back-office team, or other overhead.
If you run a product business, your per-unit cost should capture what you paid the supplier (or spent on materials and production labor), plus inbound freight and any duties. If you’re a freelancer or service provider, your “cost” is typically the direct labor hours multiplied by your loaded hourly cost, plus any materials or subcontractor fees billed to that project.
Underestimating cost is the fastest way to end up with a margin that looks healthy on paper but doesn’t cover your actual expenses. Before plugging a number into the formula, make sure you’ve accounted for every direct cost that disappears if you stop making the product or delivering the service.
Typical Margins Across Industries
Knowing your margin in isolation isn’t that useful. You need context for whether it’s healthy. Margins vary enormously by industry because of differences in production costs, competition, and pricing power.
Software companies tend to operate at the highest margins because the cost of delivering one more copy of a product is nearly zero. System and application software companies average around 41% operating margin. Grocery and food retailers sit at the opposite extreme, with operating margins near 2.5%, because their products are commoditized and price-sensitive. General retail lands around 8%, food processing around 11%, and machinery manufacturing near 17%.
These are operating margins, which subtract overhead costs beyond COGS. Your gross margin (the one you calculate with the formula above) will typically be higher than these figures because it only subtracts direct costs. If your gross margin is below the operating margin benchmark for your industry, that’s a clear signal your pricing or cost structure needs attention.
Margin on a Bundle of Products
When you sell multiple products at different costs and prices, your overall margin is a weighted calculation, not a simple average of individual margins. A high-margin item that accounts for 5% of your sales barely moves the needle compared to a low-margin item that makes up 60%.
To find your blended margin, add up total revenue across all products, subtract total cost across all products, then divide by total revenue. If you sell Product A (revenue $10,000, cost $6,000) and Product B (revenue $40,000, cost $30,000), your blended margin is ($50,000 − $36,000) ÷ $50,000 = 28%. Product A has a 40% margin and Product B has a 25% margin, but because B dominates your sales mix, your overall margin skews toward 25%.
This is why shifting your sales mix toward higher-margin products can improve profitability even if total revenue stays flat.

