acalculator

What is my cost basis?

List each purchase with its shares, price and fees, then the shares you sell and the sale price. The cost basis calculator gives your total cost basis, the average cost per share, and the basis and gain of the sale by first in, first out and by average cost.

Your numbers

Purchases
Row 1
Row 2
Row 3
Total cost basis
$10,010.00

Your cost basis is $10,010.00 for 200 shares, $50.0500 a share.

Shares bought
200
Average cost per share
$50.0500
Basis of the shares sold (FIFO)
$6,207.00
Basis of the shares sold (average cost)
$6,006.00
Basis of the shares kept (FIFO)
$3,803.00
Sale proceeds
$8,400.00
Gain or loss (FIFO)
$2,193.00
Gain or loss (average cost)
$2,394.00

Total cost basis: $10,010.00. Your cost basis is $10,010.00 for 200 shares, $50.0500 a share.

The results are estimates for information only. They are not financial, tax, or legal advice. Check the numbers with your lender or a qualified professional before you decide. Terms of use

How to calculate

Works out the cost basis of shares bought in several lots with commissions, the average cost per share, and the basis and gain of shares you sell by first in, first out or by average cost.

Example with the default inputs (Purchases [Shares 100, Price per share $50.00, Fees $5.00; Shares 50, Price per share $60.00, Fees $5.00; Shares 50, Price per share $40.00, Fees $0.00], Shares sold 120, Sale price per share $70.00): Your cost basis is $10,010.00 for 200 shares, $50.0500 a share.

Method: basis = Σ(shares × price + fees); average = basis ÷ shares; FIFO basis sold = whole oldest lots, then (shares taken ÷ lot shares) × lot cost; average basis sold = shares sold × average; gain = shares sold × sale price − sale fees − basis sold.

  • The purchases are listed oldest first. FIFO takes shares from the top of the list.
  • A lot’s fees are part of its cost, so a share of a lot carries its share of the fees.
  • Stock splits, reinvested dividends, wash sales and gifted or inherited shares need other adjustments and are not included.
  • Your broker reports your basis on Form 1099-B; this is an estimate, not tax advice.

Machine-readable copies: Markdown, JSON.

Worked examples

Each example is checked against the calculator on every build.

  1. Purchases 100 50 5; 50 60 5; 50 40 0, Shares sold 120, Sale price per share $70.00 gives Total cost basis $10,010.00, Shares bought 200, Average cost per share $50.05, Basis of the shares sold (FIFO) $6,207.00, Basis of the shares sold (average cost) $6,006.00, Basis of the shares kept (FIFO) $3,803.00, Sale proceeds $8,400.00, Gain or loss (FIFO) $2,193.00, Gain or loss (average cost) $2,394.00.Source: Internal Revenue Service, Topic no. 703, Basis of assets (the basis of stock you buy is the purchase price plus commissions and recording or transfer fees), https://www.irs.gov/taxtopics/tc703 (retrieved 2026-10-03); Internal Revenue Service, Publication 550, Investment Income and Expenses (shares not adequately identified: the basis of the shares acquired first; average basis for mutual fund and dividend reinvestment plan shares), https://www.irs.gov/publications/p550 (retrieved 2026-10-03)
  2. Purchases 10 33.33; 20 41.1 gives Total cost basis $1,155.30, Shares bought 30, Average cost per share $38.51.Source: Internal Revenue Service, Topic no. 703, Basis of assets (the basis of stock you buy is the purchase price plus commissions and recording or transfer fees), https://www.irs.gov/taxtopics/tc703 (retrieved 2026-10-03)
  3. Purchases 40 25 4.95; 60 20 4.95, Shares sold 100, Sale price per share $18.00, Fees on the sale $4.95 gives Total cost basis $2,209.90, Basis of the shares sold (FIFO) $2,209.90, Basis of the shares sold (average cost) $2,209.90, Basis of the shares kept (FIFO) $0.00, Sale proceeds $1,795.05, Gain or loss (FIFO) -$414.85.Source: Internal Revenue Service, Publication 550, Investment Income and Expenses (shares not adequately identified: the basis of the shares acquired first; average basis for mutual fund and dividend reinvestment plan shares), https://www.irs.gov/publications/p550 (retrieved 2026-10-03)

