# What is my cost basis?

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.

- Page: https://www.acalculator.org/finance/cost-basis-calculator
- JSON spec: https://www.acalculator.org/finance/cost-basis-calculator.json
- Version: 46e6311da261

## Default answer

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.

## Inputs

| Key | Label | Description |
| --- | --- | --- |
| lots | Purchases | Each purchase in the order you bought: the shares, the price per share, and the fees paid. |
| sold | Shares sold | Optional: how many of the shares you sell. |
| sale | Sale price per share | Optional: the price you sell each share at, for the gain or loss. |
| salefee | Fees on the sale | Commissions and fees for the whole sale. |

## Outputs

| Key | Label | Description |
| --- | --- | --- |
| basis | Total cost basis | Σ(shares × price + fees) over every purchase. |
| shares | Shares bought | All the shares bought, added up. |
| average | Average cost per share | The total cost basis ÷ the shares bought. |
| fifo | Basis of the shares sold (FIFO) | The basis of the shares sold, taken from the oldest purchases first. |
| avgSold | Basis of the shares sold (average cost) | Shares sold × the average cost per share. |
| left | Basis of the shares kept (FIFO) | The total cost basis minus the FIFO basis of the shares sold. |
| proceeds | Sale proceeds | Shares sold × sale price − fees on the sale. |
| gainFifo | Gain or loss (FIFO) | Sale proceeds − the FIFO basis of the shares sold. Negative for a loss. |
| gainAvg | Gain or loss (average cost) | Sale proceeds − the average-cost basis of the shares sold. |

## 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.

## Assumptions

- 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.

## Worked examples

1. lots = {"shares":100,"price":50,"fee":5} or {"shares":50,"price":60,"fee":5}, sold = 120, sale = $70.00 gives basis = $10,010.00, shares = 200, average = $50.05, fifo = $6,207.00, avgSold = $6,006.00, left = $3,803.00, proceeds = $8,400.00, gainFifo = $2,193.00, gainAvg = $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. lots = {"shares":10,"price":33.33} or {"shares":20,"price":41.1} gives basis = $1,155.30, shares = 30, average = $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. lots = {"shares":40,"price":25,"fee":4.95} or {"shares":60,"price":20,"fee":4.95}, sold = 100, sale = $18.00, salefee = $4.95 gives basis = $2,209.90, fifo = $2,209.90, avgSold = $2,209.90, left = $0.00, proceeds = $1,795.05, gainFifo = -$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).

## FAQ

### 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.

## Sources

- Internal Revenue Service, Topic no. 703, Basis of assets. https://www.irs.gov/taxtopics/tc703 (retrieved 2026-10-03)
- Internal Revenue Service, Publication 550, Investment Income and Expenses: identifying stock sold, and the average basis method for mutual fund and dividend reinvestment plan shares. https://www.irs.gov/publications/p550 (retrieved 2026-10-03)
