Cost of goods sold is what it cost you to acquire or make the products you actually sold during a period. It sits at the top of the profit and loss statement, directly under sales, and it determines your gross profit. Get it wrong and every margin figure below it is wrong too.
This guide covers the standard formula for businesses that count inventory at the start and end of a period (the periodic method), shows a worked example with verified arithmetic, and gives Excel formulas.
Updated November 2026
The COGS formula
COGS = Beginning inventory + Net purchases – Ending inventory
Beginning inventory is what you had on hand on the first day of the period. Net purchases are what you bought during the period, adjusted for returns, discounts and freight-in. Ending inventory is what is still unsold on the last day. Beginning inventory plus net purchases is called goods available for sale. Whatever is left unsold at the end is not a cost of this period, so you subtract it.
The IRS says that businesses that need to keep inventory generally have to value it at the beginning and end of each tax year to figure cost of goods sold (IRS Publication 538). If you deduct COGS on certain returns, you report it on IRS Form 1125-A.
What goes into net purchases
- Add: merchandise purchases at invoice price, plus freight-in and other costs to get goods to your location.
- Subtract: purchase returns and allowances, and purchase discounts you actually took.
- Leave out: shipping you pay to send goods to customers, advertising, and general overhead. Those are operating expenses, not COGS, in most small-business books. If you manufacture, direct labor and factory costs are also part of cost of goods.
Worked example
A small shop reports these illustrative figures for a year:
| Item | Amount |
|---|---|
| Beginning inventory | $25,000 |
| Purchases | $110,000 |
| Freight-in | + $4,200 |
| Purchase returns | – $2,000 |
| Purchase discounts taken | – $1,500 |
| Net purchases | $110,000 + $4,200 – $2,000 – $1,500 = $110,700 |
| Goods available for sale | $25,000 + $110,700 = $135,700 |
| Ending inventory (physical count) | $31,200 |
| Cost of goods sold | $135,700 – $31,200 = $104,500 |
We verified each step by recomputing it separately. If sales for the year were $160,000, then gross profit is $160,000 – $104,500 = $55,500, and gross margin is $55,500 / $160,000 = 34.7 percent. COGS is 65.3 percent of sales. To run your own numbers, use our gross profit calculator, or read how to calculate gross profit for the next step.
Excel formulas
Put the inputs in B2 through B6: beginning inventory (B2), purchases (B3), freight-in (B4), returns (B5), discounts (B6), and ending inventory in B7.
- Net purchases:
=B3+B4-B5-B6 - Goods available:
=B2+B3+B4-B5-B6 - COGS:
=B2+B3+B4-B5-B6-B7 - Gross profit with sales in B9:
=B9-B8where B8 holds the COGS cell - Gross margin:
=(B9-B8)/B9, formatted as a percentage
Periodic vs perpetual
The method above is periodic: you find ending inventory by counting stock, then work back to COGS. In a perpetual system, software records the cost of each item as it sells, so COGS accumulates all year, and the count at year end is a check. Many small shops on spreadsheets use the periodic method; a tracking sheet such as our inventory template helps you keep counts clean.
Inventory valuation changes the answer
If prices changed during the year, the cost assigned to the units you sold depends on your method. FIFO assumes the oldest units sold first, LIFO the newest, and weighted average blends them. Pick one, apply it consistently, and talk to your tax preparer before switching. The formula stays the same; only the dollar values of beginning and ending inventory change.
Common mistakes
- Forgetting freight-in, which makes COGS and margins look better than they are.
- Using an estimated ending inventory that never gets verified.
- Counting selling costs, rent or ads inside COGS.
- Applying returns from customers here; those reduce sales, not purchases.
This article is general education, not tax or accounting advice.

Frequently asked questions
What is the formula for cost of goods sold?
Beginning inventory plus net purchases minus ending inventory. Net purchases are purchases plus freight-in minus returns and discounts.
Is shipping to customers part of COGS?
Usually not. Freight you pay to bring goods in is part of the cost of inventory. Shipping you pay to deliver sold goods to customers is generally an operating expense.
How do I get gross profit from COGS?
Subtract COGS from net sales. Divide the result by net sales to get gross margin as a percentage.
Do service businesses have COGS?
Service businesses often have a similar line for direct costs, such as materials and subcontractors used on jobs. Whether it is called COGS depends on how you report; ask your accountant.


