Cost of goods sold formula: How to calculate COGS, with examples and a template

Guide9 mins read | Posted on July 24, 2026 | By Henry Jose

Introduction

Cost of goods sold (COGS) is worked out from three figures you already have: the stock you held at the start of a period, what you added during it, and what was left at the end. The difference is the cost of what you sold, and it is usually the largest expense on your income statement. An error in it flows straight into gross margin and taxable profit.

This guide gives you the formula, a worked example, a units-based method, how the costing method changes the answer, the version manufacturers use, what an inventory error does to the result, the journal entries, and a worksheet to reuse.

COGS formula 

COGS totals the cost of the goods you sold, not the goods you bought:

COGS = Beginning Inventory + Purchases − Ending Inventory

Beginning inventory is the stock you held at the start of the period. Purchases are what you added during it: stock bought for resale or, for a manufacturer, the materials, labor, and production overhead that went into what you made. Ending inventory is what remains at the end, from a physical count or your inventory records.

Beginning inventory plus purchases gives the cost of goods available for sale. Subtracting the goods still on the shelf leaves the cost of the goods that left it.

Purchases should include freight-in and import duties and should be net of trade discounts, returns to suppliers, and rebates. Manufacturers use a fuller version of the formula, covered further down.

Quick COGS calculator 

Enter your beginning inventory, purchases, and ending inventory, and the calculator returns your COGS. Use it to check a period quickly or to see how a different ending count moves the figure.

Step-by-step with a worked example

Take a period with 50,000 of beginning inventory, 20,000 of purchases, and 15,000 of stock left at the end (illustrative figures).

  1. Start with beginning inventory: 50,000.
  2. Add purchases: 50,000 + 20,000 = 70,000. This is your cost of goods available for sale.
  3. Subtract ending inventory: 70,000 − 15,000 = 55,000.
  4. Optional, gross profit: if revenue for the period was 90,000, gross profit is 90,000 − 55,000 = 35,000, a gross margin of about 38.9%.

COGS for the period is 55,000. Swap in your own figures to repeat this. The number that needs most care is ending inventory, because it comes from a count or your inventory system, and any error there passes straight into COGS and from there into profit.

The units method

When you track quantities closely but value stock only at period end, start from units:

Units sold = Units bought or produced − Increase in units held (or + a decrease)

COGS = Units sold × Cost per unit

A business bought 200 units in the period, and its stock rose by 50 units, from 100 to 150. It sold 150 units. 

At an illustrative cost of 40 per unit, COGS is 150 × 40 = 6,000.

The standard formula gives the same answer: 

beginning inventory 4,000 (100 × 40) + purchases 8,000 (200 × 40) − ending inventory 6,000 (150 × 40) = 6,000.

The units method is clean when the cost per unit stays stable. When purchase prices change during the period, the cost per unit depends on your costing method, which is the next section.

COGS under FIFO, LIFO, WAC, and specific ID 

The formula is fixed. What it produces still depends on the costing method you use, because the cost you assign to ending inventory changes with the method, and when purchase prices move during the period, the four standard methods give four different answers.

  • FIFO (first in, first out): The oldest costs leave first, so COGS uses your earliest prices, and ending inventory reflects recent ones. In rising prices, this gives the lowest COGS.
     

  • LIFO (last in, first out): The newest costs leave first, so COGS uses your most recent prices. In rising prices, this gives the highest COGS and the lowest taxable income. LIFO is permitted in the US but not under IFRS.
     

  • Weighted average (WAC): Every unit is estimated at the period's average price, smoothing out cost swings.
     

  • Specific identification: Each unit carries its own actual cost, used for serialized or high-value goods.

Worked comparison: same stock, four methods

Illustrative figures, periodic system, prices rising through the period:

BatchUnitsCost per unitTotal cost
Beginning inventory100101,000
Purchase 1100121,200
Purchase 2100141,400
Available for sale300 3,600

The business sells 180 units at 22 each, so revenue is 3,960.

MethodUnits costed as soldCOGSEnding inventoryGross profit
FIFO100 × 10 + 80 × 121,9601,6402,000
LIFO100 × 14 + 80 × 122,3601,2401,600
WAC180 × 12 (3,600 ÷ 300)2,1601,4401,800
Specific identification60 × 10 + 70 × 12 + 50 × 14 (the units actually shipped)2,1401,4601,820

