Now in open beta — close the books in 2 days, not 2 weeks.Read the case study →
Inventory · April 19, 2026 · 10 min read

How to calculate COGS step by step.

Cost of goods sold is the single biggest expense on most product businesses, and it is the one most owners cannot calculate cleanly. Get it right and your gross margin tells the truth. Get it wrong and every pricing decision for the year is built on sand. Here is the actual math, with worked examples.

The COGS formula.

Cost of goods sold = opening inventory + purchases - closing inventory. That is the master formula. If you started January with USD 80,000 of inventory, bought USD 220,000 during the month, and ended January with USD 95,000 of inventory, COGS for January is 80 + 220 - 95 = USD 205,000. Subtract COGS from revenue to get gross profit. Divide gross profit by revenue to get gross margin. Three numbers feed the most important ratio in your P&L.

The formula assumes a few things that matter. Inventory is valued at cost (not retail). Purchases include freight-in, customs duty, and any cost to bring goods to your warehouse. Closing inventory is established by a physical count, not a guess. Get any of these three wrong and COGS lies. The lie shows up as an unstable gross margin month over month, which is the symptom owners describe as "I do not understand why my margin moved."

Worked example: a retail store in Berlin.

A Berlin electronics retailer, March 2026. Opening inventory EUR 145,000. Purchases during March: EUR 280,000 in product cost plus EUR 18,000 in freight from suppliers plus EUR 12,000 in customs duty on a shipment from Korea. Total purchases EUR 310,000. End of March physical count: EUR 162,000 of inventory at cost. COGS = 145 + 310 - 162 = EUR 293,000.

Revenue for March was EUR 420,000. Gross profit = 420 - 293 = EUR 127,000. Gross margin = 127 / 420 = 30.2 percent. Operating expenses (rent, salaries, marketing) EUR 95,000. Operating profit EUR 32,000. The retailer can compare 30.2 percent gross margin against industry norms (consumer electronics retail typically 25-35 percent) and see that the month was healthy. If gross margin slipped to 22 percent next month, something specific would have happened: a clearance event, a tariff change, a shrinkage spike.

OpeningEUR 145k+ PurchasesEUR 310k (incl. freight + duty)- ClosingEUR 162k physical count= COGSEUR 293k → P&L
Gross margin: 30.2%. Within industry norm. A 22% next month is a specific event — find it.

Worked example: a manufacturer in Detroit.

A Detroit metal fabrication shop, March 2026. Opening raw materials USD 60,000, opening work-in-process USD 18,000, opening finished goods USD 42,000. Total opening inventory USD 120,000. Material purchases USD 195,000. Direct labor USD 84,000. Manufacturing overhead allocated USD 36,000 (factory rent, depreciation, supervisor salary, utilities). Total manufacturing costs added USD 315,000. End of March physical count: raw 72,000, WIP 24,000, finished 38,000 = USD 134,000.

COGS = 120 + 315 - 134 = USD 301,000. Notice manufacturing is more complex because COGS includes direct labor and allocated overhead, not just material. Skip the overhead and you understate COGS by USD 36,000, overstate gross margin, and make terrible pricing decisions on the next quote to a customer. Most small manufacturers we audit have not allocated overhead at all and are running on a fictitious gross margin of 50 percent that is actually 32 percent.

Opening$120k (raw + WIP + FG)+ Materials+$195k purchases+ Labor+$84k direct+ Overhead+$36k allocated- Closing-$134k physical= COGS$301k → P&L
Skip the $36k overhead allocation and gross margin reads 50% instead of the real 32%. Pricing decisions follow the lie.

What goes into purchases (and what does not).

Purchases include the invoiced cost of inventory plus all costs to bring it to your premises ready to sell. So: vendor invoice + inbound freight + customs duty + clearing agent fees + insurance in transit. These costs are "capitalized into inventory" until the goods sell, at which point they flow through COGS. Putting freight in a separate operating expense category understates COGS and overstates gross margin. The IRS, HMRC, and FBR all require freight-in to capitalize.

What does not go into purchases: outbound shipping to customers (that is a selling expense), warehouse rent (operating expense unless the warehouse exists only to hold inventory in transit), and general overhead. The line is: did this cost get the goods ready to sell? Yes goes into inventory. Did this cost happen after the goods were ready? No, operating expense. Clean this up once and every future COGS calculation is faster.

  • Vendor invoice cost (the headline price).
  • Inbound freight (truck, ocean, air to your warehouse).
  • Customs duty and import processing fees.
  • Insurance covering goods in transit.
  • Clearing agent fees and port charges.

The five common COGS mistakes.

