Skip to content
MoneyDeck

Cost Basis Calculator

Cost basis and capital gain by FIFO, LIFO, HIFO or average cost

Updated · Free, no signup

One lot per line in the order you bought them, e.g. "100, 50" or "100, 50, 4.95" to include a commission.

$
$

Cost basis of shares sold

$6,300.00

Realized gain (loss)

$900.00

Net sale proceeds

$7,200.00

Basis per share sold

$52.50

Average cost of all shares

$48.50

Shares remaining

180

Basis of remaining shares

$8,250.00

  • HIFO gives the smallest gain ($450.00), $450.00 less than FIFO.

Realized gain by method

Method comparison

MethodBasis soldGain (loss)Remaining basis
FIFO$6,300$900.00$8,250
LIFO$5,040$2,160$9,510
HIFO$6,750$450.00$7,800
Average cost$5,820$1,380$8,730

About the Cost Basis Calculator

When you buy the same stock or fund at different times and prices, the cost basis of the shares you sell depends on which lots you are treated as selling. This cost basis calculator takes your purchase lots, the number of shares you are selling and the sale price, and works out the basis, the realized gain or loss and the basis left in the shares you keep under four methods: first in, first out (FIFO), last in, first out (LIFO), highest cost first (HIFO) and average cost.

Use it before placing a sale to choose the lot selection that fits your tax plan — HIFO usually minimizes the gain today, while FIFO often realizes older, long-term lots — or to check the figures on a broker’s 1099-B. The comparison table shows all four methods side by side.

In the US, FIFO is the default for stocks unless you specifically identify shares with your broker at the time of sale; LIFO and HIFO are forms of specific identification, and the average cost method is allowed only for mutual fund and dividend reinvestment plan shares. Commissions per lot are added to that lot’s cost, and sale commissions reduce proceeds. Holding periods (short vs long term) are not determined here.

With the default inputs, the cost basis of shares sold is $6,300.00. Change any value above to recalculate instantly.

How to use the cost basis calculator

  1. 1List each purchase on its own line, oldest first, as shares and price (add the commission as a third number if you paid one).
  2. 2Enter how many shares you are selling and the sale price per share.
  3. 3Add any sale commission.
  4. 4Pick a lot selection method, then compare all four in the table.
  5. 5Tell your broker which lots to sell before the trade settles if you want specific identification.

Formula and method

Basis sold = Σ (shares taken from each lot × lot cost per share); Gain = shares × sale price − fees − basis; Average cost = total cost ÷ total shares

Each lot’s cost per share is its price plus any commission spread over its shares. FIFO takes shares from the oldest lots first, LIFO from the newest, and HIFO from the most expensive lots first, until the number of shares sold is reached; the basis is the sum of the shares taken times each lot’s cost per share.

The average cost method divides the total cost of all shares by the total number of shares and applies that single figure to every share sold. Net proceeds are shares sold × sale price minus sale fees, and the realized gain is proceeds minus basis. The remaining basis is the total cost of all lots minus the basis sold.

Basis sold
Total cost attributed to the shares you sell
Lot cost per share
Purchase price + lot fees ÷ lot shares
Gain
Net proceeds − basis sold

Worked examples

Three lots, selling 120 shares at $60 (FIFO)

FIFO sells all 100 shares bought at $50 and 20 of the $65 shares: $5,000 + $1,300 = $6,300 of basis. Proceeds are $7,200, so the gain is $900. The 180 shares you keep carry $8,250 of basis.

Same lots with HIFO

HIFO sells the 50 most expensive shares ($65) first, then 70 at $50: $3,250 + $3,500 = $6,750. The realized gain drops to $450, half of the FIFO result, though the shares you keep have a lower basis of $7,800.

Average cost with fees on a mutual fund

The 43 shares cost $11,130 in total, an average of $258.84 each. Selling 25 at that average gives $6,470.93 of basis. Proceeds after the $10 fee are $8,740, for a gain of $2,269.07.

Frequently asked questions

What is cost basis?+

Cost basis is what you paid for an investment, including commissions and fees, adjusted for events like reinvested dividends, return of capital or wash sales. Your taxable gain or loss is the sale proceeds minus the basis of the shares sold.

What is the difference between FIFO, LIFO and HIFO?+

FIFO sells your oldest shares first, LIFO your newest, and HIFO your highest-cost shares first. With rising prices, FIFO usually produces the largest gain and HIFO the smallest, but FIFO lots are more likely to qualify as long-term.

Which cost basis method does the IRS use by default?+

For stocks, the default is FIFO unless you specifically identify the shares you sell with your broker at the time of the trade. Mutual funds and DRIP shares may use average cost if you elect it; your broker reports the method used on Form 1099-B.

Can I use average cost for individual stocks?+

In the US, generally no — the average cost method is limited to shares of regulated investment companies (mutual funds) and shares in dividend reinvestment plans. For individual stocks you must use FIFO or specific identification of lots.

Do reinvested dividends count as a new lot?+

Yes. Each dividend reinvestment buys shares at that day’s price and creates a new lot with its own basis and holding period. Forgetting them causes double taxation because the dividends were already taxed when paid.

Is HIFO always the best choice?+

HIFO minimizes the gain realized now, but it may sell short-term lots taxed at ordinary rates and leaves low-basis shares for later. Compare the after-tax result, considering which lots are held more than one year.

Tax results are estimates based on published rules and simplified assumptions. They are not tax advice — check official guidance or a tax professional for your situation.

Related tools