Skip to content
MarginMeter

How to calculate SaaS gross margin (with a worked example)

The SaaS gross margin formula, what belongs in COGS, a worked example with AI and cloud costs, and the mistakes that make margin look better than it is.

October 3, 2026 · 2 min read

Gross margin is the share of each revenue dollar left after paying for what it takes to deliver your product. It is the clearest single signal of whether growth will make you richer or just busier.

The formula

Gross profit = Revenue − Cost of goods sold (COGS)
Gross margin % = Gross profit ÷ Revenue × 100

Both numbers must cover the same period — usually a calendar month or the last 30 days.

What counts as revenue

Use money actually earned in the period: subscription charges and one-off charges, minus refunds and disputes, excluding sales tax and VAT (you collect it for the government). If you bill annually, either spread the annual charge across months or compare like with like over a full year.

What counts as COGS

COGS is what it costs to serve the customers you have. For a typical SaaS:

  • Hosting and infrastructure — compute, databases, storage, bandwidth.
  • AI and third-party APIs used by the product — LLM inference, embeddings, OCR, maps.
  • Payment processing fees — Stripe's percentage and fixed fees.
  • In-product services — transactional email, monitoring of production, auth providers.
  • Customer support for existing customers (often included by mature companies; many early-stage founders leave it out — be consistent).

Not COGS: sales and marketing, R&D salaries, staging environments, internal tools. See what counts as COGS for SaaS.

Worked example

An AI writing tool in one month:

LineAmount
Revenue (net of refunds and tax)$10,000
OpenAI + Anthropic$1,400
AWS + Vercel$800
Stripe fees$330
Email, monitoring$120
COGS$2,650

Gross profit = $10,000 − $2,650 = $7,350. Gross margin = $7,350 ÷ $10,000 = 73.5%.

Where each $1 of revenue goesExample: $10,000 revenue
  • AI 14¢
  • Infrastructure 8¢
  • Payment fees 3¢
  • Other 1¢

Read it as cents: of every dollar, 14¢ goes to AI, 8¢ to infrastructure, 3¢ to payment fees, 1¢ to other services — you keep about 73¢.

Common mistakes

  1. Mixing MRR with costs. MRR is a run-rate, not revenue earned.
  2. Leaving out payment fees. At 3% they are often your third-largest cost.
  3. Counting credits as savings. Cloud credits expire; your real margin is what it will be without them.
  4. Partial days. Cost providers report with a delay. Comparing a complete month of revenue with 28 days of costs flatters margin.
  5. Ignoring the trend. A margin that slips half a point a week is a bigger problem than a stable one that's a little low.

Track it automatically

Calculating this once in a spreadsheet is easy. Keeping it current as prompts, models and traffic change is not. Try the gross margin calculator, or let MarginMeter compute it daily from Stripe, AWS, OpenAI and Anthropic.

See your real gross margin from your own data. Start free →

Frequently asked questions

What is the formula for SaaS gross margin?

Gross margin % = (Revenue − Cost of goods sold) ÷ Revenue × 100. For SaaS, COGS is the cost of delivering the product: hosting, AI APIs, payment fees, third-party services in the product, and customer support that serves existing customers.

Should I use MRR or revenue?

Use revenue for the same period as your costs. MRR is a run-rate; it doesn't include refunds, one-off charges or timing differences, so mixing it with actual monthly costs distorts the margin.

What is a good gross margin for SaaS?

Traditional SaaS is commonly described as running at 70–80% or more. AI-heavy products often run lower because inference is a variable cost. The trend matters as much as the level.

See your real margin in five minutes.

Connect Stripe and your cost providers with read-only access. Free for two connections — no card required.