Stock Cost Basis Calculator (FIFO, LIFO, Average)

Compute the cost basis of shares sold from multiple purchase lots using FIFO, LIFO, or average-cost methods.

Inputs

Shares bought in each lot, oldest first, comma-separated.

Purchase price for each lot, same order and count as shares.

Number of shares being sold.

How to match sold shares to purchase lots.

Result

Loading calculator…

How to use this calculator

  • Enter share counts for each purchase lot, oldest first.
  • Enter the matching purchase price for each lot, in the same order.
  • Enter how many shares you are selling and pick a method.
  • Read the cost basis and which lots were matched.

About this calculator

When you sell shares you bought at different times and prices, the cost basis — the amount you are treated as having paid — depends on which shares are considered sold, and that choice affects your taxable gain. This calculator computes the cost basis under the three standard methods. FIFO (first in, first out) assumes you sell your oldest shares first; it is the IRS default for stocks. LIFO (last in, first out) sells your most recent shares first. Average cost blends all lots into a single per-share price, common for mutual funds. Enter your purchase lots as matching lists of share counts and prices, the number of shares you are selling, and the method, and the tool shows which lots are used and the resulting basis. Choosing the method with the higher basis lowers your taxable gain.

How it works — the formula

FIFO: match sold shares to oldest lots first LIFO: match to newest lots first Average: basis = (total cost ÷ total shares) × shares sold

FIFO and LIFO consume specific lots in order; average cost blends every lot into one per-share figure before multiplying by the quantity sold.

Worked examples

Example 1
Lots 100@$10, 100@$20; sell 150
Inputs:
shares=100,100; prices=10,20; sell=150
Output:
FIFO $2,000 · LIFO $2,500 · Avg $2,250
Example 2
Avg method, sell 50 of above
Inputs:
shares=100,100; prices=10,20; sell=50, method=avg
Output:
$15 × 50 = $750
Example 3
FIFO, sell 100 of above
Inputs:
shares=100,100; prices=10,20; sell=100, method=fifo
Output:
$1,000 (the $10 lot)

Limitations

  • Computes cost basis only — not gain, tax, or holding period.
  • Ignores commissions, wash sales, and reinvested-dividend lots.
  • Specific-lot identification beyond FIFO/LIFO/average is not supported.

Not tax advice; confirm basis and method with your broker and a tax professional.

Frequently asked

What is cost basis?+
Cost basis is the amount you are treated as having paid for the shares you sell, including the purchase price (and commissions). Your taxable capital gain or loss is the sale proceeds minus the cost basis.
What is the difference between FIFO, LIFO, and average cost?+
FIFO sells your oldest shares first, LIFO sells your newest first, and average cost uses the blended average price of all your shares. The methods can produce very different cost bases — and therefore different taxable gains — when prices have moved.
Which method does the IRS use by default?+
For individual stocks, the IRS default is FIFO unless you specifically identify other shares at the time of sale. Mutual funds commonly default to average cost. Always confirm with your broker and a tax professional.
Why does the method matter for taxes?+
A higher cost basis means a smaller taxable gain (or larger loss). In a rising market, FIFO uses your cheapest old shares, producing a larger gain, while LIFO or specific-lot selection of higher-cost shares can reduce the gain.
Does this calculate my capital gains tax?+
No — it computes cost basis only. To find your gain, subtract the basis from your sale proceeds. The tax then depends on your holding period (short- vs long-term) and your tax bracket, which this tool does not model.
What about wash sales and reinvested dividends?+
They affect basis but are not handled here. Wash-sale rules can disallow losses and adjust basis, and reinvested dividends add new lots. For a complete tax picture, use your broker's records and consult a tax advisor.

Related calculators

More tools you might like

Hand-picked tools that pair well with this one — same audience, same intent.