{
  "id": "fifo",
  "version": "eb67be414b9d",
  "status": "published",
  "name": "FIFO Calculator",
  "question": "What is my FIFO cost of goods sold?",
  "summary": "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.",
  "category": "finance",
  "subcategory": "business",
  "url": "https://www.acalculator.org/finance/fifo-calculator",
  "markdown": "https://www.acalculator.org/finance/fifo-calculator.md",
  "kind": "function",
  "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."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "layers": {
        "title": "Inventory layers, oldest first",
        "description": "Beginning inventory, then each purchase in date order: the units and the cost per unit.",
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "u": {
              "title": "Units",
              "description": "Units in this layer.",
              "type": "number",
              "minimum": 0,
              "maximum": 1000000000000
            },
            "c": {
              "title": "Cost per unit",
              "description": "What each unit in this layer cost.",
              "type": "number",
              "x-unit": "USD",
              "minimum": 0,
              "maximum": 1000000000
            }
          }
        }
      },
      "sold": {
        "title": "Units sold",
        "description": "Units sold in the period.",
        "type": "number",
        "minimum": 0,
        "maximum": 20000000000000
      },
      "sales": {
        "title": "Sales revenue",
        "description": "Optional: what the units sold brought in, for the gross margin.",
        "type": "number",
        "x-unit": "USD",
        "minimum": 0,
        "maximum": 1000000000000000
      }
    }
  },
  "outputs": {
    "fifoCogs": {
      "label": "Cost of goods sold (FIFO)",
      "description": "The cost of the oldest units: the units sold taken from the first layers.",
      "format": "money"
    },
    "fifoEnding": {
      "label": "Ending inventory (FIFO)",
      "description": "Cost of goods available − FIFO cost of goods sold: the newest units.",
      "format": "money"
    },
    "lifoCogs": {
      "label": "Cost of goods sold (LIFO)",
      "description": "The cost of the newest units: the units sold taken from the last layers.",
      "format": "money"
    },
    "lifoEnding": {
      "label": "Ending inventory (LIFO)",
      "description": "Cost of goods available − LIFO cost of goods sold: the oldest units.",
      "format": "money"
    },
    "avgCogs": {
      "label": "Cost of goods sold (weighted average)",
      "description": "Units sold × weighted average cost per unit.",
      "format": "money"
    },
    "avgEnding": {
      "label": "Ending inventory (weighted average)",
      "description": "Units left × weighted average cost per unit.",
      "format": "money"
    },
    "avgCost": {
      "label": "Weighted average cost per unit",
      "description": "Cost of goods available ÷ units available.",
      "format": "money"
    },
    "available": {
      "label": "Cost of goods available",
      "description": "Σ units × cost per unit over every layer.",
      "format": "money"
    },
    "units": {
      "label": "Units available",
      "description": "Σ units over every layer.",
      "format": "number"
    },
    "left": {
      "label": "Units left",
      "description": "Units available − units sold.",
      "format": "number"
    },
    "fifoMargin": {
      "label": "Gross margin (FIFO)",
      "description": "Sales revenue − FIFO cost of goods sold. Shown when you enter the sales revenue.",
      "format": "money"
    },
    "lifoMargin": {
      "label": "Gross margin (LIFO)",
      "description": "Sales revenue − LIFO cost of goods sold. Shown when you enter the sales revenue.",
      "format": "money"
    },
    "avgMargin": {
      "label": "Gross margin (weighted average)",
      "description": "Sales revenue − weighted average cost of goods sold. Shown when you enter the sales revenue.",
      "format": "money"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "layers": [
        {
          "units": "150",
          "cost": "21"
        },
        {
          "units": "225",
          "cost": "27"
        },
        {
          "units": "210",
          "cost": "33"
        }
      ],
      "sold": 300,
      "sales": 11340
    },
    "outputs": {
      "fifoCogs": 7200,
      "fifoEnding": 8955,
      "lifoCogs": 9360,
      "lifoEnding": 6795,
      "avgCogs": 8284.615384615385,
      "avgEnding": 7870.384615384615,
      "avgCost": 27.615384615384617,
      "available": 16155,
      "units": 585,
      "left": 285,
      "fifoMargin": 4140,
      "lifoMargin": 1980,
      "avgMargin": 3055.3846153846152
    },
    "text": "Selling 300 units costs $7,200.00 by FIFO, $9,360.00 by LIFO and $8,284.62 at the weighted average."
  },
  "examples": [
    {
      "given": {
        "layers": [
          {
            "units": 150,
            "cost": 21
          },
          {
            "units": 225,
            "cost": 27
          },
          {
            "units": 210,
            "cost": 33
          }
        ],
        "sold": 300,
        "sales": 11340
      },
      "expect": {
        "fifoCogs": 7200,
        "fifoEnding": 8955,
        "lifoCogs": 9360,
        "lifoEnding": 6795,
        "available": 16155,
        "units": 585,
        "left": 285,
        "fifoMargin": 4140,
        "lifoMargin": 1980,
        "avgCost": 27.615384615384617,
        "avgCogs": 8284.615384615385,
        "avgEnding": 7870.384615384615,
        "avgMargin": 3055.3846153846152
      },
      "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; weighted average by hand calculation in content.mdx with the exact unit cost 16,155 ÷ 585 = 27.6153… (exact 359/13, Python Fraction), where OpenStax rounds it to $27.62 first ($7,872 and $8,283)"
    },
    {
      "given": {
        "layers": [
          {
            "units": 100,
            "cost": 10
          },
          {
            "units": 100,
            "cost": 12
          }
        ],
        "sold": 150
      },
      "expect": {
        "fifoCogs": 1600,
        "fifoEnding": 600,
        "lifoCogs": 1700,
        "lifoEnding": 500,
        "avgCogs": 1650,
        "avgCost": 11
      },
      "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); hand calculation in content.mdx: FIFO 100 × 10 + 50 × 12 = 1,600; LIFO 100 × 12 + 50 × 10 = 1,700; average 2,200 ÷ 200 = 11, × 150 = 1,650"
    },
    {
      "given": {
        "layers": [
          {
            "units": 40,
            "cost": 2.5
          },
          {
            "units": 60,
            "cost": 3.1
          },
          {
            "units": 50,
            "cost": 3.45
          }
        ],
        "sold": 0
      },
      "expect": {
        "fifoCogs": 0,
        "fifoEnding": 458.5,
        "lifoCogs": 0,
        "lifoEnding": 458.5,
        "avgEnding": 458.5,
        "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; hand calculation in content.mdx: 40 × 2.50 + 60 × 3.10 + 50 × 3.45 = 100 + 186 + 172.50 = 458.50"
    }
  ],
  "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)"
  ],
  "related": [
    "gross-profit",
    "inventory-turnover",
    "cost-basis",
    "gross-margin"
  ],
  "changelog": []
}