How it works

Every typed number is used as the exact decimal you typed; results are rounded only for display. For each purchase k (in the order listed, oldest first) with sₖ shares at price pₖ and fees fₖ (empty fees count as $0), its cost is cₖ = sₖ × pₖ + fₖ.

  • Total cost basis B = Σ cₖ; shares bought S = Σ sₖ, which must be more than 0.
  • Average cost per share = B ÷ S.

When shares sold n is more than 0 (it must not be more than S):

  • Basis of the shares sold (FIFO): go down the list; from each lot take t = the smaller of what is still to sell and sₖ, and add cₖ × t ÷ sₖ. A lot with 0 shares is skipped.
  • Basis of the shares sold (average cost) = n × B ÷ S.
  • Basis of the shares kept (FIFO) = B − the FIFO basis sold.

When a sale price P is typed too (sale fees F, empty counts as $0):

  • Sale proceeds = n × P − F.
  • Gain or loss = proceeds − the basis sold, by each method.

Rules

  • 1 to 20 purchases; shares from 0 to 10⁹ and prices from $0 to $10⁷ each; fees from $0 to $10⁹.

Assumptions

  • Purchases are listed oldest first. Splits, reinvested dividends, wash sales, gifts and inheritances are not included. This is an estimate, not tax advice.

Worked examples by hand

The default. Costs: 100 × 50 + 5 = 5,005; 50 × 60 + 5 = 3,005; 50 × 40 + 0 = 2,000. B = $10,010, S = 200, average = $50.05. Selling 120: FIFO = 5,005 + 3,005 × 20 ÷ 50 = 5,005 + 1,202 = $6,207; kept = $3,803; average = 120 × 50.05 = $6,006. Proceeds = 120 × 70 = $8,400; gain = $2,193 (FIFO) or $2,394 (average).

Two purchases, no fees. 10 × 33.33 = 333.30 and 20 × 41.10 = 822. B = $1,155.30, S = 30, average = $38.51.

All sold at a loss. Costs 40 × 25 + 4.95 = 1,004.95 and 60 × 20 + 4.95 = 1,204.95; B = $2,209.90. Selling all 100 gives the same basis both ways. Proceeds = 100 × 18 − 4.95 = $1,795.05; loss = −$414.85.

Other questions people ask

What is cost basis?

For stock you buy, the IRS says your basis is the purchase price plus costs such as commissions and recording or transfer fees. Your gain or loss when you sell is the sale proceeds minus that basis.

How do I calculate cost basis with several purchases?

Add shares × price plus fees for each purchase. 100 shares at $50 with a $5 fee, 50 at $60 with $5 and 50 at $40 give $5,005 + $3,005 + $2,000 = $10,010 for 200 shares, an average of $50.05 a share.

What is FIFO cost basis?

First in, first out: the shares you sell come from your oldest purchases first. The IRS uses it when you cannot adequately identify which shares you sold. Selling 120 of the shares above takes all 100 from the first lot ($5,005) and 20 from the second (20 ÷ 50 × $3,005 = $1,202), a basis of $6,207.

When can I use average cost basis?

IRS Publication 550 lets you choose the average basis method for mutual fund shares and shares in a dividend reinvestment plan. For other stock the basis follows the shares you identify, or FIFO.

Do fees count in the cost basis?

Yes. Purchase commissions and fees add to the basis, and fees on the sale reduce the proceeds, so both lower your taxable gain.

What does the calculator leave out?

Stock splits, reinvested dividends, return-of-capital payments, wash sale adjustments, and shares you inherited or were given all change the basis in other ways. Check the basis your broker reports on Form 1099-B.