Cost of Goods Sold (COGS): Formula & How to Calculate

Cost of goods sold

Cost of Goods Sold (COGS) is the direct cost of producing the goods a company sold during a period, raw materials, direct labor, and production overhead. You calculate it as Beginning Inventory + Purchases − Ending Inventory, then subtract it from revenue to get gross profit.

What is Cost of Goods Sold (COGS)?

COGS represents the direct costs tied to producing or acquiring the products a company sells. It's one of the largest line items on most income statements and the single biggest driver of gross profit and gross margin. Tracking COGS shows how efficiently a business turns inputs into sellable product, and how much room it has to price competitively while staying profitable.

The COGS Formula

COGS = Beginning Inventory + Purchases − Ending InventoryCost of goods sold

You start with the inventory you held at the beginning of the period, add everything you bought or produced during it, then subtract what's still on the shelf at the end. Whatever was "used up" to make sales is your COGS.

Worked example

Say a furniture maker starts the quarter with $20,000 of inventory, buys $50,000 of wood and fabric, and ends with $15,000 of unsold inventory:

COGS = $20,000 + $50,000 − $15,000 = $55,000Quarterly COGS

If quarterly revenue was $90,000, gross profit is $90,000 − $55,000 = $35,000 (a 39% gross margin).

What COGS Includes vs Excludes

Included in COGS (direct)Excluded from COGS (indirect → OpEx)
Raw materials & componentsMarketing & advertising
Direct production laborAdministrative & office salaries
Manufacturing overheadRent for non-production space
Freight-in / inbound shippingR&D and software tools
Inventory bought for resaleDistribution & sales commissions

COGS in SaaS (cost of revenue)

Software companies have COGS too, often labelled cost of revenue. It is the cost of delivering the service, not making a physical product, and it is the single biggest lever on SaaS gross margin. There is no inventory, so the Beginning + Purchases − Ending formula above does not apply. Instead you total the direct delivery costs for the period.

Included in SaaS COGSExcluded (→ OpEx)
Cloud hosting & infrastructure (AWS, GCP, Azure)Sales & marketing
Third-party software & APIs used to deliver the productR&D / new-feature engineering
Payment processing & transaction feesGeneral & administrative (G&A)
Customer support & success salariesMost depreciation & amortization
DevOps / site-reliability laborInterest & financing costs
Professional services (onboarding, implementation)

One nuance: some teams capitalize internally-developed software and amortize it into COGS. Treatment varies, so pick a policy and apply it consistently.

SaaS COGS benchmarks

Because delivery cost is low relative to revenue, SaaS gross margins run high. Benchmarkit's 2025 data puts the median total SaaS gross margin around 77%, with top-quartile subscription-only margins above 80%. In practice COGS lands at roughly 20-25% of revenue. Consistently below 70% total gross margin usually signals a structural problem: over-provisioned infrastructure, a heavy professional-services mix, or support that scales linearly with customers.

Estimating SaaS COGS

With no inventory, the quickest checks are the reverse formula and the ratio:

COGS = Revenue − Gross Profit · COGS % = (COGS ÷ Revenue) × 100SaaS cost of revenue

Track COGS % over time: if it climbs while you grow, an infrastructure or support cost is scaling faster than revenue, which is exactly the leak a driver-based model catches early. See SaaS unit economics for how COGS flows into margin, LTV, and payback.

Why COGS Matters

  • Drives gross profit: revenue − COGS = gross profit. A rising COGS quietly erodes margin.
  • Signals efficiency: climbing COGS as a % of revenue points to rising input costs or production waste.
  • Shapes pricing: you can't price sustainably without knowing your unit cost.
  • Affects taxes: COGS is deductible, so accurate tracking lowers taxable income legitimately.

Cost of Goods Sold FAQ

How do you calculate COGS?

Use COGS = Beginning Inventory + Purchases − Ending Inventory. Add the inventory you started with to what you bought during the period, then subtract the inventory left at the end. The result is the cost of the goods you actually sold.

Is COGS the same as operating expenses?

No. COGS is the direct cost of producing what you sold. Operating expenses (OpEx) are the indirect costs of running the business, marketing, admin, rent. Both sit on the income statement, but COGS comes first (used to find gross profit) and OpEx comes after.

Where does COGS appear on the income statement?

Directly below total revenue. Revenue − COGS = gross profit, which is the starting point for the rest of the profit and loss statement.

Does COGS include shipping?

Inbound freight (getting materials to you) is part of COGS. Outbound shipping to customers is usually a selling expense recorded under operating expenses, not COGS.

What is included in SaaS COGS?

SaaS COGS (cost of revenue) covers the direct cost of delivering the service: cloud hosting and infrastructure, third-party software and APIs used in the product, payment processing fees, customer support and success salaries, DevOps and site-reliability labor, and professional services like onboarding. Sales, marketing, R&D, and G&A are excluded, they are operating expenses.

What is a good SaaS gross margin?

Per Benchmarkit's 2025 data, the median total SaaS gross margin is around 77%, with top-quartile subscription margins above 80%, so COGS of about 20-25% of revenue is healthy. Below 70% total usually points to a structural cost issue worth investigating.

Adlega - Know your runway. SaaS financial modeling.