Contribution margin formula for a Shopify store, worked line by line

The contribution margin formula is net revenue minus variable costs. For a Shopify store, subtract product cost, then shipping, then payment fees, then ad spend. In one example month, not a customer result, $16,610,912.12 of net revenue leaves $3,332,439.80, a margin of 20.06%.

Cosmic AI cover for the topic Contribution margin: bars that step down to one bright bar, lavender on dark purple.

What is the contribution margin formula?

The contribution margin formula is revenue minus variable costs. A variable cost is one that rises and falls with the number of orders. What remains is the money that pays for fixed costs such as salaries, rent and software, and then becomes profit.

Contribution margin       = Net revenue - Variable costs
Contribution margin ratio = Contribution margin / Net revenue

My position, and you may disagree: a store should manage by contribution margin after ads, not by gross margin and not by the textbook per-unit figure. In the example month worked below, gross margin is 58.00% and margin after ads is 20.06%. A brand that buys its customers with ads lives on the second number. Ad spend belongs in the formula for that reason, and the rest of this page shows how.

According to Investopedia's definition of contribution margin, the per-unit version is the selling price per unit minus the variable cost per unit. That is the version most guides teach. I checked the five results that rank highest for this search on 25 November 2026. One works a single $50 item with $30 of variable cost. The others are a short accounting primer, a video on the ratio, a page about profit margin in a spreadsheet, and a social post.

A store does not sell one product at one price. For example, a month on Shopify has discounts, refunds, a shipping bill, card fees and an ad budget. The formula stays the same. The work is deciding what goes into each side and in what order.

Which costs are variable for a Shopify store?

Four costs are variable for nearly every Shopify store: product cost, shipping, payment fees and ad spend. Each moves with orders, and each lives in a different place.

Variable costIt rises withWhere the number livesIn the example below
Product costUnits soldCost per item on each product in Shopify42% of net revenue
Shipping and fulfilmentOrders shippedCarrier and warehouse invoices$7.50 per order
Payment feesOrders and revenueYour payment provider's statement2.9% of revenue plus $0.30 per order
Ad spendWhat you choose to spendEach ad platformMeta spend for the same days

Start from net revenue, not gross. Shopify's finance reports documentation defines net sales as gross sales minus discounts and sales reversals, and says the figure leaves out shipping charges and taxes. Shopify can hold a cost per item on every product, and Shopify's profit reports use it. Card rates depend on your plan: the Shopify pricing page lists rates from 2.9% plus 30 cents on the Basic plan.

Ad spend is the one people argue about. A textbook would call it a marketing expense. For a brand that buys most of its new customers with ads, spend moves with orders, so it belongs in the formula. Report the margin both ways, before ads and after. The levels below do exactly that.

The formula worked on one month

The figures below are example figures from an example store, not customer results. The example store is far larger than most, so read the shares and ratios, not the totals. They cover 30 days: 227,671 orders and $16,610,912.12 of net revenue. The totals for gross margin, margin before ads and margin after ads come from the product's own calculation. The individual cost lines are my arithmetic from the four cost inputs, and they land within a few cents of those totals.

LineCalculationAmountShare of net revenue
Net revenueFrom Shopify, 227,671 orders$16,610,912.12100.00%
Product cost42% x $16,610,912.12$6,976,583.0942.00%
Gross marginNet revenue less product cost$9,634,329.0158.00%
Shipping227,671 x $7.50$1,707,532.5010.28%
Payment fees2.9% x $16,610,912.12, plus 227,671 x $0.30$550,017.753.31%
Contribution margin before adsGross margin less shipping and fees$7,376,778.8044.41%
Ad spendMeta, same 30 days$4,044,339.0024.35%
Contribution margin after adsBefore ads less ad spend$3,332,439.8020.06%

Read it from the top. Of every $100 of net revenue, $42.00 went to product, $10.28 to shipping and $3.31 to card fees. That left $44.41 before any advertising. Ads took $24.35. The brand kept $20.06 to cover everything else.

The same month per order, again my arithmetic on the example data:

Average order value             $72.96
Product cost (42%)             -$30.64
Shipping                        -$7.50
Payment fees (2.9% + $0.30)     -$2.42
Margin before ads               $32.40
Ad spend per order             -$17.76
Margin after ads                $14.64

A founder who looks only at the $72.96 sees a healthy order. The $14.64 is what the order contributed.

What are contribution margin 1, 2, 3 and 4?

Contribution margin 1, 2, 3 and 4 are names for the stopping points in the subtraction. Each level takes off one more group of costs. Contribution margin 1 is what is left after product cost. Contribution margin 2 also takes off the costs of getting the order to the customer. Contribution margin 3 also takes off advertising. Some teams add a fourth level for whatever variable costs remain.

LevelCosts taken off at this levelQuestion it answersExample month
CM1Product costIs the product priced above what it costs?$9,634,329.01 (58.00%)
CM2CM1 less shipping, fulfilment and payment feesWhat is a delivered order worth before marketing?$7,376,778.80 (44.41%)
CM3CM2 less ad spendWhat did the business keep after paying for its customers?$3,332,439.80 (20.06%)
CM4, where usedCM3 less other variable costs: support per ticket, chargebacks, affiliate payoutsWhat is left once every cost that scales with orders is counted?Not in the example data

