If you sell physical products, cost of goods sold (COGS) is one of those numbers that quietly runs your entire business. Get it wrong and your gross profit lies to you. Get it right and you finally know whether that bestselling SKU is actually making you money after accounting for what it cost to acquire or produce the inventory you sold.
The good news? The COGS formula itself is simple.
The hard part is making sure the inventory and purchase numbers going into it are accurate.
The COGS Formula
For a business using the periodic inventory method, cost of goods sold is calculated by taking your beginning inventory, adding purchases and other costs included in inventory, and subtracting your ending inventory.
COGS = Beginning Inventory + Purchases − Ending Inventory
That’s it. Three numbers, one subtraction.
The complexity isn’t in the math. It’s in getting each of those three numbers right and consistently valuing your inventory.
Step 1: Find Your Beginning Inventory
Beginning inventory is the value of the inventory you had on hand at the start of the period you’re measuring. That period could be a month, quarter, or full year.
For example, if you ended last year with $40,000 worth of inventory, that amount generally becomes your beginning inventory for the new year.
Your beginning inventory should also match the prior period’s ending inventory. If those numbers don’t line up, something may have changed in your inventory records, valuation, or accounting entries and should be investigated before you calculate COGS.
For an e-commerce business, beginning inventory can include products sitting in your own warehouse as well as inventory held at a third-party fulfillment location, depending on who owns the inventory and how it is accounted for.
Step 2: Add Purchases and Other Inventory Costs
Next, determine the inventory you acquired or produced during the period.
For a typical e-commerce seller, this can include
- Wholesale or manufacturing costs for products purchased for resale
- Inbound freight and shipping associated with acquiring inventory
- Customs duties and certain import costs
- Direct production costs for businesses that manufacture or assemble products
- Other costs that are properly included in the inventory’s recorded cost
This is where Amazon and Shopify sellers often get tripped up.
For example, suppose you buy $20,000 of inventory from an overseas supplier and spend another $2,000 on inbound freight and applicable import costs to get those goods ready for sale. Treating all $22,000 appropriately as inventory cost can give you a more accurate picture of what those products actually cost you.
By contrast, expenses such as advertising, Shopify subscriptions, general administrative costs, and most selling expenses don’t become part of the product’s inventory cost simply because they helped you sell the product.
Step 3: Subtract Ending Inventory
Ending inventory is the value of the products you still own at the end of the period.
Those goods haven’t been sold yet, so their cost generally remains on the balance sheet as inventory rather than becoming part of COGS for the current period.
That’s why ending inventory is subtracted from the formula.
This is also where accurate inventory records become critical. If your ending inventory figure is wrong, your COGS figure will be wrong too.
A physical inventory count can help verify the quantities you actually have on hand. Businesses with large catalogs may also rely on inventory management and accounting systems, provided those systems are properly maintained and reconciled.
A Quick COGS Example
Suppose your e-commerce business starts the quarter with:
- Beginning inventory: $25,000
- Purchases and qualifying inventory costs: $18,000
- Ending inventory: $15,000
Your COGS would be:
$25,000 + $18,000 − $15,000 = $28,000
So your COGS for the quarter is $28,000.
If the business generated $60,000 in revenue during the same period:
$60,000 − $28,000 = $32,000 gross profit
Your gross margin would be approximately 53.3%.
That $32,000 gross profit is the amount available to cover operating expenses such as advertising, software, payroll, professional fees, and other costs before arriving at operating or net profit.
What Actually Counts as a Purchase?
This is where much of the confusion around COGS comes from.
“Purchases” in the formula isn’t necessarily limited to the amount printed on your supplier invoice. Depending on your accounting method and the nature of the cost, inventory cost can include other costs directly associated with acquiring or producing goods.
For a typical ecommerce seller, inventory cost may include:
- The wholesale or manufacturing cost of the product
- Inbound freight and transportation
- Customs duties and certain import costs
- Direct labor and production costs for goods you manufacture or assemble
- Certain packaging costs that are part of preparing the product for sale
What generally doesn’t belong in product inventory cost are expenses associated with operating or selling the business, such as:
- Paid advertising
- General administrative payroll
- Accounting and professional fees
- Shopify or other e-commerce software subscriptions
- General office expenses
- Outbound shipping to customers, depending on the nature and accounting treatment of the cost
The important distinction is between costs that become part of the inventory and operating or selling expenses incurred to run the business.
If you mix those categories, your gross margin can look very different from the economics of the actual products you’re selling.
Why Beginning and Ending Inventory Need to Be Accurate
A surprising number of small e-commerce sellers estimate inventory value instead of maintaining reliable records, especially as their catalog grows.
That’s a problem because COGS is only as accurate as the inventory figures behind it.
If ending inventory is overstated, COGS will be understated, which makes gross profit appear higher than it really is.
If ending inventory is understated, the opposite happens: COGS is overstated and gross profit appears lower.
The solution isn’t complicated, but it does require consistency.
Perform regular inventory counts or use reliable inventory software that tracks stock movements as orders, purchases, returns, adjustments, and transfers occur. Then reconcile those records to your accounting system.
For Shopify sellers, inventory tools such as Cin7 or Katana can help with inventory tracking, but software is only useful when the underlying transactions and quantities are maintained correctly.
COGS vs. Cost of Revenue: What’s the Difference?
You’ll sometimes see “cost of revenue” and “cost of goods sold” used interchangeably, especially in financial reporting.
For a business that primarily sells physical products, COGS is the more specific term.
Cost of revenue can be broader and may include costs associated with delivering products or services, depending on the company’s business model and reporting practices.
For example, a business that combines physical products with subscriptions or ongoing services may have a broader cost-of-revenue category than a straightforward e-commerce retailer.
If your business primarily buys or manufactures physical products for resale, COGS is the terminology you’ll most commonly encounter in e-commerce bookkeeping and inventory accounting.
How to Calculate COGS for Individual Products
A business-level COGS figure tells you whether the company is generating an acceptable gross margin overall. But it doesn’t tell you which products are actually making money.
That’s where SKU-level analysis becomes useful.
Instead of looking only at total COGS, assign the appropriate inventory cost to the units sold for each SKU.
For example, suppose you sell the same product at different times but your supplier raises the purchase price during the year. The cost assigned to the units you sell may vary depending on the inventory valuation method your business uses.
Common inventory valuation methods include:
- FIFO (First In, First Out)
- LIFO (Last In, First Out), where permitted
- Weighted average cost
The key is to apply your chosen method consistently and in accordance with the accounting and tax rules that apply to your business.
Once you know the cost assigned to the units sold, you can calculate the COGS for that SKU.
This can reveal problems that a business-wide margin hides. A product that once generated a 50% gross margin may now be producing a much thinner margin because of supplier price increases, higher inbound freight, or other changes in inventory cost.
What About Returns, Damaged Goods, and Lost Inventory?
Ecommerce inventory doesn’t move in a perfectly straight line from supplier to customer.
Products get returned. Orders get damaged. Inventory gets lost. Some products become unsellable.
Those events need to be reflected properly in your inventory records.
For example, if a customer returns a product and it is still in sellable condition, it may be returned to inventory. If the product is damaged and can’t be resold, its cost may require a different accounting treatment.
The same goes for inventory that is lost, destroyed, or written off.
Don’t simply leave these items sitting in your inventory records indefinitely. An inventory balance that says you have 100 units when you actually have 82 will eventually create problems for your COGS calculation and financial reporting.
How COGS Affects Your Taxes
COGS also matters when you’re preparing your US business tax return.
For businesses that report inventory and calculate COGS, the cost assigned to goods sold is generally used in determining gross income. On a Schedule C, for example, COGS is calculated in Part III and flows into the calculation of gross profit before other business expenses are considered.
That means inaccurate inventory accounting can affect more than your internal reports.
If you understate COGS, you may overstate gross profit and taxable business income.
If you overstate COGS, you may understate income and claim a larger tax benefit than you’re entitled to.
The tax treatment of inventory can depend on the business’s accounting method, size, industry, and other circumstances, so businesses with complex inventory should work with a qualified tax professional rather than treating the COGS formula as a substitute for tax advice.
Common COGS Mistakes Ecommerce Sellers Make
A few mistakes show up again and again in e-commerce bookkeeping:
1. Recording inbound freight as a generic shipping expense
Costs associated with acquiring inventory may need to be included in inventory cost rather than automatically expensed as outbound shipping.
2. Changing inventory valuation methods without proper accounting treatment
Switching between FIFO, LIFO, and other methods can affect reported COGS and inventory values. Don’t change methods casually just because one produces a better-looking margin.
3. Ignoring inventory adjustments
Damaged, lost, obsolete, or unsellable inventory needs to be reflected appropriately in the books.
4. Forgetting about returned inventory
A returned product doesn’t automatically remain a COGS expense. Its condition and whether it can be resold matter.
5. Mixing product costs with operating expenses
Advertising, software subscriptions, office costs, and other operating expenses shouldn’t automatically be pushed into inventory simply because they support the business.
6. Relying on inventory quantities without reconciling them
Your ecommerce platform may show one inventory number while your accounting system shows another. If those systems aren’t reconciled, your COGS calculation can quickly become unreliable.
These mistakes may seem small individually, but they compound over time. A business that has been making the same inventory accounting mistake for two years doesn’t just have one bad month of reporting. It may have an entire gross-margin trend that’s been misleading management.
The Honest Part
Most small e-commerce sellers don’t get COGS wrong because the formula is difficult. They get it wrong because their inventory records are messy.
The math is one subtraction.
What takes actual work is keeping consistent records of what came in, what went out, what was returned, what was damaged, and what is still sitting on the shelf.
If you’re not confident in your beginning or ending inventory numbers, fix that first. Make sure your inventory system, e-commerce platform, and accounting records tell the same story.
Because the formula only works when the inputs are accurate.
And once those inputs are reliable, COGS becomes more than a number on your income statement. It becomes one of the clearest ways to see which products are actually making your e-commerce business money.




