COGS calculator
Open with 20,000 of stock, buy 80,000, close with 15,000, and your cost of goods sold is 85,000. Enter the opening inventory, net purchases and closing count of any period to get COGS at month or year end. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Beginning inventory
- 20,000
- Purchases
- 80,000
- Ending inventory
- 15,000
- Goods available
- 100,000
- Cogs
- 85,000
Cost of goods sold, almost always abbreviated COGS on an income statement, is the inventory cost of merchandise a business actually sold during a period. The periodic identity is beginning inventory plus purchases minus ending inventory. Bookkeepers, merchandisers, and accounting students use that three-term formula at every close. This COGS calculator accepts those three finite amounts, returns cost of goods sold, and rejects a negative beginning or ending inventory so the identity never consumes an impossible stock figure.
What COGS measures and the periodic inventory identity
Cost of goods sold is the cost attached to the units that left inventory because a customer bought them, not the cost of the units still on the shelf. In a periodic merchandising system you do not track every sale against a perpetual stock card; you reconstruct sold cost at period end with a three-line identity: beginning inventory, plus net purchases during the period, minus ending inventory counted or valued at close. That identity is the definition this calculator implements.
Beginning inventory is the merchandise asset that opened the books. Purchases are the net cost of goods brought in during the window—invoice cost of merchandise acquired for resale. Ending inventory is the merchandise still unsold when the period closes.
Subtracting that leftover stock from goods available for sale (beginning plus purchases) isolates the slice that was sold, which is COGS. A shop that opened with twenty thousand, bought eighty thousand, and closed with fifteen thousand has cost of goods sold of eighty-five thousand, because twenty plus eighty minus fifteen is eighty-five. Zero opening stock is allowed: a new reseller can have beginning inventory of zero and still compute COGS from purchases and the count at close.
Zero purchases is allowed when the period only sold from existing stock. A negative beginning or ending inventory is not a stock figure; it is a data error, and this calculator rejects it instead of inventing a sold-cost number from an impossible shelf. Keep the three inputs in the same currency and the same period.
Mixing a year of purchases with a month-end count is how a COGS figure quietly lies. The formula is deliberately three arithmetic steps so homework keys, LMS oracles, and close notebooks share one reproducible definition without spreadsheet rounding drift on intermediate cells.
Where a COGS calculator earns its keep
People who type cogs into a search box already know the acronym and want the sold-cost figure, not a lecture that starts from perpetual versus periodic inventory systems. A publisher ranking for that short query is serving merchandisers who have an opening count, a purchases total, and a closing count, students who must fill the cost-of-goods-sold section of an income statement, and bookkeepers who need a deterministic oracle that rejects a negative inventory value instead of silently producing a nonsense expense.
Small retailers building a month-end notebook want the same beginning-plus-purchases-minus-ending figure analysts write on slides, without hand errors when currency decimals change. Failed validation does not consume balance. Pair this capability with a separate gross-profit or inventory-turnover tool when you need those identities; keep this surface focused on the merchandise cost that people mean when they search cogs.
What you can do with it
Month-end merchandising close
Enter opening stock, net purchases, and the closing count to publish COGS for the period without rebuilding the identity in a spreadsheet.
FAQ
How do I calculate COGS?
Cost of goods sold equals beginning inventory plus purchases minus ending inventory. Example: 20000 + 80000 − 15000 = 85000.
Can beginning inventory or purchases be zero?
Yes. A new shop may open with zero stock, and a period may have no purchases. Only negative inventory (or negative purchases) is rejected.
Does this use FIFO, LIFO, or freight-in?
No. The calculator applies the periodic identity only. Fold freight-in, returns, and layer costing into the three inputs before you call.
What are goods available for sale?
Beginning inventory plus purchases, meaning everything you could have sold during the period. In the example that is 100,000. Cost of goods sold is the part of it that left the shelf, so subtracting the closing stock isolates it.
Why must all three figures cover the same period?
Because COGS only works when opening stock, purchases and the closing count describe one window in one currency. Mixing a full year of purchases with a month-end count produces a figure that looks right but is wrong.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/fin/cogs \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"beginning_inventory":20000,"purchases":80000,"ending_inventory":15000}'const res = await fetch("https://api.kit.forhosting.com/fin/cogs", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"beginning_inventory": 20000,
"purchases": 80000,
"ending_inventory": 15000
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/fin/cogs",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"beginning_inventory": 20000,
"purchases": 80000,
"ending_inventory": 15000
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/fin/cogs", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"beginning_inventory":20000,"purchases":80000,"ending_inventory":15000}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"beginning_inventory":20000,"purchases":80000,"ending_inventory":15000}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/fin/cogs", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"beginning_inventory": 20000,
"purchases": 80000,
"ending_inventory": 15000
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "fin.cogs",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
Successful calls are billed at $0.002; invalid input is not charged.
Input contract, response shape, and validation
A negative purchases amount is likewise rejected. Example: beginning inventory twenty thousand, purchases eighty thousand, and ending inventory fifteen thousand yield goods available one hundred thousand and cost of goods sold eighty-five thousand. Prefer bare numbers over formatted strings; currency marks, thousands separators, and trailing unit labels are not parsed. POST a JSON body with three required finite numbers in the same currency and the same reporting window. beginning_inventory is merchandise on hand at the start of the period and must be greater than or equal to zero; aliases beginning, begin_inventory, opening_inventory, opening, and bi are accepted so a ledger export does not need a rename step. purchases is net merchandise bought during the window and must also be non-negative; aliases net_purchases, merchandise_purchases, and p are accepted. ending_inventory is merchandise still on hand at close and must be non-negative; aliases ending, end_inventory, closing_inventory, closing, and ei are accepted. Each field may arrive as a JSON number or as a numeric string that matches a strict finite decimal pattern. Missing fields, empty strings, non-finite values, or any negative inventory value fail with invalid_input naming the field and are not billed. On success the body echoes rounded beginning_inventory, purchases, and ending_inventory, returns goods_available as beginning plus purchases, returns cogs as goods available minus ending inventory, and includes a formula string restating the identity so a dashboard can print the definition next to the number. This endpoint does not take freight-in, purchase returns, or allowances as separate lines, and it does not allocate FIFO or LIFO layers; fold those adjustments into purchases or the inventory values before you call. Pricing for a successful item is a flat $0.002.
Where a COGS calculator earns its keep
Classroom and certification courses that teach the periodic inventory method need an endpoint that returns COGS and goods available and nothing else, so a grader can compare against a textbook key without this tool pretending to run a full general ledger. Keep requests small, pin the rounded cogs and goods_available in tests, and you get reproducible cost of goods sold for homework, exam generators, and lightweight close notebooks without standing up a full inventory subledger.
Integration use cases
Homework and income-statement oracles
Students compute COGS = beginning + purchases − ending by hand and compare against a deterministic result that rejects a negative inventory value as invalid_input.
Gross-profit prep without taking sales
Compute cost of goods sold first, then subtract it from net sales in your own notebook; this endpoint returns COGS only.
Technical questions
What happens if an inventory value is negative?
The task fails with invalid_input. A negative beginning or ending inventory is not a stock figure, so the request is rejected and is not billed.
What does the COGS calculator cost?
The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid input is not billed.