# What is my FIFO cost of goods sold?

Computes cost of goods sold and ending inventory by FIFO, LIFO and weighted average from your beginning inventory and purchases, by the periodic method, with gross margin when you add sales.

- Page: https://www.acalculator.org/finance/fifo-calculator
- JSON spec: https://www.acalculator.org/finance/fifo-calculator.json
- Version: eb67be414b9d

## Default answer

Example with the default inputs (Inventory layers, oldest first [Units 150, Cost per unit $21.00; Units 225, Cost per unit $27.00; Units 210, Cost per unit $33.00], Units sold 300, Sales revenue $11,340.00): Selling 300 units costs $7,200.00 by FIFO, $9,360.00 by LIFO and $8,284.62 at the weighted average.

## Inputs

| Key | Label | Description |
| --- | --- | --- |
| layers | Inventory layers, oldest first | Beginning inventory, then each purchase in date order: the units and the cost per unit. |
| sold | Units sold | Units sold in the period. |
| sales | Sales revenue | Optional: what the units sold brought in, for the gross margin. |

## Outputs

| Key | Label | Description |
| --- | --- | --- |
| fifoCogs | Cost of goods sold (FIFO) | The cost of the oldest units: the units sold taken from the first layers. |
| fifoEnding | Ending inventory (FIFO) | Cost of goods available − FIFO cost of goods sold: the newest units. |
| lifoCogs | Cost of goods sold (LIFO) | The cost of the newest units: the units sold taken from the last layers. |
| lifoEnding | Ending inventory (LIFO) | Cost of goods available − LIFO cost of goods sold: the oldest units. |
| avgCogs | Cost of goods sold (weighted average) | Units sold × weighted average cost per unit. |
| avgEnding | Ending inventory (weighted average) | Units left × weighted average cost per unit. |
| avgCost | Weighted average cost per unit | Cost of goods available ÷ units available. |
| available | Cost of goods available | Σ units × cost per unit over every layer. |
| units | Units available | Σ units over every layer. |
| left | Units left | Units available − units sold. |
| fifoMargin | Gross margin (FIFO) | Sales revenue − FIFO cost of goods sold. Shown when you enter the sales revenue. |
| lifoMargin | Gross margin (LIFO) | Sales revenue − LIFO cost of goods sold. Shown when you enter the sales revenue. |
| avgMargin | Gross margin (weighted average) | Sales revenue − weighted average cost of goods sold. Shown when you enter the sales revenue. |

## Method

Cost of goods available = Σ units × cost. FIFO cost of goods sold = the units sold taken from the oldest layers first; LIFO = from the newest layers first; weighted average = units sold × (cost of goods available ÷ units available). Ending inventory = cost of goods available − cost of goods sold. Gross margin = sales − cost of goods sold.

## Assumptions

- The periodic method: every purchase of the period is counted before the units sold are costed. FIFO gives the same result under the perpetual method; LIFO and the weighted (moving) average can differ.
- Layers are listed oldest first, starting with the beginning inventory.
- Arithmetic is exact on the typed decimals, with no rounding of the average cost per unit; money shows to the cent, halves up.

## Worked examples

