Now in open beta — close the books in 2 days, not 2 weeks.Read the case study →
Accounting · April 30, 2026 · 9 min read

Cost of goods sold (COGS) calculation explained

Gross margin is the most-watched number in any retail or distribution business. It depends entirely on COGS being correct. The formula is simple, the execution is where SMBs go wrong. A $12 million revenue with COGS off by 8% misstates gross profit by nearly $1 million.

The formula and why it matters.

COGS = Beginning Inventory + Purchases - Ending Inventory. Sales minus COGS equals gross profit. Gross profit divided by sales equals gross margin percentage. This is the single most important operational metric in any business that sells physical goods. Pricing decisions, supplier negotiations, branch performance comparisons, vendor mix, all flow from gross margin.

A COGS calculation that drifts by 5-10% across a year is common in growing SMBs without proper inventory accounting. $50 million in revenue with COGS at 73% (correct) shows gross margin of 27%. Same revenue with COGS at 78% (incorrect) shows gross margin of 22%. The owner makes pricing and inventory decisions based on the wrong number, often discovering the error during annual audit when adjustment is painful.

OpeningBeginning Inventory+ PurchasesGoods received- ClosingEnding Inventory= COGSOn the P&L
Three measurements, one formula. Mess up any of the three and gross margin lies.

Periodic vs perpetual inventory.

Periodic inventory: COGS is calculated only at period end, by physical count and the formula above. During the period, purchases hit a Purchases account; nothing is moved out of inventory until the count. Simple but blind: you do not know real-time inventory levels.

Perpetual inventory: every sale moves inventory out at cost in real time. DR COGS / CR Inventory at the cost of the items sold. Inventory account on the balance sheet matches reality at any moment. Gross margin is visible immediately. Modern accounting systems including Nonari run perpetual inventory by default. Most growing SMBs that have moved off Excel are now perpetual.

Periodic still requires a physical count at period end to confirm the perpetual figure. Discrepancies between perpetual and physical count are inventory variance, investigated and adjusted. A perpetual that never reconciles to physical is not perpetual at all, just a lie that got formatted.

Costing methods, WAC vs FIFO.

When inventory is bought at different prices over time, which cost flows out at sale? Three common methods. Weighted Average Cost (WAC): each new purchase blends with existing stock to a new average. Sale moves out at the current average cost. Simple, smooths out price spikes, used by most growing SMBs. FIFO (First In First Out): the oldest stock is assumed to sell first, at its original cost. Newer stock stays at newer prices. More accurate during inflation, more complex.

LIFO (Last In First Out) is generally not permitted under IFRS for SMEs and is rarely used. Specific identification (each item tracked individually with its own cost) works for high-value low-volume goods like vehicles or jewelry. Most growing SMBs in retail and distribution use WAC because it is simpler and the results are reasonable across most price scenarios.

Nonari uses WAC per branch, recalculated on every purchase. Each branch has its own weighted average because the inventory composition differs by location. A consolidated WAC across branches would smooth too much and hide branch-level performance.

A worked WAC example.

Branch starts February with 100 units at $500 each, total $50,000. Buys 50 units on Feb 8 at $540 each, total $27,000. New balance: 150 units, total cost $77,000, WAC $513.33.

Sells 80 units on Feb 12. COGS at WAC: 80 x 513.33 = $41,067. Inventory remaining: 70 units at 513.33 = $35,933.

Buys 60 units on Feb 20 at $550 each, total $33,000. New balance: 130 units, total cost $68,933, WAC $530.25.

Sells 40 units on Feb 25. COGS: 40 x 530.25 = $21,210. Inventory remaining: 90 units at 530.25 = $47,723.

Total February COGS: $62,277. Total February sales (assuming $800 per unit): 120 x 800 = $96,000. Gross margin: $33,723 = 35.1%. Compare to a static-cost approximation that would have used $500 throughout, computing COGS at $60,000 and gross margin at 37.5%, overstating profit by $2,277 in just one month.

Branch-level inventory and consolidated reporting.

Multi-branch businesses must run inventory per branch. Atlanta branch has its own stock with its own WAC. Manchester branch has its own. When inventory transfers between branches, both sides post: source DR Inter-Branch Transfer / CR Inventory at source WAC; destination DR Inventory / CR Inter-Branch Transfer at the same value. The destination then re-blends into its own WAC if the cost differs from existing destination stock.

