Guide

Gross margin is the fraction of revenue left after the direct cost of delivering the product. That direct cost is COGS (cost of goods sold). Everything else — building the product, selling it, running the office — is opex. Mix them up and every later ratio on the P&L lies.

Gross profit  = Revenue − COGS
Gross margin  = Gross profit / Revenue

Concept

If turning off a customer would eventually remove the cost, it is usually COGS. If the cost exists whether you have 10 or 10,000 customers this month — core engineering salaries, the CEO, the office — it is opex. Grey areas exist. Be consistent quarter to quarter.

Walking through a SaaS P&L

In COGSUsually opex
Cloud hosting and compute for productionCore product engineering (R&D)
Third-party APIs required to deliver the product (LLM APIs, SMS, maps)Sales and marketing
Payment processing feesGeneral and administrative
Customer-facing support tightly tied to deliveryBrand marketing, PR
CDN and bandwidth for the productRecruiting for R&D
Licensed software embedded in the serviceOffice, legal, finance

Support is the classic grey area. Many SaaS companies put technical support in COGS and success / account management in S&M. AI companies almost always put inference in COGS — correctly.

A kitchen picture: flour and the cook's time for this plate are COGS. The rent on the restaurant and the recipe R&D are opex. The analogy breaks on shared infrastructure — a database serves every customer — but the test still holds: would the cost fade if that customer left?

Why the line matters

Gross margin sets the ceiling on operating margin. A company at 80% GM can spend 40 points on S&M, 20 on R&D, 10 on G&A and still show a path to 10%+ operating profit. A company at 50% GM that spends the same opex percentages is structurally loss-making until it cuts or reprices.

Even at healthy margins, the dollars add up. A company at $50M ARR with 75% instead of 80% GM leaves $2.5M / year on the table (0.05 × 50,000,000). That is several senior engineers.

Common mistakes

  • Putting inference in R&D so the AI product looks like 80% SaaS. Peers who book it correctly are not comparable.
  • Moving COGS into R&D before a fundraise to inflate gross margin. Auditors and good VCs notice.
  • Comparing marketplace GM on GMV to SaaS GM on subscription revenue. Ask: margin on what revenue definition?

Check yourself

  1. A new customer means more LLM tokens and a Stripe fee. COGS or opex? COGS — both scale with serving that customer.
  2. You hire two core product engineers. COGS or opex? Opex (R&D). Building the product is not delivering it.

Key takeaways

  • COGS is the cost of delivering. Building the product is R&D opex.
  • Gross margin = (Revenue − COGS) / Revenue.
  • The classification test: would the cost go away if the customer did?
  • Be consistent. Grey areas (support) are fine if they do not move around.

Further learning

How this number behaves for AI products: inference as COGS.