1. layers = {"units":150,"cost":21} or {"units":225,"cost":27}, sold = 300, sales = $11,340.00 gives fifoCogs = $7,200.00, fifoEnding = $8,955.00, lifoCogs = $9,360.00, lifoEnding = $6,795.00, available = $16,155.00, units = 585, left = 285, fifoMargin = $4,140.00, lifoMargin = $1,980.00, avgCost = $27.6154, avgCogs = $8,284.62, avgEnding = $7,870.38, avgMargin = $3,055.38. Source: OpenStax, Principles of Financial Accounting, 10.2 Calculate the Cost of Goods Sold and Ending Inventory Using the Periodic Method (Spy Who Loves You Corporation: 150 units at $21, 225 at $27, 210 at $33; 300 units sold for $11,340; FIFO cost of goods sold $7,200, ending inventory $8,955, gross margin $4,140; LIFO $9,360, $6,795, $1,980). https://openstax.org/books/principles-financial-accounting/pages/10-2-calculate-the-cost-of-goods-sold-and-ending-inventory-using-the-periodic-method.
2. layers = {"units":100,"cost":10} or {"units":100,"cost":12}, sold = 150 gives fifoCogs = $1,600.00, fifoEnding = $600.00, lifoCogs = $1,700.00, lifoEnding = $500.00, avgCogs = $1,650.00, avgCost = $11.0000. Source: OpenStax, Principles of Financial Accounting, 10.2 Calculate the Cost of Goods Sold and Ending Inventory Using the Periodic Method (Spy Who Loves You Corporation: 150 units at $21, 225 at $27, 210 at $33; 300 units sold for $11,340; FIFO cost of goods sold $7,200, ending inventory $8,955, gross margin $4,140; LIFO $9,360, $6,795, $1,980). https://openstax.org/books/principles-financial-accounting/pages/10-2-calculate-the-cost-of-goods-sold-and-ending-inventory-using-the-periodic-method (the periodic method).
3. layers = {"units":40,"cost":2.5} or {"units":60,"cost":3.1}, sold = 0 gives fifoCogs = $0.00, fifoEnding = $458.50, lifoCogs = $0.00, lifoEnding = $458.50, avgEnding = $458.50, left = 150. Source: OpenStax, Principles of Financial Accounting, 10.2 Calculate the Cost of Goods Sold and Ending Inventory Using the Periodic Method (Spy Who Loves You Corporation: 150 units at $21, 225 at $27, 210 at $33; 300 units sold for $11,340; FIFO cost of goods sold $7,200, ending inventory $8,955, gross margin $4,140; LIFO $9,360, $6,795, $1,980). https://openstax.org/books/principles-financial-accounting/pages/10-2-calculate-the-cost-of-goods-sold-and-ending-inventory-using-the-periodic-method.

## FAQ

### What is FIFO?

FIFO, first in, first out, is an inventory costing method that assumes the oldest units are sold first. Cost of goods sold carries the oldest costs, and ending inventory carries the newest ones.

### How do I calculate cost of goods sold with FIFO?

Take the units sold from your oldest layer first, then the next, and add up their costs. Spy Who Loves You Corporation sold 300 units from 150 at $21 and 225 at $27 (then 210 at $33): 150 × 21 + 150 × 27 = 3,150 + 4,050 = $7,200.

### How do I calculate ending inventory with FIFO?

Subtract FIFO cost of goods sold from the cost of all goods available, or cost the units left at the newest prices. Spy had $16,155 of goods available, so its FIFO ending inventory was 16,155 − 7,200 = $8,955: 210 units at $33 and 75 at $27.

### How is LIFO different?

LIFO, last in, first out, takes the units sold from the newest layer first. For Spy: 210 × 33 + 90 × 27 = 6,930 + 2,430 = $9,360 of cost of goods sold, leaving $6,795 in ending inventory.

### How does the weighted average method work?

Divide the cost of goods available by the units available, then multiply by the units sold. Spy: 16,155 ÷ 585 = $27.6154 a unit, and 300 × 27.6154 = $8,284.62. OpenStax rounds the unit cost to $27.62 first and shows $8,283; this calculator keeps the exact unit cost.

### Which method gives the highest profit?

When costs are rising, FIFO matches the cheapest units against sales, so it gives the lowest cost of goods sold and the highest gross margin; LIFO gives the opposite. With $11,340 of sales, Spy’s gross margin was $4,140 by FIFO and $1,980 by LIFO.

### Does it matter if I use the periodic or the perpetual method?

Not for FIFO: the oldest units go first either way, so the result is the same. LIFO and the average cost can differ, because the perpetual method costs each sale with only the purchases made before it. This calculator uses the periodic method, counting all the purchases of the period first.

## Sources

- OpenStax, Principles of Financial Accounting, 10.2 Calculate the Cost of Goods Sold and Ending Inventory Using the Periodic Method: the Spy Who Loves You Corporation example (beginning inventory 150 units at $21, purchases of 225 at $27 and 210 at $33, 300 units sold for $11,340; goods available $16,155; FIFO cost of goods sold $7,200, ending inventory $8,955, gross margin $4,140; LIFO $9,360, $6,795, $1,980; weighted average with the unit cost rounded to $27.62: $8,283, $7,872, $3,057). https://openstax.org/books/principles-financial-accounting/pages/10-2-calculate-the-cost-of-goods-sold-and-ending-inventory-using-the-periodic-method (retrieved 2026-10-19)
