1. Calculators
  2. Taxes, Inflation & Currency

Stock Cost Basis & Realized Gain Calculator

Enter every purchase of a stock or fund and the sale you made. The calculator matches the shares sold to your lots, shows the cost basis and realized gain split into short-term and long-term, and compares all four cost basis methods side by side.

Updated Oct 16, 2026Free · no sign-upFormulas tested

Your inputs

Enter every purchase of the same stock or fund, then the sale. Dates as YYYY-MM-DD; fees in dollars per trade.

Purchase lots
Date (YYYY-MM-DD)Shares sharesPrice per shareFee
$
$
$
$
$
$
$
$
Reinvested dividends are purchases too: add each one as a lot. Adjust shares and price for any stock split.
Sale
Date (YYYY-MM-DD)Shares sold sharesSale price per shareFee
$
$
One sale at a time. For a later sale, first reduce the lots by the shares already sold.
Cost basis method
%
Your ordinary income tax bracket (plus state rate if you like). Used for the tax estimate only.
%
Usually 0%, 15% or 20% federally.

Results

Realized gain$2,130.00FIFO: 150 shares sold for $9,265.00 after fees
Short-term gain
$0.00
Lots held one year or less
Long-term gain
$2,130.00
Lots held more than one year
Cost basis of shares sold
$7,135.00
Purchase price plus purchase fees
Proceeds after sale fee
$9,265.00
Estimated tax on the sale
$319.50
At 24% short-term and 15% long-term
Shares remaining
120
Basis of remaining shares
$6,670.00
$55.58 per share

Using first in, first out, the sale realizes a gain of $2,130.00: $0.00 short-term and $2,130.00 long-term. HIFO would lower the estimated tax to $152.

Short-term and long-term gain by method

Short-termLong-term
$0$500$1K$1.5K$2K$2.5KFIFOLIFOHIFOAverage cost

Lots matched to the sale (FIFO)

LotBoughtShares soldCost per shareBasisProceedsGainDays heldTerm
12023-02-14100$42.0500$4,205.00$6,176.67$1,971.671,336Long-term
22024-06-0350$58.6000$2,930.00$3,088.33$158.33861Long-term
Total150$7,135.00$9,265.00$2,130.00

Compare the four methods

The same sale, matched four ways. The tax estimate nets short-term and long-term results and uses your two rates.

MethodBasis soldGainShort-termLong-termEstimated 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

Shares you still hold

Each remaining lot keeps its own purchase date and cost.

LotBoughtSharesCost per shareBasis
32025-12-0880$51.3125$4,105.00
42026-03-0540$64.1250$2,565.00
Total120$6,670.00

Results are estimates from the numbers you enter. They are not financial, tax or legal advice.

How to use the cost basis calculator

  1. 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.
  2. 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.
  3. Choose a method. FIFO, LIFO, HIFO or average cost. The comparison table always shows all four, so you can switch and see what changes.
  4. 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

Cost per share of a lot = Price + Purchase fee ÷ Shares
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.
Average cost per share = Total cost of all lots (with fees) ÷ Total sharesWith average cost, the basis of the remaining shares stays at the same per-share figure after the sale.

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.

Frequently asked questions

What is cost basis?
Cost basis is what you paid for an investment, including commissions and fees, adjusted for events such as stock splits, reinvested dividends and return-of-capital distributions. When you sell, your taxable gain or loss is the sale proceeds minus the cost basis of the shares sold.
Which cost basis method is best?
No method is best in every case. HIFO usually gives the smallest gain on a sale, because it sells the most expensive shares first, but it can turn a long-term gain into a short-term one. FIFO often sells the oldest, cheapest shares, which gives a larger gain that is more likely to be long-term. In the example, the estimated tax ranges from $151.65 with HIFO to $319.50 with FIFO.
What cost basis method does my broker use by default?
For stocks, US brokers generally use FIFO unless you choose another method, and for mutual funds many use average cost. You can usually change the default in your account settings, or pick specific lots when you place a sell order. The choice has to be made by the time the trade settles; it cannot be changed after the fact.
Can I use average cost for individual stocks?
Generally no. In the US, the average cost method is allowed for shares of mutual funds and for stock bought through a dividend reinvestment plan. For individual stocks held outside such a plan, the basis must come from specific lots, using FIFO or lots you identify.
How do reinvested dividends affect cost basis?
Each reinvested dividend buys new shares, and that dividend amount becomes the cost basis of those shares. Because you already paid tax on the dividend, forgetting to add it to your basis means paying tax on the same money twice when you sell. Enter each reinvestment as its own purchase lot.

Related calculators

All calculators →

Check the numbers for real companies

All stocks →

This calculator is for education and planning. It uses the formulas described above and the inputs you provide; real results depend on fees, taxes, timing and other details that a general tool cannot know. PromtFinance does not give personal financial advice. Check important decisions with your provider or a qualified professional.