How to use the cost basis calculator
- Enter each purchase as a lot. Give the trade date in YYYY-MM-DD form, the number of shares, the price per share and the commission. Your broker’s trade confirmations or the “lots” view of your position have all four. Reinvested dividends are purchases too: add each as a lot.
- Enter the sale. Date, shares sold, sale price per share and the commission on the sale. The calculator handles one sale at a time; for a later sale, reduce the lots by the shares already sold.
- Choose a method. FIFO, LIFO, HIFO or average cost. The comparison table always shows all four, so you can switch and see what changes.
- Optional: your tax rates. Your ordinary income tax rate for short-term gains and your long-term rate (usually 0%, 15% or 20% federally). They are only used for the tax estimate.
The results show the realized gain, its short-term and long-term parts, the basis of the shares sold and what you still hold. The first table lists each lot matched to the sale with its holding period; the second compares the methods; the third lists your remaining lots.
How cost basis and realized gain are calculated
Basis of shares sold = Σ (Shares taken from each lot × That lot's cost per share)
Proceeds = Shares sold × Sale price − Sale fee
Realized gain = Proceeds − Basis of shares soldEach matched lot is short-term if held one year or less, and long-term if sold after the one-year anniversary of its purchase date.
The methods only change which lots are matched to the sale:
- FIFO (first in, first out): the oldest shares are sold first.
- LIFO (last in, first out): the newest shares are sold first.
- HIFO (highest in, first out): the shares with the highest cost per share are sold first. Brokers usually offer it as a form of specific identification.
- Average cost: every share carries the same basis, total cost ÷ total shares. For the holding period, the shares sold are treated as the oldest ones first. This method is mainly for mutual funds and dividend reinvestment plans.
A worked example
An investor bought shares of a fictional Company A four times, 270 shares for $13,805.00 including fees, and on 2026-10-12 sells 150 shares at $61.80 with a $5.00 commission. Proceeds after the fee are $9,265.00.
With FIFO, the sale takes the 100 shares bought in February 2023 and 50 from June 2024. Their basis is $7,135.00, so the realized gain is $2,130.00, all long-term. At a 15% long-term rate, the estimated tax is $319.50.
The investor still holds 120 shares with a basis of $6,670.00: the two most recent and most expensive lots.
Comparing the four methods
The same sale, matched four ways:
| Method | Basis of shares sold | Realized gain | Short-term | Long-term | Estimated tax |
|---|---|---|---|---|---|
| FIFO | $7,135.00 | $2,130.00 | $0.00 | $2,130.00 | $319.50 |
| LIFO | $8,428.00 | $837.00 | $742.00 | $95.00 | $192.33 |
| HIFO | $8,573.75 | $691.25 | $532.92 | $158.33 | $151.65 |
| Average cost | $7,669.44 | $1,595.56 | $0.00 | $1,595.56 | $239.33 |
Estimated tax uses 24% for short-term and 15% for long-term gains.
LIFO sells the 40 newest shares, bought at $64, at a small loss, then the December 2025 lot, which has not yet been held a year. Most of its smaller gain is short-term. HIFO picks the three most expensive lots and produces the smallest gain, $691.25, and the lowest estimated tax even though most of it is short-term. Average cost lands between FIFO and HIFO, and all of its gain is long-term because the shares deemed sold are the oldest.
The trade-off is in what you keep. HIFO leaves you holding the cheapest shares: the remaining average cost is $43.59 a share against $55.58 under FIFO. Their larger gain is still there, waiting for a future sale. A lower gain today is a deferral, not a permanent saving, unless the shares are held until a step-up in basis or sold in a lower-tax year.
When the sale is at a loss
If the price falls to $45, every method shows a loss, and the order flips: the method that gave the smallest gain now gives the largest loss. FIFO shows a result of -$390.00, while HIFO shows -$1,828.75, of which -$1,147.08 is short-term. Capital losses offset gains and up to $3,000 of ordinary income a year; the capital gains tax calculator works through the netting and the carryforward.
Watch the wash-sale rule. If you buy the same or a substantially identical security within 30 days before or after a sale at a loss, the loss is disallowed for now and added to the basis of the replacement shares. Reinvested dividends count as purchases, so an automatic reinvestment inside that window can trigger a partial wash sale.
Adjusting basis for splits and reinvested dividends
The basis you enter must be the adjusted basis, which changes after some corporate events:
- Stock splits do not change the total basis of a lot; they spread it over more shares. After a 2-for-1 split, a lot of 50 shares at $80 becomes 100 shares at $40. Enter the split-adjusted figures, and keep the original purchase date. The stock split calculator does the conversion.
- Reinvested dividends create new lots with their own date and cost. Leaving them out overstates your gain.
- Return of capital distributions reduce basis, and spin-offs split it between the old and the new shares according to the allocation the company publishes.
- Inherited shares generally take a basis equal to their value at the date of death, and gifted shares usually keep the giver’s basis.
What this calculator does not include
- Wash-sale adjustments. The calculator flags the rule on a loss but does not change any basis.
- Multiple sales. Each sale is calculated against the lots you enter; earlier sales must be removed from the lots first.
- Tax netting across the year. The tax estimate covers this sale only and gives zero on a net loss.
- Specific identification of any lot. HIFO is one rule for picking lots; you can choose any lots with your broker.
- Covered and noncovered reporting. For shares bought long ago, your broker may not report basis to the IRS, so your own records matter.
Brokers report the basis and holding period of covered shares on Form 1099-B. Use this calculator to check those figures and to see the effect of a method before you sell.