To calculate cost of goods sold, add your beginning inventory to the purchases you made during the period, then subtract your ending inventory. The COGS formula is: beginning inventory + purchases - ending inventory. For ecommerce sellers, purchases means fully landed cost, which includes the supplier's unit price plus inbound freight and import duty.
That formula appears in every accounting textbook, and it is correct. It is also the easy part. Most ecommerce sellers who get COGS wrong do not get the arithmetic wrong. They feed the formula bad inputs: a landed cost that misses freight and duty, an inventory count that has not been reconciled in months, or marketplace fees classified into the wrong bucket. This guide covers the formula, then spends most of its time on the inputs, because that is where the real number lives.
COGS sits at the center of ecommerce accounting. It is the largest expense line for most product businesses, it drives gross margin, and it determines whether the growth you are funding with ad spend is profitable growth or expensive noise. A COGS number that is off by 10 percent quietly reprices every decision downstream of it.
The COGS formula, term by term
The formula has three inputs, and each one has a precise meaning. Beginning inventory is the value of stock you held on the first day of the period, at cost, not at retail price. Purchases is everything you added to inventory during the period, again at cost. Ending inventory is the value of stock still on hand when the period closes.
The logic is simple once you see what the formula is doing. Beginning inventory plus purchases equals everything you could have sold, which accountants call goods available for sale. Whatever you did not sell is still sitting in ending inventory. Subtract it, and what remains is the cost of everything that went out the door.
Two properties of the formula matter for sellers. First, COGS only recognizes cost when a unit sells. A $40,000 purchase order that arrives in March but sells through in April belongs to April's COGS, not March's. That is why COGS on your income statement rarely matches your inventory spend in the same month, and why the two numbers should never be expected to match. Second, the formula is only as accurate as the ending inventory count. If ending inventory is overstated because of unrecorded shrinkage or stale counts, COGS is understated and profit looks better than it is.
What belongs in COGS for an ecommerce brand
The formula tells you how to combine the inputs. It does not tell you what qualifies as a product cost in the first place, and this is where ecommerce sellers make the most classification mistakes. The rule of thumb: if a cost was required to get a sellable unit onto your shelf, it belongs in COGS. If a cost was incurred to sell, ship out, or run the business, it is an operating expense.
In COGS: the supplier's unit price, inbound freight from factory to warehouse, import duties and tariffs, customs brokerage, cargo insurance, and the packaging that makes the product sellable, such as the retail box the customer keeps. Together these make up landed cost, and we cover the full build in our guide to true landed cost per SKU.
Not in COGS: merchant processing fees, marketplace referral fees, outbound shipping to the customer, the shipping carton and void fill, pick and pack fees, advertising, software, and salaries. These are real variable costs, and they absolutely belong in contribution margin when you evaluate a SKU. But they are selling and fulfillment expenses, not product costs, and mixing them into COGS distorts gross margin and makes benchmarking impossible. If you want to see what those selling costs actually total per order, our ecommerce fee calculators break down the marketplace and processing side.
The packaging distinction trips up almost everyone, so it is worth stating plainly. Product packaging that is part of the unit, like a branded box or protective insert applied before the item is stocked, is inventory cost and flows through COGS. Shipping materials consumed at fulfillment, like mailers and tape, are fulfillment expense. The test is whether the cost attaches to the unit before it sells or at the moment it ships.
A worked example: one quarter, two purchase orders
Here is how the calculation looks for a seller who imports a single SKU and receives two purchase orders during the first quarter. All figures are illustrative. Notice that each lot carries a different landed cost, because freight and duty rarely land at the same rate twice.
Step 1: Build landed cost per lot (illustrative figures)
| Lot | Units | Unit cost | Freight per unit | Duty per unit | Landed cost per unit | Lot value |
|---|---|---|---|---|---|---|
| Beginning inventory (Jan 1) | 1,200 | n/a | n/a | n/a | $9.00 | $10,800 |
| PO 1 (received January) | 2,000 | $7.10 | $0.70 | $0.30 | $8.10 | $16,200 |
| PO 2 (received March) | 1,500 | $7.40 | $1.00 | $0.60 | $9.00 | $13,500 |
Step 2: Apply the formula (illustrative figures)
| Component | Calculation | Value |
|---|---|---|
| Beginning inventory | 1,200 units at $9.00 | $10,800 |
| + Purchases at landed cost | $16,200 + $13,500 | $29,700 |
| − Ending inventory (counted Mar 31) | 1,450 units at $9.00 (FIFO) | $13,050 |
| = COGS for Q1 | $27,450 |
The seller sold 3,250 units during the quarter. Under FIFO, those units drew down the oldest costs first: all 1,200 beginning units at $9.00, all 2,000 units from PO 1 at $8.10, and 50 units from PO 2 at $9.00. That totals $27,450, which matches the formula. The 1,450 unsold units, all from the newest lot, carry forward as ending inventory at $9.00 each.
Now run the same quarter with the most common input error: using factory unit cost instead of landed cost. Purchases would be recorded at $25,300 instead of $29,700, and the $4,400 of freight and duty would either vanish into a general expense line or be missed entirely. COGS drops, gross margin looks materially better than reality, and every per-unit profitability decision built on that margin inherits the error. The formula did its job. The input was wrong.
Your costing method changes the number
The worked example used FIFO, which assigns the oldest costs to units sold first. That was a choice, and it is not the only one. Under weighted average cost, every unit in stock carries the blended average of all lots, and under LIFO the newest costs flow out first. With the lot costs above, each method produces a different COGS from identical physical sales.
The differences are not academic when costs are moving. In a rising-cost environment, FIFO produces lower COGS and higher reported profit, while LIFO produces higher COGS and a lower tax bill. Most ecommerce sellers land on FIFO or weighted average, in part because LIFO is prohibited under IFRS and adds real complexity. The full comparison, including the tax rules and a worked example of switching, is in our guide to FIFO vs LIFO.
Whichever method you choose, consistency matters more than the choice itself. The method decides which cost layer gets expensed when a unit sells, and switching methods between periods makes your margin trend meaningless. Pick one, document it, and apply it every period.
Why marketplace reports understate true COGS
Shopify and Amazon both offer cost-of-goods fields, and both will happily report a gross profit number built on whatever you typed into them. Sellers often treat these reports as their COGS source of truth. They are not, for three structural reasons.
First, the cost field holds a single static number per SKU, usually the factory unit cost someone entered when the listing was created. It knows nothing about freight, duty, brokerage, or insurance, so it systematically reports cost below true landed cost. It also never updates as new lots arrive at new prices, so a SKU whose landed cost has climbed 15 percent across three purchase orders still reports the original figure.
Second, marketplace reports have no inventory count. They multiply units sold by the static cost, which means shrinkage, damaged returns, disposed FBA stock, and miscounts never reach the cost line. The periodic formula catches all of this automatically, because whatever is missing from the physical count flows into COGS. A units-times-cost report cannot, and the gap compounds every month it goes unreconciled.
Third, each channel only sees itself. If you sell on Shopify and Amazon from shared inventory, neither platform can value your total stock or agree on which lot a given unit came from. Consolidating channels against one inventory ledger is a bookkeeping job, not a reporting toggle, and it is one of the core reasons multichannel sellers move to proper ecommerce bookkeeping instead of exporting dashboards.
Marketplace profit reports are useful for directional, same-channel comparisons. For your income statement, tax filings, and any decision where margin accuracy matters, calculate COGS from your own books.
Three input checks that fix most COGS errors
Before trusting a COGS number, audit the three inputs. Check the landed cost build first: pull your last purchase order and confirm freight, duty, and brokerage were capitalized into inventory rather than expensed on arrival. If those costs went straight to an expense account, your COGS is understated and your operating expenses are overstated by the same amount.
Check the count second. Ending inventory should come from a physical count or a cycle-count program reconciled to your ledger, not from a system quantity nobody has verified since last year. Every unit of unrecorded shrinkage sits in ending inventory as phantom value, suppressing COGS and inflating profit until the eventual write-off lands all at once.
Check classification third. Scan your COGS account for merchant fees, outbound shipping, and ad spend that drifted in, and scan operating expenses for freight-in that drifted out. Clean classification is what makes your gross margin comparable to benchmarks and your product profitability analysis trustworthy at the SKU level. It also keeps inventory turnover honest, since that ratio depends on a clean COGS numerator.
Where Futureproof fits
Everything above is manual work today for most sellers: chasing freight invoices, allocating duty across lots, reconciling counts, and reclassifying fees every close. Futureproof's AI finance team does this as bookkeeping, not as a spreadsheet project. Theo captures supplier and freight bills as they arrive, Vic keeps the books and classifications clean, and Margo turns the resulting margins into forecasts you can act on.
Shopify and Amazon integrations are now in beta. If you want COGS calculated from real landed costs instead of a static cost field, join the ecommerce waitlist.
Frequently asked questions
What is the formula for COGS?
COGS = beginning inventory + purchases during the period - ending inventory. Beginning and ending inventory are valued at cost, and purchases should reflect fully landed cost, meaning unit price plus inbound freight, duty, and related import costs. The result is the cost of the units that actually sold during the period.
Are Shopify or Amazon fees included in COGS?
No. Payment processing fees, referral fees, and fulfillment fees are selling expenses, not product costs, so they belong in operating expenses. They still matter for per-order profitability, which is why they appear in contribution margin analysis, but including them in COGS overstates product cost and makes your gross margin impossible to benchmark.
Is shipping included in cost of goods sold?
Inbound shipping is, outbound shipping is not. Freight from your supplier to your warehouse is part of landed cost and is capitalized into inventory, flowing through COGS as units sell. Shipping an order to a customer is a fulfillment expense that belongs below the gross profit line.
How do you calculate COGS without an ending inventory count?
You can estimate it by multiplying units sold by landed cost per unit, which is how perpetual inventory systems work between counts. The estimate is fine for interim reporting, but it silently misses shrinkage, damage, and miscounts. Reconcile against a physical count at least quarterly so the accumulated gap flows into COGS instead of hiding in inventory.
Does COGS include unsold inventory?
No. Inventory you have not sold stays on the balance sheet as an asset and only becomes COGS when it sells. This is why a heavy inventory purchase does not hit your profit in the month you pay for it, and why COGS and inventory spend can look very different in any given period.



