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

Cost basis of 150 shares (FIFO)
$2,000.00
$13.33/share
  • Total shares owned200
  • Total cost of all lots$3,000.00
  • Shares sold150
  • Lots used100 sh @ $10.00 + 50 sh @ $20.00
  • Cost basis$2,000.00
  • Average basis per share$13.33
Not financial advice โ€” For tax purposes the IRS default for stocks is FIFO unless you specify otherwise; mutual funds may use average cost. This tool computes basis only โ€” not gain/loss, wash sales, or holding-period (short vs long-term) treatment.

Step-by-step

  1. FIFO matches sold shares to the oldest lots first.
  2. Matched: 100 sh @ $10.00 + 50 sh @ $20.00.
  3. Cost basis of the 150 shares sold = $2,000.00 ($13.33/share).

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

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.

Related calculators

More tools you might like