Stock Calculator

Cost Basis Calculator

List your buys and sells, choose FIFO, LIFO, HIFO or average cost, and see the gain on every sale, the lots you still hold and their cost basis — exact to the cent.

Type a ticker or a company name. The search runs in your browser.
Settings
Buy fee
Sell fee
Decimal places
Percent
Amounts
Shares
Cost basis method

FIFO (first in, first out): each sell uses your oldest shares first.

Enter your trades to see live results:

shares at each
shares at each
shares at each
shares at each

One trade per line — shares@price, a leading minus means sell. Example: 100@50 or -40@65.

$47.6$65$80.00#1 BUY 100 @ $50.00 · Average cost basis $50.00#2 BUY 100 @ $70.00 · Average cost basis $60.00#3 BUY 100 @ $66.00 · Average cost basis $62.00#4 SELL 100 @ $80.00 · Average cost basis $68.00#1 BUY 100 @ $50.00 · Average cost basis $50.00#2 BUY 100 @ $70.00 · Average cost basis $60.00#3 BUY 100 @ $66.00 · Average cost basis $62.00#4 SELL 100 @ $80.00 · Average cost basis $68.00#1#2#3#4

Open lots

LotSharesCost per shareCost basisUnrealized P/L
#2100$70.00$7,000.00+$1,000.00
#3100$66.00$6,600.00+$1,400.00

Sells and the lots they used

SellSharesNet proceedsCost basisGain or lossLots used
#4100$8,000.00$5,000.00+$3,000.00#1 × 100

# is a trade's place in the list above. A lot is the shares left from one buy; net proceeds are after the sell fee, and cost basis includes the buy fee.

Chart and prices come from TradingView and load only when you open them. Read the price off the chart, then type it into “Share price now”.

Total P/L
Open position (shares)
Average cost basis
Cost basis of shares held
Total invested
Realized P/L
Unrealized P/L
Return on investment
Break-even price
After-tax P/L (illustrative)
Keyboard shortcuts
b / s Set the focused trade to buy / sell
Tab / Shift+Tab Next / previous field
↑ / ↓ Step a value by 1 (Shift: 10, Alt: 0.1)
Enter Copy the primary result
[ / ] Fewer / more decimal places (percent)
Esc Clear the field

How the cost basis method changes your gain

The example above buys 100 shares three times, at $50, $70 and $66, then sells 100 shares at $80. The sale brings in $8,000 whichever way you count. What it cost depends on which 100 shares left the account:

Method Shares sold Realized gain Cost basis left Average cost left Unrealized at $80 Total P/L
FIFO the $50 lot +$3,000.00 $13,600.00 $68.00 +$2,400.00 +$5,400.00
LIFO the $66 lot +$1,400.00 $12,000.00 $60.00 +$4,000.00 +$5,400.00
HIFO the $70 lot +$1,000.00 $11,600.00 $58.00 +$4,400.00 +$5,400.00
Average cost a third of the pool +$1,800.00 $12,400.00 $62.00 +$3,600.00 +$5,400.00

The last column is the point. Every method arrives at the same $5,400 total, because the same $18,600 went in and the same shares are worth the same today. The method only decides how that total is split between the gain you have already realized and the gain still sitting in your open lots. Report a smaller gain now and you keep cheaper shares, so a larger gain waits for the next sale.

Which method applies to you

That depends on where you pay tax and what your broker has on file. This page does the arithmetic; it cannot tell you which method you are allowed to use.

What this calculator leaves out

Trades are processed in the order you list them, and they carry no dates. That keeps the tool quick, and it puts three things out of reach: holding periods (short-term or long-term gains), wash-sale adjustments, and the date-based matching rules above. Stock splits, mergers and returns of capital are not modelled either; restate the affected lots yourself. Reinvested dividends are ordinary purchases — add each one as a buy.

Fees are handled the way cost basis usually treats them: a buy fee is added to the cost of the lot it opens, and a sell fee is taken off the proceeds of the sale. Set them under Settings. The tax field applies one illustrative rate to the total and knows nothing about your bracket, allowances or holding period.

Cost basis FAQ

What is cost basis?

Cost basis is what you paid for the shares you hold, including the commission on the purchase. When you sell, your gain or loss is the net proceeds of the sale minus the cost basis of the shares sold. With one purchase that is simple. With several purchases at different prices you first have to decide which shares were sold — and that is what a cost basis method does.

What is the difference between FIFO, LIFO and HIFO?

They differ in which shares a sell uses up. FIFO (first in, first out) sells your oldest shares first. LIFO (last in, first out) sells your newest shares first. HIFO (highest in, first out) sells the shares you paid the most for first, which gives the smallest gain on that sale. Average cost does not pick shares at all: every share carries the same pooled cost.

Does the cost basis method change my total profit?

No. The method decides how much of your profit counts as realized now and how much stays in the shares you still hold. Realized plus unrealized is the same under every method, and once you have sold everything the realized total is identical too. Switch the method above and watch Total P/L: it does not move.

Which cost basis method gives the lowest gain?

For a single sale, HIFO — it uses the most expensive shares, so no other choice of lots can report a smaller gain on that sale. When prices have been rising, LIFO comes close and FIFO reports the largest gain. A smaller gain today is a deferral, not a saving: the cheaper shares are still in your account, with a lower cost basis, waiting for a later sale. Real tax outcomes also depend on how long each lot was held, which this calculator does not track.

Can I use average cost for stocks in the United States?

Generally not. The IRS allows the average basis method for mutual fund shares and for certain dividend reinvestment plan shares, not for ordinary stock holdings. For stocks, the shares you acquired first count as sold first unless you identify other shares at the time of the sale. In the United Kingdom and Canada it is the reverse: shares of the same company are pooled and averaged. The average cost article covers how the pooled figure behaves.

Does this calculator handle wash sales or short-term and long-term gains?

No. Trades here have an order but no dates, so the calculator cannot tell a short-term gain from a long-term one, adjust for a wash sale, or apply the United Kingdom's same-day and 30-day matching rules. Use it to compare methods and to check the arithmetic on a broker statement; for a tax return, rely on your broker's records and the rules of your tax authority.