Mistake one: valuing inventory at retail instead of cost. A shop with 4,000 units at USD 25 cost and USD 60 retail records inventory as USD 240,000 (correct) not USD 240,000 (correct) -- the trap is using retail of 60 * 4,000 = USD 240,000 when the actual cost basis is 100,000. Mistake two: not capitalizing freight. Mistake three: forgetting consignment goods (they are not yours; do not include them).

Mistake four: skipping the physical count and using a "system says" number that has drifted from reality. Most perpetual inventory systems are off by 3-8 percent in retail and 5-15 percent in manufacturing without an annual physical count. Mistake five: using cash basis (recording COGS only when you pay the supplier) instead of accrual. Cash basis confuses COGS with cash flow. Use accrual: book COGS when the sale happens, regardless of when you paid for the inventory.

Wrong-COGS findings (any cause) · 100 %Inventory at retail not cost · 45 %Freight not capitalised · 25 %No physical count (drift) · 18 %Cash basis instead of accrual · 8 %Consignment goods included · 4 %
Two issues — retail-valuation + freight — cause 70% of wrong COGS in audits. Get those right and gross margin stops drifting.

COGS on the P&L vs inventory on the balance sheet.

COGS lives on the income statement (P&L). Inventory lives on the balance sheet. The flow is: when you buy inventory, it sits on the balance sheet as an asset. When you sell it, it moves from the balance sheet to the P&L as COGS. The journal entry on every sale: DR COGS / CR Inventory. The sale itself: DR Cash or AR / CR Sales Revenue. Two paired entries, four accounts moved, the books stay balanced.

For a London bookshop selling a book that cost GBP 7.50 for GBP 14.99 plus VAT (20 percent total GBP 17.99): DR Cash 17.99 / CR Sales 14.99 / CR VAT Output 3.00, and DR COGS 7.50 / CR Inventory 7.50. Gross profit on this sale: 14.99 - 7.50 = GBP 7.49 or 50 percent margin. Multiply by every sale of the day, every day of the month, and you have the P&L. The balance sheet inventory drops as the P&L COGS rises.

One book sale — £14.99 + 20% VAT, cost £7.50DEBITCREDITCash17.99Sales14.99COGS7.50VAT Output3.00Inventory7.50TOTAL DR25.49TOTAL CR25.49
Two paired entries, four accounts. Balance sheet inventory drops as P&L COGS rises — the link between the two statements.

How software computes COGS automatically.

Manual COGS calculation requires a quarterly or annual physical count and a spreadsheet that nobody enjoys maintaining. Perpetual inventory software computes COGS in real time: every sale knows the cost basis of the item being sold, posts the COGS journal entry instantly, and updates the inventory ledger. The owner sees the gross margin of each sale at the moment of sale. Pricing mistakes become visible in days, not quarters.

Nonari uses weighted average cost per SKU per branch. When you sell a unit from the Karachi branch, the COGS journal entry posts at the current weighted average cost of that SKU at that branch. Branch transfers move at weighted average too, so cost basis stays clean even with stock moving between locations. The physical count at year-end is now a confirmation, not a discovery. The COGS number you see on Day 1 of the next month is the actual COGS, audit-ready.

Frequently asked

Common questions.

What is the difference between COGS and operating expenses?

COGS is the direct cost of goods or services sold (materials, direct labor, freight-in). Operating expenses are everything else needed to run the business (rent, marketing, admin salaries, software). COGS varies with revenue; operating expenses are mostly fixed. Gross margin uses COGS; net margin uses both.

Does COGS include shipping to customers?

No. Outbound shipping to customers is a selling expense, not COGS. Inbound shipping to your warehouse is part of COGS. The line is "was this cost needed to get the goods ready to sell?" Inbound yes, outbound no.

Can I use FIFO or LIFO instead of weighted average?

Yes, depending on jurisdiction and accounting policy. FIFO (first in, first out) and weighted average are allowed under both US GAAP and IFRS. LIFO is allowed under US GAAP but not IFRS. Pick a method and apply it consistently; changes require disclosure and sometimes regulatory approval.

How often should I calculate COGS?

Monthly at minimum, for monthly P&L. With perpetual inventory software, COGS calculates in real time on every sale, so the monthly number is just a sum. Without software, you compute at month-end from opening + purchases - closing using a count or a system snapshot.

Why is my gross margin different from my industry average?

Common reasons: you are not capitalizing freight (margin appears higher than reality), you are not posting overhead to manufacturing COGS, your physical count has drifted from your system, or your product mix differs from the industry average. Run the math both ways and explain the gap; it is usually one of those.

Try nonari

Put your books on autopilot.

Free to start. No credit card. Bring your books, kick the tires, export everything if you decide to leave.