How to Calculate Cost of Goods Sold: Formula & Steps

Cost of goods sold (COGS) is calculated with a simple formula: take your beginning inventory, add any purchases or production costs during the period, then subtract your ending inventory. The result tells you exactly how much you spent on the products you actually sold. Whether you run a retail shop, an online store, or a manufacturing operation, this calculation drives your gross profit and affects your tax bill.

The Core COGS Formula

The standard formula works the same regardless of your business type:

COGS = Beginning Inventory + Purchases – Ending Inventory

“Beginning inventory” is whatever stock you had left over from the previous period that didn’t sell. “Purchases” covers everything you bought or produced during the current period to have available for sale. “Ending inventory” is what’s still sitting on your shelves (physical or virtual) when the period closes. You’re essentially calculating how much inventory you started with, adding what came in, and removing what’s still there. What’s left is what went out the door.

Say you own a candle shop. You started January with $4,000 worth of candles in stock. Over the month, you purchased $6,000 more from your supplier. At the end of January, you count $3,500 worth of unsold candles. Your COGS is $4,000 + $6,000 – $3,500 = $6,500. That $6,500 represents the direct cost of every candle you sold that month.

What Counts as a COGS Expense

COGS only includes costs directly tied to producing or acquiring the products you sell. For a retailer, that means the price you paid for merchandise plus shipping to get it to your warehouse. For a manufacturer, it includes raw materials, direct labor (the workers actually assembling or building the product), and costs like factory equipment maintenance or production facility taxes.

A useful test: ask yourself whether the expense would exist even if you made zero sales. If yes, it’s not COGS. Rent for your office, marketing campaigns, accounting staff salaries, insurance, and utilities for non-production spaces are all operating expenses, not COGS. But the coffee beans a cafe buys, the to-go cups, the filters, and the wages of the barista making drinks are all COGS because those costs only arise when producing something to sell.

Getting this classification right matters. COGS is subtracted from revenue to calculate gross profit, so miscategorizing an operating expense as COGS (or vice versa) will distort your profit margins and potentially your tax obligations.

How Inventory Valuation Methods Change the Number

The formula itself is straightforward, but your COGS can vary significantly depending on which inventory valuation method you use. The three most common are FIFO, LIFO, and weighted average cost. Each assigns a different cost to the units you sold, which changes both your reported profit and your tax liability.

FIFO (First In, First Out)

FIFO assumes you sell your oldest inventory first. If you bought 200 chairs at $10 each and later bought 300 more at $20 each, then sold 100 chairs, FIFO says those 100 came from the cheaper $10 batch. Your COGS would be $1,000 (100 × $10). This method produces a lower COGS when prices are rising, which means higher reported profit and a higher tax bill. During periods of falling prices, FIFO has the opposite effect, minimizing taxes.

LIFO (Last In, First Out)

LIFO assumes your newest inventory sells first. Using the same chair example, the 100 sold would come from the $20 batch, making your COGS $2,000 (100 × $20). During inflation, LIFO matches higher-cost inventory against revenue, producing a larger COGS, lower reported profit, and a smaller tax bill. That tax advantage is why some businesses prefer LIFO when costs are trending upward. Note that LIFO is allowed under U.S. tax rules but not permitted under international accounting standards (IFRS).

Weighted Average Cost

This method blends all your inventory costs into a single average. With 200 chairs at $10 ($2,000) and 300 at $20 ($6,000), your total inventory cost is $8,000 for 500 chairs, or $16 per chair. Selling 100 chairs gives you a COGS of $1,600 (100 × $16). Weighted average smooths out price fluctuations and is simpler to maintain than tracking individual batches.

Whichever method you choose, you generally need to use it consistently from year to year. Switching methods changes your financial comparisons and may require disclosure or approval depending on your reporting obligations.

Extra Steps for Manufacturers

If you manufacture products rather than resell them, you need an intermediate calculation called cost of goods manufactured (COGM) before you can plug numbers into the standard COGS formula. Manufacturing involves three types of inventory instead of one: raw materials, work-in-process (partially finished goods), and finished goods.

First, calculate your direct materials used: take your beginning raw materials inventory, add purchases, and subtract ending raw materials inventory. Then add direct labor costs and manufacturing overhead (factory rent, equipment depreciation, production utilities) to get your total manufacturing costs for the period.

Next, apply the COGM formula:

COGM = Beginning Work-in-Process Inventory + Total Manufacturing Costs – Ending Work-in-Process Inventory

The COGM figure represents the total cost of all goods you finished producing during the period. It flows into your finished goods inventory, which is what you use in the standard COGS formula. So for manufacturers, the final step looks like this:

COGS = Beginning Finished Goods Inventory + COGM – Ending Finished Goods Inventory

This layered approach captures costs at every stage of production. A furniture maker, for example, would track lumber and hardware as raw materials, partially assembled tables as work-in-process, and completed tables ready for sale as finished goods. Each category has its own beginning and ending balance that feeds into the calculation.

A Step-by-Step Example

Here’s a complete walkthrough for a retail business calculating COGS for one quarter:

  • Beginning inventory (April 1): $25,000 worth of merchandise on hand
  • Purchases during the quarter: $40,000 in new merchandise, plus $2,000 in freight costs to receive it
  • Ending inventory (June 30): A physical count shows $18,000 worth of merchandise remaining

Total purchases including freight: $42,000. Plug into the formula: $25,000 + $42,000 – $18,000 = $49,000. That’s your COGS for the quarter. If your revenue for the same period was $80,000, your gross profit is $31,000.

Notice that freight costs for getting products to your location are included in purchases. Transportation costs to deliver goods to customers, on the other hand, are typically classified as an operating expense.

Why Accurate Inventory Counts Matter

The COGS formula depends entirely on two inventory figures: beginning and ending. If either number is wrong, your COGS will be wrong. Ending inventory that’s overstated makes COGS look artificially low, inflating your gross profit. Ending inventory that’s understated does the opposite.

Your beginning inventory for any period should match the ending inventory from the previous period exactly. If there’s a discrepancy, it usually signals a counting error, theft, damage, or a bookkeeping mistake. Regular physical inventory counts, even if you use a perpetual tracking system, help catch these gaps before they snowball into reporting problems. Many businesses do a full physical count at least once a year and spot-check high-value or fast-moving items more frequently.