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.
Result
- 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
Step-by-step
- FIFO matches sold shares to the oldest lots first.
- Matched: 100 sh @ $10.00 + 50 sh @ $20.00.
- 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 soldFIFO 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
- Inputs:
- shares=100,100; prices=10,20; sell=150
- Output:
- FIFO $2,000 ยท LIFO $2,500 ยท Avg $2,250
- Inputs:
- shares=100,100; prices=10,20; sell=50, method=avg
- Output:
- $15 ร 50 = $750
- 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.