Three things to read from the table:

  • COGS plus ending inventory is 3,600 under every method. The method only decides how the same cost is split between this period and the stock you carry forward.
  • Price direction decides the ranking. With rising prices, FIFO gives the highest profit and LIFO the lowest. When prices fall, the order reverses.
  • Over the life of the stock, total COGS is the same. Once every unit has sold, each method has expensed the full 3,600. What differs is which period carries the cost.

Under a perpetual system, LIFO and WAC can give slightly different results from these periodic figures, because costs are assigned at each sale rather than at period end. LIFO is permitted under US generally accepted accounting principles (GAAP) but not under International Financial Reporting Standards (IFRS) or Indian Accounting Standard (Ind AS) 2. 

The method you pick can change your reported profit and your tax on the very same sales. The trade-off is worked through in our FIFO vs. LIFO guide.

Cost of goods manufactured (COGM): the manufacturer's formula

A manufacturer holds stock at three stages: raw materials, work in progress (WIP), and finished goods. Its COGS runs in three steps:

1. Direct materials used = Beginning raw materials + Raw material purchases − Ending raw materials

2. Cost of goods manufactured (COGM) = Beginning WIP + Direct materials used + Direct labour + Manufacturing overhead − Ending WIP

3. COGS = Beginning finished goods + COGM − Ending finished goods

The last step is the standard COGS formula, with COGM in place of purchases.

Worked example, illustrative figures:

StepWorkingAmount
Direct materials used10,000 + 40,000 − 8,00042,000
Direct labor 30,000
Manufacturing overhead 18,000
Total manufacturing costs42,000 + 30,000 + 18,00090,000
COGM12,000 (beginning WIP) + 90,000 − 9,000 (ending WIP)93,000
COGS20,000 (beginning finished goods) + 93,000 − 25,000 (ending finished goods)88,000

COGM is the cost of what was finished in the period; COGS is the cost of what was sold. The 5,000 gap between them here is the rise in finished goods held, from 20,000 to 25,000. Where costs are tracked by order or batch, job order costing supplies the labor and overhead figures per job.

What is and is not in COGS

The formula is only as good as the costs fed into it. COGS holds the costs of buying or making what you sold and getting it ready for sale. The costs of selling it and running the business sit below it as operating expenses.

In COGS (cost of the goods)Not in COGS (operating expenses)
Direct materialsOffice rent and utilities
Direct labor (production and assembly wages)Management, admin, and sales salaries
Manufacturing overhead (factory rent, utilities, equipment depreciation)Marketing and advertising
Freight-in (inbound shipping to receive stock or materials)Outbound shipping to customers and distribution
Packaging included with the productResearch, development, interest, and other financing

One question sorts most costs: was this cost incurred to buy or make the goods and get them to the place and condition in which they will be sold? If yes, it belongs in inventory and becomes COGS when the goods sell. If it was incurred to sell or deliver the goods or to run the business, it is an operating expense. Factory rent passes the test even in a month with no production; office rent does not.

Shipping is where ecommerce sellers most often slip. Freight to bring stock in counts toward COGS, while shipping orders out to customers is a selling expense that sits below it. 

When the inventory figure is wrong

COGS is a balancing figure. Whatever error sits in ending inventory lands in COGS in the opposite direction, then reverses in the next period through beginning inventory.

Take the worked example above and suppose ending stock was overcounted: the count said 15,000, but the true figure was 10,000. In the next period, purchases are 30,000, and an ending inventory of 12,000 is counted correctly (illustrative).

 Period 1 as reportedPeriod 1 correctPeriod 2 as reportedPeriod 2 correct
Beginning inventory50,00050,00015,00010,000
Purchases20,00020,00030,00030,000
Ending inventory15,00010,00012,00012,000
COGS55,00060,00033,00028,000

Period 1 COGS is understated by 5,000, so profit is overstated by 5,000. Period 2 reverses it, with COGS overstated by the same amount. Across the two periods COGS totals 88,000 either way, but both periods report the wrong margin and the wrong taxable profit.

