Ecommerce gross margin is the share of each sales dollar left after paying for the products you sold: net revenue minus cost of goods sold, divided by net revenue. It is the first number to check when an online store is growing but cash still feels tight. This guide is for Shopify, Amazon and DTC sellers who want to calculate it correctly, know what belongs in it, and find the levers that move it.
How to calculate ecommerce gross margin
The formula has three parts, and each one has a common mistake attached to it.
- Net revenue. Start with gross sales, then subtract returns, refunds and discounts. IRS Publication 334 calls this “net receipts”: gross receipts minus returns and allowances, which include refunds, rebates and other reductions to the sales price. Using gross sales instead overstates margin, sometimes by a lot for brands with high return rates.
- Cost of goods sold (COGS). Beginning inventory plus purchases and other product costs, minus ending inventory. This is the same calculation as lines 35 to 42 of Schedule C.
- Gross profit and gross margin. Gross profit is net revenue minus COGS. Gross margin is gross profit divided by net revenue, shown as a percentage.
Gross margin % = (net revenue − COGS) ÷ net revenue × 100
Gross margin is not the same as markup. Markup divides gross profit by cost, not by revenue. A product that costs $40 and sells for $100 has a 150% markup but a 60% gross margin. Mixing the two up is one of the most common reasons sellers think their margins are healthier than they are.
What belongs in cost of goods sold for an online store
Most margin errors come from putting costs in the wrong place. Your cost of goods sold deduction on the tax return follows specific rules, and your management reports should start from the same base.
| Cost | Where it goes | Why |
|---|---|---|
| Product cost from the supplier, net of trade discounts | COGS | Pub. 334: use the price you pay, not list price |
| Freight-in (shipping from supplier to you or your warehouse) | COGS | Pub. 334 lists freight-in as part of COGS |
| Packaging that is an integral part of the product | COGS | Pub. 334: integral packages are part of COGS |
| Shipping boxes and mailers not part of the product | Selling expense | Pub. 334: other containers are a shipping or selling expense |
| Outbound shipping to customers, marketplace and payment fees, ads | Operating expenses | Costs of selling, not of acquiring the goods |
| Inventory you took for personal use | Removed from purchases | Pub. 334 requires personal withdrawals to be excluded |
Larger sellers may also have to capitalize some indirect costs, such as warehousing and purchasing overhead, into inventory under the uniform capitalization rules of section 263A. Small business taxpayers are exempt: for 2025 that means average annual gross receipts of $31 million or less over the three prior tax years, a figure indexed for inflation each year (IRS Publication 334).
The method you use to assign cost to units sold also changes the number. Rising supplier prices make FIFO and LIFO produce different COGS from the same purchases; our guide to ecommerce inventory costing methods walks through the difference.
A worked example
The numbers below are an illustration, not data from any real store. A Shopify brand sells a skincare set for $60.
| Line | Per unit | Notes |
|---|---|---|
| Selling price | $60.00 | |
| Average discounts and returns | −$6.00 | 10% of gross sales |
| Net revenue | $54.00 | |
| Supplier cost | $15.00 | After trade discount |
| Freight-in, allocated per unit | $1.50 | |
| Branded jar and box (integral packaging) | $2.50 | |
| COGS | $19.00 | |
| Gross profit | $35.00 | Gross margin 64.8% |
| Outbound shipping and mailer | −$7.00 | Selling expense |
| Payment processing | −$1.80 | About 3% of the sale |
| Paid ads per order | −$14.00 | Customer acquisition |
| Contribution margin | $12.20 | 22.6% of net revenue |
A 65% gross margin looks comfortable. After shipping, fees and ads, only about 23 cents of each net revenue dollar is left to pay for salaries, software, rent and profit. That gap is why the next section matters.
Gross margin vs contribution margin vs net margin
Ecommerce brands need all three, because each answers a different question.
- Gross margin tells you whether the product itself is priced and sourced well. It is the number lenders, buyers and investors compare first, and it ties to your tax return.
- Contribution margin subtracts the variable costs of each order (fulfillment, shipping, marketplace and payment fees, and usually advertising). It tells you whether selling one more order makes or loses money.
- Net margin subtracts everything, including fixed overhead. It tells you whether the business as a whole is profitable.
Because ecommerce brands differ so much in where they put fulfillment and marketplace fees, gross margins are hard to compare across companies. Compare your own gross margin month to month, by product and by channel, using one consistent definition. Profitability analytics for ecommerce covers how to build those reports.
Why high profit margins matter for an ecommerce business
A thin gross margin leaves little room for the costs that grow with every order: shipping, fees, and advertising to win the next customer. Higher gross margins matter for three practical reasons.
- They pay for growth. Paid acquisition comes out of gross profit. A product with a 30% gross margin can only afford a fraction of the ad spend per order that a product with a 65% margin can.
- They protect cash. Inventory is paid for before it sells. Better margins refill the cash you tied up in stock faster.
- They absorb shocks. Supplier price increases, new import duties or higher shipping rates come straight out of gross profit. A wider margin gives you time to react without pricing changes.
How to improve your gross margin
- Measure it by SKU and channel. A single blended margin hides losers. Run gross margin per product and per channel (your site, Amazon, wholesale) every month.
- Fix the inputs first. Make sure returns, discounts and freight-in are recorded in the right accounts. Many “margin drops” are bookkeeping timing, not real changes.
- Negotiate landed cost, not only unit price. Freight, duties and packaging are part of what a unit costs you. Volume tiers, consolidated shipments and simpler packaging can move margin more than a small price increase.
- Review discounting. A permanent 20%-off code is a price cut. Check how much of your revenue carries a discount and whether it changes conversion enough to pay for itself.
- Use bundles carefully. Bundles raise order value, but pairing a high-margin item with a low-margin one can lower the margin percentage. Price bundles from the combined COGS.
- Cut or reprice the tail. Products that sell slowly at low margin tie up cash and warehouse space. Reprice them, reorder less, or discontinue them.
- Count inventory and write off what can’t be sold. Damaged or obsolete stock left in inventory overstates your margin until it is finally written off. IRS Publication 538 explains how goods that can’t be sold at normal prices are valued.
Common gross margin mistakes
- Calculating margin on gross sales instead of net revenue after returns and discounts.
- Confusing markup with margin when setting prices.
- Leaving freight-in or import duties out of product cost, then wondering why the books and the product spreadsheet disagree.
- Expensing inventory when it is bought instead of when it sells, which makes margins swing with purchasing cycles.
- Comparing your margin with another brand’s without knowing whether they include fulfillment and marketplace fees.
If your Amazon fees are part of the picture, our guide to ecommerce platform fee accounting shows where each fee belongs. For hands-on help, see our ecommerce accounting services.
Frequently asked questions
What is a good ecommerce gross margin?
There is no single target, because brands differ in what they put in cost of goods sold and in how much they spend on shipping, fees and ads below the gross profit line. The useful comparison is your own margin over time, by product and by channel, calculated the same way every month.
How do you calculate gross margin for an online store?
Subtract returns, refunds and discounts from gross sales to get net revenue. Subtract cost of goods sold to get gross profit. Divide gross profit by net revenue and multiply by 100. A product with $54 of net revenue and $19 of COGS has a gross margin of about 64.8%.
What is the difference between gross margin and markup?
Gross margin divides gross profit by revenue; markup divides it by cost. A product that costs $40 and sells for $100 has a 60% gross margin but a 150% markup. Pricing from markup while reporting margin is a common reason sellers overestimate their profitability.
Do shipping costs count in ecommerce cost of goods sold?
Freight-in, the cost of shipping inventory from your supplier to you, is part of cost of goods sold under IRS Publication 334. Outbound shipping to customers, shipping boxes that aren’t part of the product, and marketplace and payment fees are selling expenses below gross profit.
Why should I focus on high profit margins for my ecommerce business?
Gross profit is what pays for shipping, fees and the advertising that wins the next customer. A wider margin lets you afford more acquisition per order, refills the cash tied up in inventory faster, and gives you room to absorb supplier price increases or new import duties.






