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.
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.
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.
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.
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.