The usual sources of the error:

  • Miscounts: items missed, double counted, or recorded in the wrong location.
  • Cutoff: goods counted before their purchase is recorded, or a purchase recorded for goods not yet received.
  • Goods in transit and consignment stock: stock you own but have not received left out, or stock you hold for someone else counted as yours.
  • Unit of measure: a case recorded as "each," or the reverse, which can move a value by a factor of 12 or 24.

Regular cycle counting catches most of these before the period closes.

COGS by industry 

What counts as a direct cost shifts with the business:

Business type

What goes into COGS (or its equivalent)

Manufacturer

Direct materials, direct labor, and factory overhead for goods produced and sold.

Retailer or wholesaler

The purchase cost of goods sold plus freight-in is often reported as “cost of sales” rather than COGS.

eCommerce

Product cost plus inbound shipping. Fulfillment and outbound shipping are usually operating expenses, not COGS.

Service business

The direct labor and materials used to deliver the service, usually reported as “cost of services” or “cost of revenue.”

SaaS

Reported as “cost of revenue:” hosting, third-party fees, and support tied directly to delivering the software.

The label changes with the model (COGS, cost of sales, or cost of revenue), but the principle is the same: It's only the direct costs of what you sold.

Period-end journal entries 

Once you have the number, you still have to record it, and that is the step most guides leave out. How you record it depends on your inventory system. Under a perpetual system, you record the cost at the moment of each sale:

Account

Debit

Credit

Cost of goods sold

X

 

Inventory

 

X

Under a periodic system, you do not touch COGS during the period; purchases sit in a temporary purchases account. At a period's end, one closing entry moves everything into COGS. Using the worked example above:

Account

Debit

Credit

Cost of goods sold

55,000

 

Purchases

 

20,000

Inventory

 

35,000

That single entry clears the period's purchases, reduces inventory from its $50,000 beginning balance to the $15,000 you counted, and lands $55,000 in COGS.

Common COGS mistakes 

  • Mixing operating expenses into COGS: Rent, admin salaries, marketing, and outbound shipping belong below gross profit, not inside COGS. Fold them in, and you understate your gross margin and can misstate your tax.
     

  • Leaving out freight-in: The cost of getting stock or materials to you is part of their cost. Skip it and you overstate your margin.
     

  • A wrong ending inventory count: COGS is only as accurate as the count behind ending inventory. A miscount passes straight through to profit.
     

  • Changing costing methods casually: FIFO, LIFO, and WAC produce different COGS, so switching midstream breaks comparability between periods. In the US, using LIFO for tax requires a formal election with the Internal Revenue Service (IRS).

COGS worksheet

Copy this table to work out COGS for any period.

LineYour figureWhere it comes from
Beginning inventory Last period's closing inventory
Add: purchases, net of discounts, returns and rebates Purchase records for the period
Add: freight-in and import duties Freight and customs bills for the period
= Cost of goods available for sale Sum of the lines above
Less: ending inventory Count or inventory records at period end
= Cost of goods sold Goods available for sale minus ending inventory
Revenue Sales for the period
Gross profit Revenue minus COGS
Gross margin Gross profit ÷ revenue

Frequently Asked Questions

What is the cost of goods sold formula?

COGS = Beginning Inventory + Purchases - Ending Inventory.

It measures what the inventory you sold during the period cost you; stock you bought but have not sold stays on the balance sheet as inventory until it does.

How do you calculate COGS?

Start with beginning inventory, add purchases to get your cost of goods available for sale, then subtract your ending inventory. For $50,000 beginning, $20,000 purchases, and $15,000 ending, COGS is $55,000.

What is included in COGS?

The direct costs of what you sold: materials, direct production labor, manufacturing overhead, and freight-in. It excludes operating expenses such as rent, admin and sales salaries, marketing, and shipping orders out to customers.

Is COGS an expense?

Yes, COGS is an expense on the income statement and is deductible for tax. Inventory sits on the balance sheet as an asset until it is sold, and at that point its cost becomes COGS.

Leave a Reply

Your email address will not be published. Required fields are marked

The comment language code.
By submitting this form, you agree to the processing of personal data according to our Privacy Policy.
Thank you! Our team will get in touch with you shortly.