Cost of goods sold (COGS) is what the products you sold in a period cost you. It isn't what you spent on stock in that period, because some of what you bought is still on the shelf and some of what you sold was bought earlier. The calculator handles that by starting from inventory, not from purchases.

COGS is the first cost subtracted from revenue, so every margin figure in your business depends on it. Get it wrong and your gross margin, your break-even ROAS and your view of which products make money are all wrong with it.

How to calculate COGS

The formula follows the inventory through the period:

COGS = beginning inventory + purchases + other product costs − ending inventory

  • Beginning inventory is the value of the stock you held on the first day, at what it cost you. Not at retail price.
  • Purchases are the stock you bought during the period.
  • Other product costs are what it took to get that stock ready to sell: inbound freight, import duties and, if you make your own products, production labour.
  • Ending inventory is the value of the stock still on hand on the last day, counted the same way as the opening figure.

This is the same structure the IRS uses on Form 1125-A, the cost of goods sold schedule for US businesses: opening inventory, purchases, labour and other costs, minus closing inventory.

If you add revenue for the same period, the calculator subtracts COGS from it to give gross profit, and divides by revenue to give gross margin.

COGS worked example

These are the calculator's default inputs, for one quarter. Change them to your own numbers above.

Input or resultValue
Inventory at the start$40,000
Stock bought$22,000
Freight in and duties$3,000
Inventory at the end$35,000
Cost of goods sold$40,000 + $22,000 + $3,000 − $35,000 = $30,000
Revenue$100,000
Gross profit$100,000 − $30,000 = $70,000
Gross margin$70,000 ÷ $100,000 = 70%

The store spent $25,000 on stock and freight this quarter, but its COGS is $30,000, because it sold $5,000 more than it bought and ran its inventory down to cover the gap. Reading purchases as COGS would have overstated gross margin by five points.

What belongs in COGS, and what doesn't

The line is simple: costs of getting a product ready to sell go in, costs of selling it and getting it to the customer stay out.

In COGSNot in COGS
Product cost from your supplier or manufacturerShipping orders to customers
Inbound freight to your warehousePayment processing fees
Import duties and customs feesAd spend and agency fees
Production labour, if you make the productShopify plan and app subscriptions
Packaging that is part of the productDiscounts (they lower revenue instead)

The costs in the right-hand column still matter. Shipping, fees and discounts come out of every order, and they're what separate gross margin from contribution margin. They just aren't part of what the product cost you.

COGS per unit vs COGS for a period

The calculator above gives COGS for a period: a month, a quarter or a year. That's the figure for your profit and loss statement and for a store-wide gross margin.

For pricing one product you need COGS per unit instead: the supplier price plus that unit's share of freight, duties and packaging. That's the "cost of goods" input on the gross margin calculator and the markup calculator. Work out the landed cost once per product and update it when a supplier price or a freight rate changes.

Common COGS mistakes

  • Using purchases as COGS. It only works if inventory didn't change. In a month where you stock up for a sale, it makes margin look far worse than it is; in a month you sell through, far better.
  • Valuing inventory at retail. Opening and closing inventory must be at cost. Valuing stock at its selling price inflates ending inventory and makes COGS too low.
  • Leaving out freight and duties. The factory price alone understates what a product cost you, often by enough to move gross margin by several points.
  • Counting outbound shipping. It's real money, but it's a cost of fulfilment. Put it in contribution margin, or your gross margin will be too low to compare with anyone else's.
  • Skipping the stock count. Ending inventory from your system and inventory on the shelf drift apart through damage, loss and miscounts. A count at least once a year keeps COGS honest.

Where to go next

COGS feeds two other numbers worth tracking. Divide it by your average inventory with the inventory turnover calculator to see how quickly stock sells, or carry it into a full month with the Shopify profit calculator. Browse all our ecommerce calculators, or if you'd rather we looked at the store itself, the Teardown reviews your homepage, best-selling product page and cart drawer, with every finding ranked by what to fix first.