Cost Basis Calculator

Last Updated: June 24, 2026

Calculate the cost basis of your stock or fund purchases, find your average cost per share, and figure the capital gain or loss on a sale.

Cost Basis Calculator

Pick a mode and the form will show only the inputs that mode needs.

Required: shares purchased and price per share.

Added to your total cost basis.

Required: one purchase per line, written as shares, price (commission optional as a third value).

Each line is one buy or reinvested dividend. Example: 50, 27.10, 4.95 means 50 shares at $27.10 with a $4.95 fee. Separate values with a comma or space.

Required: shares sold, cost basis per share, and sale price per share.

Not sure of your cost basis per share? Use the “Average cost basis” mode first.

Cost Basis Formula

The cost basis is the total amount you paid to acquire an investment, including any commissions or fees. The calculator uses one of three formulas depending on what you want to find.

For a single purchase:

Cost Basis = (Shares * Price Per Share) + Fees

For an average cost basis across multiple buys:

Average Cost Per Share = Total Cost Basis / Total Shares

For a capital gain or loss on a sale:

Gain or Loss = (Shares Sold * Sale Price - Sale Fees) - (Shares Sold * Cost Basis Per Share)
  • Cost Basis is the total dollar amount invested, fees included.
  • Shares is the number of shares bought or sold.
  • Price Per Share is the amount paid for each share at purchase.
  • Fees are any commissions or transaction charges added to your basis.
  • Total Shares is the sum of all shares across every purchase.
  • Cost Basis Per Share is the total basis divided by the shares you own.
  • Sale Price is the amount you receive per share when you sell.
  • Gain or Loss is the sale proceeds minus the basis of the shares sold.

The single mode adds fees to the purchase total and divides by shares to give a per share basis. The average mode totals the dollars spent and shares acquired across every buy, which is how dividend reinvestment and dollar cost averaging are handled. The sale mode subtracts the basis of the shares sold from the net proceeds to report a capital gain or loss and whether it is short or long term.

Typical Fees and Holding Periods

Fees raise your cost basis, which lowers a future taxable gain. Your holding period decides the tax treatment of that gain.

ItemTypical RangeEffect on Basis
Online stock commission$0 to $7 per tradeAdded to basis
Mutual fund load0% to 5.75%Added to basis
Reinvested dividendVariesAdds shares and basis
Holding PeriodDefinitionTax Treatment
Short termHeld 1 year or lessTaxed as ordinary income
Long termHeld more than 1 yearTaxed at lower capital gains rates

Example Problems

Example 1. You buy 100 shares at $25 per share and pay a $5 commission. The cost basis is (100 * 25) + 5 = $2,505. The cost basis per share is 2,505 / 100 = $25.05.

Example 2. You own those 100 shares with a basis of $25.05 per share and later sell all of them at $40 per share with a $5 sale fee. Net proceeds are (100 * 40) - 5 = $3,995. The basis sold is 100 * 25.05 = $2,505. The capital gain is 3,995 - 2,505 = $1,490.

Frequently Asked Questions

What is cost basis? Cost basis is the total amount you paid to acquire an investment, including the purchase price and any commissions or fees. You subtract it from your sale proceeds to find your taxable capital gain or loss.

How do commissions and fees affect cost basis? Fees paid to buy a security are added to your cost basis, and fees paid to sell reduce your proceeds. Both raise your basis or lower your proceeds, which reduces the taxable gain on a sale.

How is average cost basis calculated for multiple purchases? Add up the total dollars spent across every purchase, including fees, then divide by the total number of shares you own. The result is your average cost per share, which is the method commonly used for mutual funds and dividend reinvestment plans.

Cost Basis Calculator