Cost of goods sold — always shortened to COGS — is the direct cost of whatever you sold during a period. It is the single most important number on a profit-and-loss statement after revenue, because it sits right on the line between sales and profit. This calculator takes four familiar inventory figures — beginning inventory, purchases, ending inventory, and revenue — and instantly gives you your COGS, gross profit, and gross margin percentage. No spreadsheet required.
Type your numbers into the boxes below and every result updates the moment you finish typing. You can experiment with different inventory counts, supplier purchase totals, and revenue forecasts to see how each change moves your gross margin.
How to Use
- Enter Beginning Inventory — the cost of the unsold goods you had on hand at the start of the period. This is exactly the ending inventory figure from last period.
- Enter Purchases During the Period — the total cost of all inventory you bought (or manufactured) between the start and end of the period. Include freight and handling that is part of getting the goods ready to sell.
- Enter Ending Inventory — the cost of the unsold goods physically counted at the end of the period. This should come from an actual count, not a guess.
- Enter Revenue — total sales for the same period. Revenue is what you charged customers, not the profit.
- Read the result card: Total Goods Available is what you could have sold; COGS is what you actually consumed; Gross Profit is revenue minus COGS; Gross Margin expresses that profit as a percentage of revenue.
- If the ending inventory figure changes after a surprise stock count, re-enter it to see how a smaller ending inventory raises COGS and lowers your margin.
The COGS Formula
The cost of goods sold identity is one of the oldest and most reliable equations in accounting, used identically by Investopedia, Xero, QuickBooks, and the IRS in Publication 538:
COGS = Beginning Inventory + Purchases − Ending Inventory
The logic is simple. Whatever goods you started with plus whatever you bought during the period equals everything you had available to sell. Whatever you did not sell at period-end is still inventory on the balance sheet. The difference — the goods that left your building — is the cost of what you sold.
Where:
- Beginning Inventory is last period's ending inventory at cost.
- Purchases are the cost of new inventory acquired in the period.
- Ending Inventory is the cost of unsold goods remaining at period-end.
From COGS, gross profit and gross margin follow directly:
Gross Profit = Revenue − COGS Gross Margin = (Gross Profit / Revenue) × 100
Worked example: a retailer starts the year with $20,000 of inventory, buys $50,000 more, and ends with $15,000 on the shelf. COGS is $20,000 + $50,000 − $15,000 = $55,000. On revenue of $120,000, gross profit is $65,000 and the gross margin is 65,000 / 120,000 × 100 = 54.17% — meaning roughly 54 cents of every sales dollar is left after paying for the goods themselves.
If revenue is zero or negative, the gross margin cannot be computed (there is no sales base to divide by), which is why the calculator requires a positive revenue figure. If any inventory figure is negative, the calculator flags it rather than returning a meaningless result.
What Counts as COGS — and What Does Not
COGS includes only costs directly tied to the products you sold:
- The wholesale cost of merchandise for resellers.
- Raw materials and direct factory labor for manufacturers.
- Freight-in and packaging required to get goods ready for sale.
COGS explicitly excludes operating overhead:
- Rent, utilities, and office salaries.
- Marketing, advertising, and sales commissions.
- Equipment depreciation not tied to production.
- Shipping to customers (often booked as a separate fulfillment expense).
Mixing overhead into COGS is a common bookkeeping mistake that distorts your true gross margin. Keep overhead below the gross-profit line as operating expenses.
Examples
Example 1 — A retail boutique. A shop starts a quarter with $20,000 of inventory, buys $50,000 of new stock, and counts $15,000 left at quarter-end. COGS is $55,000. On $120,000 of sales, gross profit is $65,000 and gross margin is 54.17%. The owner now knows that a 20% off sale that cuts revenue to $96,000 (with the same COGS) pushes gross margin down to roughly 42.7% — a much sharper drop than the discount headline suggests.
Example 2 — A manufacturer at scale. A factory carries $500,000 of beginning inventory, buys and produces $2,000,000 of goods during the year, and ends with $300,000 on hand. COGS is $500,000 + $2,000,000 − $300,000 = $2,200,000. On revenue of $4,000,000, gross profit is $1,800,000 and gross margin is 45.0%. On seven-figure statements, even a one-percentage-point margin shift is worth tens of thousands of dollars, so the calculator keeps the numbers precise at scale.
Example 3 — A loss-making product line. A business with $80,000 beginning inventory, $120,000 of purchases, and $40,000 ending inventory sold $160,000 worth of goods. COGS is $160,000. Against revenue of only $150,000, gross profit is −$10,000 and gross margin is −6.67% — the company is losing money on every unit before overhead even starts. This is the signal to reprice, switch suppliers, or drop the line.
FAQ
How do I calculate cost of goods sold?
Add your beginning inventory to the purchases you made during the period, then subtract the ending inventory. The formula is COGS = Beginning Inventory + Purchases − Ending Inventory. For example, $20,000 beginning + $50,000 purchases − $15,000 ending = $55,000 COGS. This calculator performs that subtraction the moment you enter all four figures.
What is the difference between COGS and operating expenses?
COGS are the direct costs of the goods you actually sold — materials, wholesale purchases, and direct labor. Operating expenses (also called SG&A) are overhead not tied to specific products: rent, marketing, office salaries, and utilities. COGS is subtracted from revenue to arrive at gross profit; operating expenses are subtracted later to arrive at operating profit.
How do I find beginning and ending inventory?
Beginning inventory is simply last period's ending inventory carried forward. Ending inventory is the cost of unsold goods counted at period-end, usually from a physical stocktake multiplied by your unit cost (using FIFO, LIFO, or weighted-average costing consistently from one period to the next).
What is a good gross margin for a small business?
A "good" margin depends on the industry. Grocery and discount retail run on thin gross margins of 2–5%, while software, luxury goods, and consulting often enjoy 60–80%. As a rule of thumb, a gross margin above 30% is comfortable for many product businesses, above 50% is strong, and below 15% leaves little room for overhead. Compare yourself against competitors in your own sector.
Does COGS include shipping to customers?
Usually no. The cost to receive inventory (freight-in) is part of COGS, but shipping finished goods to customers is normally treated as a fulfillment or operating expense. Check your accounting policy and apply it consistently, because mixing the two distorts period-to-period margin comparisons.
What does a negative gross margin mean?
A negative gross margin means your cost of goods sold is higher than your revenue — you are paying more to source or make the product than customers are willing to pay. It usually signals underpricing, an inflated supplier quote, or a product line that should be repriced or discontinued. Entering a negative inventory or zero revenue figure in this calculator returns an error rather than a misleading result.
Disclaimer
This COGS calculator is provided for informational purposes only and does not constitute financial, accounting, tax, or legal advice. Results are based solely on the inventory and revenue figures you enter and use the standard COGS identity; actual reported COGS depends on your chosen inventory costing method (FIFO, LIFO, or weighted average), accounting policies, and tax jurisdiction. Figures are approximations. Always confirm your cost of goods sold and gross margin with a qualified accountant before making pricing, tax, or investment decisions.