Tax & Trade Admin

FIFO vs LIFO vs HIFO Calculator

Compare the cost basis and gain of a sale matched first in first out, last in first out, highest cost first and at average cost, for any asset bought in lots.

Purchases (lots)

Proceeds from the sale: $675.00

MethodCost BasisGain or LossAverage Cost of Units Left
FIFO10 @ $20.00 + 5 @ $35.00$375.00$300.00$41.43
LIFO6 @ $30.00 + 8 @ $50.00 + 1 @ $35.00$615.00$60.00$24.29
HIFO8 @ $50.00 + 5 @ $35.00 + 2 @ $30.00$635.00$40.00$22.86
Average costAll 29 units at $32.9310$493.97$181.03$32.93

Which method you may use is set by your country's tax rules, and some countries prescribe one (for example a pooled average, or matching rules for buys shortly before or after a sale). This shows the arithmetic only; fees are left out.

How the FIFO vs LIFO vs HIFO calculator works

When you sell part of a holding bought at different prices, the cost of the units sold depends on which purchases (lots) the sale is matched with. The calculator matches one sale four ways: oldest lots first (FIFO), newest first (LIFO), highest cost first (HIFO), and at the average cost of everything held. It shows the cost basis and the gain or loss for each, and the average cost of what is left.

Gain or loss = proceeds - cost basis of the units sold
Proceeds = units sold x sale price
FIFO / LIFO / HIFO: cost basis = sum of (units taken from each lot x that lot's price), taking lots oldest first / newest first / highest price first
Average cost: cost basis = units sold x (total cost of all lots / total units)
FIFO, LIFO, HIFO and average cost: bars showing which purchase lots FIFO, LIFO and HIFO match with a sale of fifteen units, and the average-cost basis, against the sale proceeds
Bars showing which purchase lots FIFO, LIFO and HIFO match with a sale of fifteen units, and the average-cost basis, against the sale proceeds

Worked example

Four purchases: 10 units at $20, 5 at $35, 8 at $50 and 6 at $30 (in that order, 29 units costing $955), then a sale of 15 units at $45, for proceeds of $675.

  1. FIFO takes 10 @ $20.00 + 5 @ $35.00: cost $375.00, gain $300.00.
  2. LIFO takes 6 @ $30.00 + 8 @ $50.00 + 1 @ $35.00: cost $615.00, gain $60.00.
  3. HIFO takes 8 @ $50.00 + 5 @ $35.00 + 2 @ $30.00: cost $635.00, gain $40.00.
  4. Average cost: $955 / 29 = $32.9310 a unit; 15 units cost $493.97, gain $181.03.
  5. The 14 units left have an average cost of $41.43 after FIFO but $22.86 after HIFO: the gain HIFO avoids now is still there when they are sold.

The same sale shows a gain of $300 under FIFO, $181.03 at average cost, $60 under LIFO and $40 under HIFO.

Frequently asked questions

What do FIFO, LIFO and HIFO mean?

First in, first out matches a sale with your oldest purchases; last in, first out with your newest; highest in, first out with the most expensive. Average cost ignores individual lots and uses the average price of everything you hold.

Which method am I allowed to use?

That depends on where you pay tax, and many countries prescribe one. For example, the UK pools holdings at an average cost with special rules for buys within 30 days of a sale, Canada uses an average adjusted cost base, and the US allows specific identification of lots when records support it, otherwise first in, first out. Check your own country's rules or ask a tax adviser.

Does HIFO always save tax?

It gives the smallest gain on this sale, but it leaves the cheapest lots for later, so it mainly delays tax rather than removing it. Where lots held longer are taxed at a lower rate, the holding period can matter more than the price.

Are fees included?

No. Where your tax rules allow, buying fees usually add to a lot's cost and selling fees reduce the proceeds; add them to the prices you enter to include them.

More tools in the Hub

Premium opens the Hub's Analytics section: market data, research, radars, screeners, macro, calculators and backtesting. The website and the Discord stay free.