How COGS really works, why periodic and perpetual systems disagree, and the rounding and concurrency bugs that corrupt inventory values.
You buy the same product three times at three different prices. A customer buys one. Which price counts as the cost of that sale?
It sounds like a trivial question, but the answer decides how much profit your business reports, how much tax you may owe, and how your inventory is valued on the balance sheet. The number at the center of it all is called cost of goods sold, or COGS, and this post explains it in plain English, with one worked example you can follow with a pencil.
What cost of goods sold actually is
Cost of goods sold is the direct cost of the inventory you sold during a period. It appears on the income statement, and when you subtract it from your sales revenue, you get gross profit.
Revenue - COGS = Gross profit
What counts as a cost of the goods? Think of everything it took to get the product into sellable condition:
- The purchase price you paid the supplier
- Freight-in, meaning shipping you paid to receive the goods
- Minus any returns you sent back to the supplier
- Minus any purchase discounts you earned
What doesn't count? Costs of selling and running the business, such as shipping to your customers, advertising, and the salaries of your sales staff. Those are operating expenses, and they're reported separately.
The basic COGS formula
The classic formula, used when you count your inventory at the end of a period (called the periodic method), looks like this:
COGS = Beginning inventory + Net purchases - Ending inventory
And net purchases are:
Net purchases = Purchases - Purchase returns - Purchase discounts + Freight-in
Here's an example. A store starts the quarter with $50,000 of inventory, buys $120,000 more, returns $3,000 of it, earns $2,000 in discounts, and pays $4,000 in freight. At the end of the quarter, a count shows $60,000 of inventory left.
Net purchases = 120,000 - 3,000 - 2,000 + 4,000 = $119,000
Goods available for sale = 50,000 + 119,000 = $169,000
COGS = 169,000 - 60,000 = $109,000
The idea to hold onto is "goods available for sale." Every dollar of it ends up in one of two places: it becomes COGS (the stuff you sold) or it stays in ending inventory (the stuff still on the shelf). Nothing appears and nothing vanishes. If your numbers ever break that rule, you've made an error somewhere.
Why the method you choose changes your profit
Here's where it gets interesting. If you bought identical items at different prices, you need a rule for deciding which cost goes with which sale. There are three common rules.
FIFO (first in, first out) assumes the oldest units are sold first. Your COGS uses the oldest, earliest costs.
LIFO (last in, first out) assumes the newest units are sold first. Your COGS uses the most recent costs.
Weighted average blends all the costs into one average cost per unit and uses that for every sale.
Let's see them side by side. A small business has the following in March:
- March 1: Beginning inventory of 100 units at $10 each ($1,000)
- March 10: Purchase of 200 units at $12 each ($2,400)
- March 15: Sells 250 units
- March 20: Purchase of 100 units at $14 each ($1,400)
Total goods available for sale: 400 units costing $4,800. Prices rose across the month, which is the situation where the choice matters most.
If the business updates its costs at the moment of each sale (called the perpetual method), here's what happens to the 250 units sold on March 15:
FIFO: sells the 100 oldest units at $10 and 150 units at $12. COGS = $1,000 + $1,800 = $2,800.
LIFO: sells 200 units at $12 and then 50 at $10. COGS = $2,400 + $500 = $2,900.
Weighted average: the average cost on March 15 is $3,400 divided by 300 units, about $11.33 per unit. COGS = 250 x $11.33 = about $2,833.33.
Now suppose each unit sells for $20, so revenue is $5,000. Gross profit comes out to:
- FIFO: $5,000 - $2,800 = $2,200
- LIFO: $5,000 - $2,900 = $2,100
- Weighted average: $5,000 - $2,833.33 = $2,166.67
Same products, same sales, same shelves, and the reported profit still differs by up to $100 purely because of the cost-flow assumption. In a real business with thousands of items, that gap can be very large. When prices are rising, FIFO generally reports higher profit and higher ending inventory, LIFO reports lower profit, and weighted average lands in the middle. When prices are falling, the pattern reverses.
One more note: LIFO is permitted under US accounting rules (GAAP) but not under international standards (IFRS), and tax rules around LIFO come with conditions. This post explains the concepts, not tax advice, so check with an accountant before choosing a method for a real business.
Periodic vs. perpetual: why the same data can give different answers
In the example above, the sale happened on March 15, before the March 20 purchase arrived. Now compare what happens if the business doesn't cost each sale as it happens, but instead waits until month end, looks at everything it bought, and then works out COGS for all 250 units at once. That's the periodic method.
- FIFO: periodic $2,800, perpetual $2,800
- LIFO: periodic $3,200, perpetual $2,900
- Weighted average: periodic $3,000, perpetual $2,833.33
FIFO gives the same answer both ways, because the oldest costs get used first no matter when you do the math. LIFO and weighted average depend on timing. In the periodic method, LIFO "sells" the newest layer, the $14 units bought on March 20, even though those units hadn't arrived yet when the sale took place. That's allowed because all the costing happens at the end of the period.
This is why a homework problem or a business report that doesn't say "periodic" or "perpetual" is ambiguous. Always confirm which system you're working in before comparing your answer with anyone else's.
If you'd like to test your own scenarios, a free COGS calculator will compute FIFO, LIFO, and weighted average side by side from the same inputs. And if you're curious about the engineering side, such as how rounding leaks and overselling bugs can quietly corrupt inventory values in real software, I wrote a deeper technical breakdown on Medium that walks through the code.
Common mistakes to avoid
1. Mixing up COGS with operating expenses. Shipping to customers and advertising are not part of COGS.
2. Forgetting freight-in, returns, or discounts when calculating net purchases.
3. Rounding too early. If you round an average cost per unit before multiplying, your totals can drift. Work from total costs and round at the end.
4. Ignoring whether the problem is periodic or perpetual.
5. Ending up with a negative COGS. That's impossible. It means ending inventory is larger than goods available for sale, which points to a counting error, a missing purchase, or a typo.
Try it yourself
Work these out on paper first, then check the answers below.
Problem 1. A shop starts with $20,000 of inventory, buys $75,000 of goods, returns $1,500, earns $1,000 in purchase discounts, and pays $2,500 in freight-in. Ending inventory is $24,000. What is COGS?
Problem 2. A business has 100 units at $10 and then buys 200 units at $12. It then sells 150 units. What is the COGS under FIFO, under LIFO, and under weighted average? If each unit sells for $20 (revenue of $3,000), what is the gross profit under each method?
Answers
Problem 1. Net purchases = 75,000 - 1,500 - 1,000 + 2,500 = $75,000. Goods available = 20,000 + 75,000 = $95,000. COGS = 95,000 - 24,000 = $71,000.
Problem 2. FIFO: 100 x $10 + 50 x $12 = $1,600, so gross profit is $1,400. LIFO: 150 x $12 = $1,800, so gross profit is $1,200. Weighted average: $3,400 divided by 300 units is about $11.33 per unit, and 150 x $11.33 = $1,700, so gross profit is $1,300.
The takeaway
COGS is the bridge between what you bought and what you sold. The formula is simple, but the assumptions behind it, which cost goes with which sale and when you do the calculation, can move your reported profit in ways that matter. Learn the three methods, know whether you're using a periodic or perpetual system, and always check that cost of goods sold plus ending inventory adds up to the goods you had available. Use a COGS calculator to double-check your work, and read the technical Medium breakdown if you want to see how the same ideas play out in code.
Have a COGS or inventory question you're stuck on? Leave a comment below and I'll take a look.

Comments
Post a Comment