Cost Basis Calculator (FIFO/LIFO)

Calculate stock cost basis using FIFO, LIFO, specific ID, or average cost. Compare tax impact of each method.

By Konstantin Iakovlev · Updated September 2026 · Source: IRS Publication 550 (2025), Investment Income and Expenses

Purchase Lots
$
$
$
$
$
Cost Basis Method

Sale Proceeds

$6,000.00

Cost Basis (FIFO)

$4,008.00

Gain/Loss

$1,992.00

Method Comparison

FIFOGain: $1,992.00
LIFOGain: $1,388.00
Specific ID (Highest Cost)Gain: $1,388.00
Average CostGain: $1,690.00

Tax Impact (Estimated)

FIFOSTCG: $0.00 | LTCG: $1,992.00
LIFOSTCG: $0.00 | LTCG: $1,388.00
AVERAGESTCG: $1,690.00 | LTCG: $0.00
SPECIFICSTCG: $0.00 | LTCG: $1,388.00

Recommendation

Best Method for Tax SavingsLIFO
NoteSpecific ID requires broker notification before sale

Use the Cost Basis Calculator (FIFO/LIFO) above to calculate your results. Enter your values and see instant results — all calculations run in your browser.

Disclaimer: This calculator is for informational purposes only and does not constitute tax, financial, or legal advice. Results are estimates based on the information you provide and current rates. Always consult a qualified tax professional or financial advisor for advice specific to your situation.

How It Works

When you sell a stock, your taxable gain or loss is the difference between the sale price and your cost basis, which makes pinning down that basis one of the most consequential numbers on your return. It can move your tax bill meaningfully: gains on shares held more than a year are taxed at 0%, 15% or 20% depending on taxable income, while shorter-term gains are taxed as ordinary income. Get the basis right and you avoid handing the IRS more than you owe.

Four methods are available here, and each one points at a different set of purchase lots. FIFO (First-In, First-Out) treats your oldest shares as the first sold; LIFO (Last-In, First-Out) does the opposite and sells the newest first; Specific Identification lets you name the exact shares going out the door (the calculator models it by selling the highest-cost lots first, the choice with the smallest gain); and Average Cost blends every lot into a single weighted figure, a method the IRS allows only for mutual fund shares and shares held in a dividend reinvestment plan. Whichever you pick decides which purchase prices attach to the sale, and therefore the size of your reported gain or loss.

If you never track basis yourself, your broker typically defaults to FIFO, which is not always the most tax-efficient choice. With a position that has appreciated sharply, Specific Identification lets you unload your highest-cost shares first and hold your gain down. One more rule to respect: wash sale provisions can disallow a loss if you buy back a substantially identical security within 30 days before or after the sale that produced it.

Example: Comparing Methods on Two Lots

  1. 1 Input (the calculator's defaults): Lot 1 bought 2022-01-15, 50 shares at $100 with a $10 fee; Lot 2 bought 2023-06-01, 30 shares at $120 with a $10 fee. You sell 40 shares at $150, so proceeds are $6,000. The calculator dates the sale March 1, 2026 when it sorts gains into short- and long-term, so both lots are long-term.
  2. 2 FIFO: all 40 shares come from Lot 1. Basis = 40 × $100 + $8 (40/50 of the $10 fee) = $4,008, so the gain is $6,000 − $4,008 = $1,992.
  3. 3 LIFO and Specific ID both take Lot 2 first (the newest lot, and the costliest at $120.33 a share with its fee): 30 × $120 + $10 = $3,610, plus 10 shares of Lot 1 at 10 × $100 + $2 of fee = $1,002. Basis $4,612, gain $1,388. Average cost: ($5,010 + $3,610) / 80 = $107.75 a share, basis 40 × $107.75 = $4,310, gain $1,690.
  4. 4 Tax: at the 15% long-term rate the calculator assumes for its comparison, FIFO's gain costs $298.80 and LIFO's or Specific ID's $208.20, so the calculator recommends LIFO, $90.60 cheaper than FIFO. Tell your broker which lots you are selling before the trade; otherwise FIFO applies.

Source: IRS Publication 550 (2025), Investment Income and Expenses · Last updated: September 2026

Frequently Asked Questions

What is the difference between FIFO and LIFO for cost basis?
FIFO (First In, First Out) sells your oldest shares first, often resulting in higher gains if the stock has risen over time. LIFO (Last In, First Out) sells the newest shares, which may show smaller gains if recent purchases were at higher prices.
Which cost basis method (FIFO or specific ID) saves the most on taxes?
Your cost basis determines your capital gain or loss when you sell. A higher cost basis means lower gains and less tax. The method you choose (FIFO, LIFO, specific identification, or average cost) can significantly impact your tax bill.
What is the cost basis of inherited stock?
Inherited stock gets a stepped-up cost basis to the fair market value on the date of the decedent death. This means unrealized gains during the decedent lifetime are effectively tax-free for the heir.