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
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.
Frequently asked
What is cost basis?+
What is the difference between FIFO, LIFO, and average cost?+
Which method does the IRS use by default?+
Why does the method matter for taxes?+
Does this calculate my capital gains tax?+
What about wash sales and reinvested dividends?+
Related calculators
More tools you might like
Hand-picked tools that pair well with this one — same audience, same intent.
Compute the future value under continuous compounding (A = Pe^rt) and compare it with daily, monthly, and annual compounding.
Project the future value of a present sum at a nominal growth rate, then adjust for inflation to show its real, inflation-adjusted value.
Project the growth of an investment when dividends are automatically reinvested, compared with taking dividends as cash.
Sales tax + total for a purchase amount in any US state using the 2026 state-level base rate. State rates only (no county / city add-ons).
Simple dividend yield = annual dividend ÷ share price × 100. Quarterly payout breakdown and forward-yield comparisons.
Outcome of investing a fixed amount monthly over time.