COGS calculator
Cost of goods sold from your inventory numbers, or backwards from revenue and gross profit. Add what you sold and you get gross profit and gross margin on the same screen.
Verified August 22, 2026
Cost of goods sold
$40,000
What the goods you sold cost you
You sold $40,000 of goods and kept $60,000 of gross profit, a 60% gross margin.
- Available to sell
- $64,000
- Cost of goods sold
- $40,000
- Revenue
- $100,000
- Gross profit
- $60,000
- Gross margin
- 60%
Gross profit only. Ad spend, salaries, software and shipping to the customer sit below this line and come out of what is left.
How cost of goods sold is calculated
One identity, three numbers. What you started with, plus what you added, minus what is left. Whatever is missing was sold, and what it cost you is your cost of goods sold. The IRS uses the same structure on Form 1125-A, which runs beginning inventory, purchases, cost of labor, additional section 263A costs and other costs down lines 1 through 5, adds them, and subtracts ending inventory to reach COGS on line 8.
COGS = beginning inventory + purchases − ending inventory
18,000 + 46,000 − 24,000 = 40,000
100,000 − 40,000 = 60,000 gross profit
$18,000
Beginning inventory
$46,000
Purchases
$40,000
Cost of goods sold
$24,000
Ending inventory
The top bar is everything you could have sold. The bottom bar splits it into what left and what stayed.
Purchases is the line people get wrong. It is not only the invoice from your manufacturer. Freight-in and labor are their own lines on the IRS form: Publication 334 puts cost of labor on line 37 and lists freight-in, express-in and cartage-in under other costs on line 39, all of them part of cost of goods sold. This calculator folds them into purchases so you enter one number. Schedule C sole proprietors use the same shape on lines 35 to 42, with purchases reduced by anything you took out for personal use.
What stays out is anything that did not go into making the product. Ad spend, your salary, apps, agency fees and the shipping label to the customer are all operating costs. They come out of gross profit, not out of it before you get there. Put them in COGS and your gross margin reads low while your operating costs read light, which makes every downstream number wrong in the same direction.
Ending inventory has to be valued, and the IRS names the methods: cost, lower of cost or market, or another method it has approved. Publication 538 names specific identification, FIFO and LIFO for deciding which units the cost belongs to, and adopting LIFO requires Form 970. Pick one and stay on it.
Small business taxpayers get an easier route. The Form 1125-A instructions give them three options: treat inventory as non-incidental materials and supplies, follow the inventory treatment in an applicable financial statement, or follow the method in their own books and records if they have no applicable financial statement. The gross receipts threshold that defines a small business taxpayer under section 448(c) is $32 million for tax years beginning in 2026.
Where the numbers live in Shopify
Shopify holds the cost side in one field: cost per item, which it defines as how much the product or variant costs you. Fill it in on every variant and the profit reports work; leave it blank and they quietly do not. Shopify reports profit on a product only when a cost was recorded at the time it sold, so a variant you costed last week tells you nothing about what it earned last quarter.
Gross profit in those reports is net sales minus cost. Net sales is gross sales minus discounts and sales reversals, and gross sales is product price times quantity before taxes, shipping and discounts. That is a narrower cost figure than the one the identity above produces, because it is the cost of what sold rather than the movement of your whole inventory position, and it only sees the variants you costed.
Use both. The inventory identity is what a full period actually cost you. The Shopify report tells you which product is carrying the store. When the two disagree, the usual reason is a variant with no cost per item, or freight-in that never made it into a cost field.
The cost side is only half of a margin. The other half moves with what you charge and what each order carries, which is what the AOV calculator works out per order, and with what you paid to bring the customer in, which the CAC calculator puts against it.
Working backwards from gross profit
Cost of goods sold equals revenue minus gross profit. Sometimes the inventory count is the number you do not have. Your profit and loss shows revenue and gross profit, and you want the cost. Gross profit is defined as revenue minus COGS, so the identity solves the other way with no new information: $100,000 of revenue and $60,000 of gross profit is $40,000 of cost of goods sold, and a 60% gross margin. Switch the mode above to "From gross profit" and the calculator does it that way round.
COGS = revenue − gross profit
100,000 − 60,000 = 40,000
gross margin = gross profit ÷ revenue
60,000 ÷ 100,000 = 0.60
In a spreadsheet it is one formula. Put beginning inventory in B2, purchases in B3 and ending inventory in B4, then put this in B5:
=B2+B3-B4
gross profit, with revenue in B1: =B1-B5
gross margin: =(B1-B5)/B1
Format the margin cell as a percentage rather than multiplying by 100 in the formula. Keep one row per period and the same three columns, and the year adds up by dragging the formula down.
Gross margin from cost of goods sold
Gross margin is gross profit divided by revenue. Cost of goods sold on its own is trivia; against revenue it becomes the constraint every other decision runs into, because that margin is the ceiling on what you can spend to sell the thing. At 60% you have 60 cents per dollar to cover ads, people, software and the shipping label. At 30% you have half of that, and the same ad account has to work twice as hard.
Cost of goods sold on the left, gross margin on the right, against $100,000 of revenue every time.
Read the ladder as a spending ceiling rather than a grade. Nothing here says what your margin should be, because a $12 consumable and a $400 piece of furniture are not in the same argument. What it does say is that the same $10,000 of ad spend needs a different result at each row, which is the point where this number becomes a marketing number. The ROAS calculator takes a contribution margin and returns the return on ad spend you have to clear to break even.
Two costs get left out of COGS and then forgotten entirely. Shipping to the customer is one. The payment fee is the other, and it is bigger on small orders than most people assume, which the Stripe fee calculator shows on a per-order basis. Both belong in contribution margin even though neither belongs in cost of goods sold.
There is a third pressure on the same line, and it is not a cost. When somebody lists your product using your own photographs at a third of your price, the pressure lands on what you can charge, which is the revenue half of every calculation on this page. Knockoff watches your catalog's photos across Amazon, Temu, eBay, Etsy, AliExpress, Walmart and the open web, and every confirmed match arrives as a finished case you approve. Run a scan to see which of your products are being copied right now.
Common questions about COGS
How do you calculate cost of goods sold?
+
Beginning inventory plus what you bought during the period, minus what is still on the shelf at the end of it. $18,000 of opening stock plus $46,000 of purchases, minus $24,000 of closing stock, is $40,000 of cost of goods sold. Freight-in and labor are their own lines on the IRS form, Pub 334 lines 37 and 39, and this calculator folds them into purchases so you enter one number.
How to get COGS from gross profit?
+
Subtract gross profit from revenue. $100,000 of revenue with $60,000 of gross profit means $40,000 of cost of goods sold. Gross profit is defined as revenue minus COGS, so the same identity solves either way, and the reverse mode above does it for you.
How do I calculate COGS in Excel?
+
Put beginning inventory in B2, purchases in B3 and ending inventory in B4, then enter =B2+B3-B4. For gross margin from a revenue figure in B1, use =(B1-B5)/B1 and format the cell as a percentage.
What is included in cost of goods sold?
+
The cost of the goods themselves, the freight-in to get them to you, and the direct labor that produced them. Publication 334 puts cost of labor on line 37 and freight-in under other costs on line 39. Marketing, ad spend and salaries for people who did not make the product sit below the gross profit line, not in COGS.
Sources
- IRS Form 1125-A, for the line structure on lines 1 through 8, the cost of labor and section 263A lines, the closing inventory valuation methods, and the three small business taxpayer options
- IRS Publication 334, for the Schedule C cost of goods sold lines 35 to 42, including purchases less the cost of items withdrawn for personal use, cost of labor on line 37, and freight-in, express-in and cartage-in under other costs on line 39
- IRS Publication 538, for specific identification, FIFO and LIFO, and Form 970 for adopting LIFO
- Revenue Procedure 2025-32, for the $32 million section 448(c) gross receipts threshold for tax years beginning in 2026
- Shopify Help Center, profit reports, for cost per item, gross profit as net sales minus cost, and profit being reported only for products that had a cost recorded when they sold
- Shopify Help Center, sales reports, for gross sales as product price times quantity before taxes, shipping and discounts, and net sales as gross sales minus discounts and sales reversals
Every figure on this page was read from the source beside it and verified August 22, 2026. The arithmetic is arithmetic and belongs to nobody. Nothing here is tax advice, and your accountant gets the final say on how your inventory is valued.