The cost of goods sold (COGS) formula is COGS = opening inventory + purchases − closing inventory. For example, a shop that starts the month with $12,000 of stock, buys $30,000 more and counts $8,000 still unsold has COGS of $12,000 + $30,000 − $8,000 = $34,000.
Cost of Goods Sold (COGS) is the direct cost of whatever you actually sold during a period — not everything you spent money on, and not everything sitting on your shelves. Knowing how to calculate cost of goods sold correctly is the difference between a gross profit figure you can trust and one that's quietly wrong every single month.
Key takeaways
- COGS = Opening Inventory + Purchases − Closing Inventory.
- COGS only reflects stock that left the business as a sale during the period — unsold stock stays on the balance sheet as inventory, not as a cost.
- Freight-in (the cost of getting purchased stock to you) is added to COGS. Rent, admin salaries, and marketing are not COGS at all — they're operating expenses.
- Service businesses without physical inventory often use "cost of service" instead, covering direct labor and materials tied to delivering the service.
- Get the inventory count wrong at either end of the period, and COGS — and therefore gross profit — is wrong too, even if every purchase was recorded correctly.
The COGS formula
COGS = Opening Inventory + Purchases − Closing Inventory
Cost of Goods Sold
Each term is a value taken at a point in time, not a running total:
- Opening inventory — the value of stock on hand at the start of the period (which is last period's closing inventory).
- Purchases — everything bought into stock during the period, plus freight-in (the cost of shipping that stock to you).
- Closing inventory — the value of stock still on hand, unsold, at the end of the period.
The logic is straightforward once you see it: you start with what you had, add what you bought, and whatever isn't left over at the end must be what you sold. That's COGS.
A worked example
A small trading business starts the month with $12,000 of stock on the shelves. Over the month it buys $30,000 more inventory. At month-end, a physical count shows $8,000 of stock still unsold.
| Component | Amount |
|---|---|
| Opening inventory | $12,000 |
| + Purchases | $30,000 |
| − Closing inventory | ($8,000) |
| Cost of goods sold | $34,000 |
Cost of Goods Sold (COGS) = Opening Inventory + Purchases − Closing Inventory. For example, a shop starts the month with $12,000 of stock, buys $30,000 more, and ends with $8,000 left unsold. COGS = $12,000 + $30,000 − $8,000 = $34,000 — the cost of what was actually sold that month, no more and no less.
If revenue for the same month was $54,000, gross profit is $54,000 − $34,000 = $20,000, a margin of 37%. Every part of that number depends on the closing inventory count being accurate — count it wrong by $2,000 in either direction, and COGS (and gross profit) is off by exactly $2,000 too.
COGS is only as reliable as your opening and closing inventory figures. If nobody physically checks what's on the shelf and the book figure is used instead, any shrinkage, breakage, or uncounted stock silently distorts COGS — and with it, every profit number built on top of it. A periodic stock count is what keeps this formula honest.
The COGS formula for manufacturers
A business that makes what it sells does not simply buy finished goods, so the inputs change. First work out the cost of goods manufactured (COGM), then use it in place of purchases:
COGM = Direct Materials + Direct Labor + Manufacturing Overhead + Opening Work-in-Progress − Closing Work-in-Progress
Cost of Goods Manufactured
COGS = Opening Finished Goods + COGM − Closing Finished Goods
Cost of Goods Sold for a manufacturer
For example, a workshop uses $18,000 of materials, pays $9,000 of production labor and carries $6,000 of factory overhead. Work-in-progress was $3,000 at the start of the month and $4,000 at the end, so COGM = $18,000 + $9,000 + $6,000 + $3,000 − $4,000 = $32,000. With $5,000 of finished goods at the start and $7,000 at the end, COGS = $5,000 + $32,000 − $7,000 = $30,000.
Which unit cost you place on closing stock also changes the answer; see FIFO vs average costing and COGS and inventory costing. Other business types are covered in what counts as COGS by industry.
What belongs in COGS — and what doesn't
The rule is simple to state and easy to get wrong in practice: COGS is the direct cost of producing or acquiring what was sold. Anything that would exist even if you sold nothing this month is an operating expense, not COGS. It's the same classification question covered in cost vs expense vs asset: inventory sits in the asset column until it sells, at which point its cost becomes COGS.
| Included in COGS | Not COGS (operating expense instead) |
|---|---|
| Purchase price of goods for resale | Store or office rent |
| Freight-in (shipping stock to you) | Admin and sales staff wages |
| Direct production labor and materials (manufacturers) | Marketing and advertising |
| Packaging that ships with the product | Loan interest |
| Direct production overhead tied to units made | Software subscriptions, insurance, utilities |
Mixing these two lists is one of the most common ways a business's gross profit ends up looking healthier than it really is: park an operating cost inside COGS by mistake, and gross margin understates itself; leave a genuine product cost out of COGS, and gross margin looks better than it should.
Not every business calls it COGS
A retailer or wholesaler with physical stock uses the formula above directly. A service business that holds no inventory at all often reports a "cost of service" line instead — covering direct labor, subcontractor fees, and materials tied specifically to delivering the service — but it sits in exactly the same place on the income statement and does exactly the same job. What counts as a direct cost also looks different again for manufacturers, who add production labor and factory overhead into the mix. How COGS differs by business type walks through five of the most common cases side by side.
Recording COGS: when it actually happens
A purchase of inventory is not an expense. It's an asset — value the business is holding, not value it has used up. That value only becomes a cost, and only reduces profit, at the moment the stock is sold. Buying $30,000 of stock this month has no effect on gross profit at all if none of it sells yet:
| Account | Debit | Credit |
|---|---|---|
| Inventory | 30,000 | |
| Accounts payable | 30,000 |
Recording a purchase this way — and the sale itself — follows the same pattern used for everyday purchase and inventory transactions throughout this course. Then, at the moment a sale actually happens, two things are recorded together — the revenue earned, and the cost of the specific stock that just left the shelf:
| Account | Debit | Credit |
|---|---|---|
| Accounts receivable | 2,500 | |
| Sales revenue | 2,500 | |
| Cost of goods sold | 1,700 | |
| Inventory | 1,700 |
Notice the inventory account only moves when a sale happens — not when stock is purchased, and not on some month-end schedule. Run that same paired entry for every sale in the month, and total cost of goods sold builds up automatically, transaction by transaction, matching exactly what the opening-plus-purchases-minus-closing formula would calculate for the period as a whole.
Calculating your own COGS this month
- Pull last month's closing inventory value — that's this month's opening inventory.
- Total every inventory purchase made this month, including freight-in.
- Do a physical stock count at month-end and value it at cost — this is closing inventory.
- Apply the formula: opening + purchases − closing = COGS.
- Subtract COGS from revenue to get gross profit, and check the margin against what you'd expect for your kind of business.
Keep this formula alongside the rest of the core profitability formulas so you're not hunting for it separately each month. This lesson is the step-by-step calculation. To see how FIFO or average costing changes the inventory values you plug into it, read COGS and inventory costing methods.
Show a second worked answer
Opening inventory: $5,000. Purchases this month: $12,000. Closing inventory: $4,000.
COGS = $5,000 + $12,000 − $4,000 = $13,000.
If nothing had been on the shelf at the start of the very first trading period, opening inventory would simply be $0, and COGS would equal purchases minus closing inventory for that first period only — from the second period on, each period's closing inventory automatically becomes the next period's opening figure.
Doing this calculation by hand every month is exactly the kind of work accounting software exists to remove. Reyuko's Product catalog tracks a costing method per item — Average, FIFO, or LIFO — and its inventory ledger records every purchase batch and every sale against it automatically.
That means cost of goods sold isn't a month-end reconstruction: each sale posts its own COGS entry, calculated from the actual batches in stock, at the moment the sale happens — the same mechanism shown in the journal entries above, just automated. The Income Statement report then reflects an up-to-date gross profit at any point in the month, not only after a manual count and calculation.
Reyuko