Cost Basis Calculator
Find your average cost per share from several purchases, and the gain or loss when you sell using FIFO or average cost.
Average cost per share
$27.7107
- Total shares
- 225
- Total cost, with fees
- $6,234.90
- Amount received from the sale
- $4,195.05
- Gain or loss, FIFO
- $1,038.12
- Gain or loss, average cost
- $869.77
Your 225 shares cost $27.71 each on average, counting fees.
Calculation breakdown
| Step | Formula | Result |
|---|---|---|
| Average cost per share | $6,234.90 ÷ 225 shares | $27.7107 |
| Basis of the shares sold, FIFO | The first 120 shares bought, in order, with their fees | $3,156.93 |
| Gain or loss, FIFO | $4,195.05 − $3,156.93 | $1,038.12 |
How it works
List each purchase on its own line as shares, price and an optional fee. Add a sale to see the gain or loss.
Worked example
Three purchases: 100 shares at $25.00 with a $4.95 fee, 50 at $32.50 with a $4.95 fee, and 75 at $28.00:
- Total cost: 2,504.95 + 1,629.95 + 2,100.00 = $6,234.90 for 225 shares
- Average cost: 6,234.90 ÷ 225 = $27.71 a share
- Selling 120 shares at $35 with a $4.95 fee gives 4,195.05 received; the FIFO basis is $3,156.93, so the FIFO gain is about $1,038.12
Sources
Frequently asked questions
What is cost basis?
Cost basis is generally what you paid for an investment, the purchase price plus costs of purchase such as commissions. It is the starting point for working out your gain or loss when you sell.
How do you calculate average cost per share?
Add up everything you paid for all your purchases, fees included, and divide by the total shares. 100 shares at $25, 50 at $32.50 and 75 at $28, with two $4.95 fees, cost $6,234.90 for 225 shares, or $27.71 a share.
What is FIFO?
First-in first-out treats the earliest shares you bought as the first ones sold. The IRS says that if you cannot identify which shares you sold, FIFO is used. The calculator takes whole lots in order and part of the last one.
How is gain or loss worked out?
Subtract the basis of the shares sold from the amount you received, which is the sale price minus selling expenses. A positive number is a gain and a negative number is a loss.
Do the two methods give the same answer?
Usually not, when your purchase prices differ. Which methods you may use depends on the type of investment, and on whether you identify the shares sold, so check IRS guidance or ask a tax professional.
For information only, not tax advice. Rules differ for mutual funds, reinvested dividends, wash sales and inherited shares, which this calculator does not handle.