Cost Basis Calculator
List your purchases and the shares you sold to get their cost basis and your gain or loss, by FIFO or average cost.
Free, no sign-upRuns in your browserHow we calculate
Enter purchases oldest first, including reinvested dividends as their own buys.
- Gain
- $2,795.00
- Basis per share sold
- $21.7083
- Shares left
- 30
- Basis of shares left
- $900.00
- Total basis (all shares)
- $3,505.00
- Gain with average cost
- $2,596.00
How this was calculated
- FIFO basis (oldest shares first): 100 × $20.05 + 20 × $30 = $2,605.
- Proceeds: 120 × $45 = $5,400.
- Gain: $5,400 − $2,605 = $2,795.
| Shares | Basis per share | Basis |
|---|---|---|
| 100 | $20.05 | $2,005.00 |
| 20 | $30.00 | $600.00 |
Educational, not tax advice. Your broker's Form 1099-B is the record the IRS sees; wash sales, splits and gifted or inherited shares change the basis.
What the cost basis calculator does
Cost basis is what you paid for an investment, commissions and fees included. When you sell, your capital gain or loss is the proceeds (shares × sale price − selling fees) minus the basis of the shares you sold. This cost basis calculator keeps each purchase as a separate lot and works out which shares left the account, either first in, first out (FIFO) or at the average cost of all shares.
Worked example: FIFO vs average cost
You bought 100 shares at $20 plus a $5 commission ($2,005) and later 50 shares at $30 ($1,500). You sell 120 shares at $45 for $5,400. Under FIFO the first 100 shares carry $2,005 of basis and the next 20 come from the second lot at $30, so the basis is $2,005 + $600 = $2,605 and the gain $2,795. Under average cost every share is worth $3,505 ÷ 150 = $23.37, so 120 shares carry $2,804 and the gain is $2,596. Same trade, $199 less gain, simply because of the method. The 30 shares you keep carry the rest of the basis: $900 under FIFO.
Which method applies to you
For individual stocks the IRS default is FIFO: unless you name specific lots when you sell (specific identification, set up with your broker), the oldest shares go first. In a rising market that sells the cheapest shares and produces the largest gain. Mutual fund shares and shares bought through a dividend reinvestment plan may use the average-cost method instead, which many fund companies apply by default. Once you use average cost for a fund, you generally keep using it for that fund. Shares held more than a year produce long-term gains, taxed at lower rates; under FIFO the oldest shares are also the ones most likely to qualify.
What changes the basis
Reinvested dividends are new purchases and add to basis; leave them out and you pay tax twice on the same money. A stock split changes the share count and the per-share basis but not the total. Wash sales (buying back within 30 days of selling at a loss) add the disallowed loss to the new shares. Gifted shares usually keep the giver's basis, while inherited shares take the value on the date of death. Your broker reports basis for shares bought since 2011 (2012 for funds) on Form 1099-B; check it against your own records.
Sources
IRS Publication 551 (Basis of Assets), IRS Publication 550 (Investment Income and Expenses: identifying shares, average basis, wash sales), 26 CFR 1.1012-1 (FIFO default and average basis for regulated investment company shares), IRS Form 8949 and 1099-B instructions.
Frequently asked questions
What is cost basis?
Cost basis is what you paid for an investment, including commissions and fees. Your taxable gain is the sale proceeds minus selling fees minus the basis of the shares you sold.
How do you calculate cost basis for shares bought at different prices?
Each purchase is a separate lot with its own basis. Under FIFO the shares you sell come from the oldest lots first; under average cost every share has the same basis, total cost ÷ total shares.
Which method does the IRS use?
For stocks the default is first in, first out (FIFO) unless you tell your broker which lots to sell. Mutual fund and dividend-reinvestment shares may use average cost (IRS Publication 550).
Do reinvested dividends add to cost basis?
Yes. Reinvested dividends were taxed when paid, so each reinvestment is a new purchase at that day's price. Leaving them out overstates your gain.
What if my broker does not show the cost basis?
Brokers must report basis on Form 1099-B for shares bought since 2011 (2012 for funds). For older shares, rebuild it from trade confirmations or statements, or historical prices on the purchase dates.