The example column is the same example month, not a customer result.

There is no single standard for the levels. Some teams count shipping in CM1. Others take advertising off at CM2 and keep CM3 for the smaller variable costs. Pick one convention, write down which costs sit at each level, and use it in every report. A CM2 from one tool and a CM2 from another may not be the same number.

The levels earn their keep when you judge ad spend. Contribution margin 2 sets the break-even. By my arithmetic, 1 divided by 0.4441 is 2.25, so this example store needs $2.25 of revenue for each ad dollar before advertising pays for itself. Its marketing efficiency ratio for the month was 4.11, which clears that bar, and the article on break-even ROAS takes the calculation further. Contribution margin 3 is the number to manage the business by. It is the only level that falls when you overspend on ads.

How do I track contribution margin for my Shopify store?

Track it weekly, from five inputs, at the same three levels every time.

  1. Record a cost per item on every product and variant in Shopify. Without it there is no CM1.
  2. Pull net sales and order count by day from Shopify. Use net sales, after discounts and returns.
  3. Add shipping and fulfilment cost. A cost per order from your carrier and warehouse invoices is enough to start.
  4. Add payment fees from your provider's statement: the percentage and the fixed fee per order.
  5. Add ad spend by day from each ad platform, in the same time zone as the store.

Then compute CM1, CM2 and CM3 for the same days and put them in one row per week. A spreadsheet handles this for one store. What breaks it is upkeep: costs change, a platform export shifts by a day, and nobody notices until the margin looks strange.

Three mistakes that make the formula lie

  1. Mismatched dates. Revenue and ad spend must cover the same days. Subtracting 90 days of ad spend from a year of revenue produces a margin that looks wonderful and means nothing. On the same example data, the 90 day figure is 20.52% on $37,285,338.38 of net revenue, close to the 30 day figure, which is what you should expect when the windows match.
  2. Using revenue an ad platform claims. The formula starts from what Shopify recorded. Meta, Google and Klaviyo each report revenue they credit to themselves, and those claims overlap. The guide to ecommerce data reconciliation shows how far apart they can sit.
  3. Treating product cost as a flat percentage. The example does this, at 42%, to keep the arithmetic readable. A real store should not copy it. A discount lowers revenue without lowering what the product cost you, so a flat percentage hides the damage a sale does. Use cost per item.

A fourth, smaller one: leaving out the fixed fee per order. At $0.30 on 227,671 orders it was $68,301.30 in this example month.

How Cosmic AI uses the formula

Cosmic AI computes contribution margin for a Shopify brand once its costs are set, and its agents report in that figure instead of revenue. If costs have not been entered, the answer is "not enough data", not an estimate. Supported figures are checked against their source first. The month above is an example, and there are no customer results to show yet.

The same figures are available in a terminal through the command line tool. The product page and pricing cover the rest, and the article on an AI growth agent for Shopify explains the agents. For the ratio and the per-order view, see contribution margin ratio and contribution margin per order.

Frequently asked questions

How are contribution margins calculated?

Contribution margin is the result of subtracting variable costs from net revenue. For a Shopify store the variable costs are product cost, shipping, payment fees and ad spend. Divide the result by net revenue to get the ratio. The example month above works out to 20.06%.

Is 30% contribution margin good?

A contribution margin is good when it covers your fixed costs with profit left over, so the answer depends on those costs. A 30% margin on $10 million of net revenue is $3 million. If salaries, rent and software total $2 million, it is enough. If they total $4 million, it is not.

What is contribution margin 1, 2, and 3?

Contribution margin 1, 2 and 3 are the stopping points in the calculation. CM1 is usually net revenue less product cost. CM2 also removes shipping and payment fees. CM3 also removes ad spend. Companies define the levels differently, so ask what each one includes.

What is a variable cost?

A variable cost is a cost that changes with how much you sell. Product cost, shipping and card fees rise with every order. Rent and salaries do not, so they are fixed costs and stay out of the contribution margin formula.

How do I track contribution margin for my Shopify store?

Record a cost per item on every product in Shopify, then each week combine five inputs for the same days: net sales, product cost, shipping cost, payment fees and ad spend. Report the result at three levels, CM1, CM2 and CM3, so you can see where margin is lost.

Check what went into your margin.

See the Cosmic command that shows the contribution margin calculation and its assumptions.

Cosmic AI is one desktop app where a lead agent and its specialists do the marketing work for a Shopify store. Each figure is checked against its source, and agents act on their own inside limits you set.

Book a callSee the margin command

Get Jake's AI newsletter

Three short emails a week with the AI news that matters for running or building a business. Every item links to its source.

I'll try to point you to something useful for it in your first email. No passwords or keys.

You will get Jake's newsletter and occasional Cosmic AI news. Unsubscribe in one click from any email. Privacy