How to Calculate Profit Margin in Excel (With Formulas)

Short answer: profit margin is profit divided by the selling price. In Excel, with the price in B2 and the cost in C2:

=(B2-C2)/B2

Format the cell as a percentage. A product that sells for 100 and costs 60 has a margin of 40%.

That one formula covers most everyday questions. Below you will find the three margins on a profit and loss statement, the difference between margin and markup (the mistake I see most often in small business pricing), and the formula that tells you what to charge to hit a target margin. Every example is in the free calculator file you can download at the end.

Margin vs Markup: The Difference That Matters

Both compare profit to something, but not the same thing:

Formula Price 100, cost 60
Margin Profit ÷ selling price 40 ÷ 100 = 40%
Markup Profit ÷ cost 40 ÷ 60 = 66.7%

Same product, same profit, two very different percentages. The problem starts when someone says “we work on 40%” and means markup, while the accountant hears margin. A 40% markup is only a 28.6% margin.

I worked with a small catering business that priced every job at cost plus 30%, believing that left 30% for overheads and profit. The real margin was 23%, and their overheads alone were 25% of sales. They had been losing a little on every booking for a year without knowing why.

Profit margin calculator in a spreadsheet showing selling price, cost, gross profit, margin and markup for six products, the price needed for a target margin, and a markup to margin conversion table

Margin and Markup Formulas in Excel

Assume the selling price is in C6 and the cost in D6.

Gross profit per item

=C6-D6

Margin %

=IF(OR(C6="",C6=0),"",(C6-D6)/C6)

The IF stops a #DIV/0! error on empty rows or when the price is zero.

Markup %

=IF(OR(C6="",D6=0),"",(C6-D6)/D6)

Same profit, divided by cost instead of price.

Convert one to the other

Margin from markup:   =markup/(1+markup)
Markup from margin:   =margin/(1-margin)

A 50% markup is a 33.3% margin. A 50% margin needs a 100% markup.

The Price You Need for a Target Margin

This is the formula most people get wrong. To hit a 40% margin on an item that costs 7.80, it is tempting to add 40% to the cost (7.80 × 1.4 = 10.92). That gives a markup of 40%, but the margin is only 28.6%.

The correct formula divides the cost by one minus the target margin:

=ROUND(C20/(1-D20),2)

With a cost of 7.80 in C20 and 40% in D20, the price is 13.00. Check: (13.00 − 7.80) ÷ 13.00 = 40%. The calculator file includes a check column that does this for you.

A target margin of 100% or more is impossible (it would mean a price with no cost at all), so the file leaves those rows blank instead of showing an error.

Gross, Operating and Net Profit Margin

For the business as a whole, take the totals from your profit and loss statement for the same period:

Margin Formula What it tells you
Gross profit margin (Revenue − cost of goods sold) ÷ revenue What is left from each sale after the direct cost of what you sold
Operating profit margin Operating profit ÷ revenue How well overheads such as rent, wages and marketing are controlled
Net profit margin Net profit ÷ revenue What you keep after every expense, interest and tax

In Excel, with revenue in C5, gross profit in C7, operating profit in C9 and net profit in C12:

Gross margin:      =IF(N(C$5)=0,"",C7/C$5)
Operating margin:  =IF(N(C$5)=0,"",C9/C$5)
Net margin:        =IF(N(C$5)=0,"",C12/C$5)

The $ before 5 keeps the revenue row fixed, so you can copy the formulas across to compare years.

Gross, operating and net profit margin calculated from profit and loss totals for this year and last year, with the change in net margin in percentage points

In the sample file, gross margin rose from 55.0% to 58.1% and net margin from 8.9% to 13.5%, an improvement of 4.6 percentage points. Note the wording: the margin went up by 4.6 points, not 4.6%. Mixing the two up is a common slip in reports to lenders.

How to Read Your Margins

There is no single good margin. A software business can run gross margins above 80%, while a grocery store may work on far less, and both can be healthy. What matters most:

  • Your trend. A margin that slips a little every year usually means costs are rising faster than prices.
  • The gap between gross and net. A strong gross margin with a thin net margin points to overheads, not pricing.
  • Product mix. The product table often shows one or two items dragging the average down. The calculator highlights any margin under 20% so they stand out.

For budgeting the year ahead, our monthly business budget template lets you plan revenue and costs and see the margin you are aiming for.

Common Errors and How to Fix Them

#DIV/0! error. The price or revenue cell is empty or zero. Wrap the formula in IF, as in the examples above, or use IFERROR(formula,"").

Margin shows as 0.4 instead of 40%. The formula is right; the cell just needs percentage format. Select it and press Ctrl+Shift+5, or use Format Cells > Percentage.

Margin over 100%. You divided by cost instead of price, so you calculated markup. Margin can never be above 100%; markup can.

Negative margin. The cost is higher than the price. Either the price needs to rise, or the cost figure includes something that does not belong to that product.

Totals look wrong when averaging. Do not average the margin column. Divide total profit by total sales instead: =SUM(E6:E15)/SUM(C6:C15). A simple average gives a 2.00 coffee the same weight as a 450 service package.

Download the Profit Margin Calculator

  • File: sheetforma-profit-margin-calculator.xlsx
  • Contains: margin and markup for up to 10 products, price for a target margin, markup and margin conversion, and gross, operating and net margin for two years
  • Format: .xlsx, no macros; works in Excel 2016 or later, Microsoft 365, Google Sheets and LibreOffice
  • Price: Free, no sign-up

This guide is general information, not financial advice. See our Disclaimer.

Frequently Asked Questions

What is the formula for profit margin in Excel?

=(price-cost)/price, formatted as a percentage. For example, =(B2-C2)/B2 with the selling price in B2 and the cost in C2.

What is the difference between markup and margin?

Margin divides profit by the selling price; markup divides profit by the cost. The same item always has a lower margin than markup.

How do I calculate the selling price from a target margin?

Divide the cost by one minus the margin: =cost/(1-margin). A cost of 60 with a 40% target margin needs a price of 100.

What is a good profit margin for a small business?

It depends heavily on the industry. Compare your margins with your own past years and, where you can, with businesses like yours.

How do I calculate net profit margin?

Divide net profit (after all expenses, interest and tax) by revenue for the same period. Our profit and loss template gives you both figures.

Can I use these formulas in Google Sheets?

Yes. Every formula in this guide works the same way in Google Sheets.

Related Templates and Guides

New templates for invoicing, cash flow, budgets and reports are added every week. Browse them on the Sheetforma homepage, or tell us which template you need next.