Consolidated inventory on the balance sheet is the sum of all branch inventories. Consolidated COGS is the sum of all branch COGS. Consolidated gross margin can be computed at consolidated level or as a weighted average of branch margins. Both should match within rounding. With Nonari, branch and consolidated views are one click apart; manual systems often have inventory at consolidated level only and lose visibility per branch.

Common COGS errors.

Error one: posting purchases directly to COGS instead of inventory. P&L looks fine in the month of purchase but inventory never grows; gross margin in subsequent months is huge because no COGS books at sale. Cumulative error grows until annual physical count catches it.

Error two: not relieving inventory when goods leave for non-sales reasons (samples, write-offs, damage, shrinkage). Inventory stays on books, COGS is understated, gross margin is overstated. Cycle counts flag this.

Error three: including non-product costs in COGS. Sales rep salary is selling expense, not COGS. Office rent is operating expense, not COGS. Mixing them inflates COGS and confuses what is actually the cost of the product. Keep COGS pure: product cost + freight in + customs + direct labor for manufacturers, nothing else.

Error four: foreign currency purchases at wrong rate. $cost of imported inventory is the rate-on-purchase-date times USD invoice. Subsequent rate changes do not change the inventory cost; they create exchange gain/loss on the payable. SMBs sometimes update the inventory cost when they pay, which is wrong.

Purchases → COGSDirect, never inventoryForgot samplesInventory inflatesSales rep in COGSMargin liesFX at payment dateInventory drifts
Four COGS errors. Each creates a different kind of margin lie — and each is invisible until annual audit forces the correction.
  • Purchases must hit Inventory, not COGS directly.
  • Relieve inventory for samples, damage, shrinkage.
  • Keep COGS pure: only direct product costs.
  • FX rate locked at purchase date for imports.
  • Reconcile perpetual to physical count quarterly.

Closing the COGS-inventory loop monthly.

Each month, three checks. First, total purchases per supplier statements equals total purchases per books. Second, perpetual inventory at month end reconciles to a sample physical count. Third, COGS as a percentage of sales is within expected range for the product mix. Outliers are investigated.

These three checks take 30 minutes monthly with disciplined data. Without them, COGS can be off for half a year before anyone notices, and the correction at year end is a several-million-$adjustment that auditors challenge. Better to catch a $80,000 monthly variance than a $1.5 million annual surprise.

Service businesses and COGS.

Service businesses also have COGS, often called Cost of Services or Direct Costs. For a consulting firm, this is consultant time at cost. For a software firm, it is hosting and licensing for delivered services. For a logistics firm, fuel and driver pay. The principle is the same: directly attributable costs of delivering revenue. Sales rep, admin, office rent are not COGS.

Many service SMBs lump all costs together and look only at net margin. This loses signal. Gross margin discipline applies to services too. A consulting engagement at $800,000 revenue with $480,000 of consultant time and $50,000 of travel has gross margin of $270,000 = 33.75%. Track this per engagement and you spot unprofitable client work before it eats the year.

Frequently asked

Common questions.

Should I use WAC or FIFO?

For most retail and distribution SMBs, WAC. Simpler to operate, results close to FIFO during normal price movements, easier to audit. FIFO is better in high-inflation environments where matching newest costs to current sales materially affects gross margin. The two methods often produce similar gross margins over a year; the differences are timing within the year.

How do I handle freight and customs in COGS?

Roll into the inventory cost as freight-in. $100,000 worth of goods imported with $12,000 freight and $8,000 customs duty has a total cost of $120,000 in inventory. When you sell, COGS is the loaded cost, not just the supplier invoice. Without this, gross margin looks higher than it is and pricing decisions go wrong.

What if I have damaged or expired stock?

Write down to net realizable value if you can sell at a discount, or write off entirely if not. Entry: DR Inventory Write-Down (or COGS) / CR Inventory. Document the reason. For perishables, this is monthly; for durable goods, quarterly. Skipping write-downs overstates inventory and hides the loss until year-end audit forces it.

Can the AI bookkeeper compute COGS automatically?

Yes, on Nonari. Every sale triggers a perpetual inventory entry at the current branch WAC. Every purchase updates WAC. Every transfer between branches re-blends destination WAC. The accountant reviews monthly variance reports and approves any unusual adjustments. Manual systems require a careful end-of-period exercise that often gets skipped or rushed.

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.