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
FIFO (first in, first out): each sell uses your oldest shares first.
Enter your trades to see live results:
One trade per line — shares@price, a leading minus means sell. Example: 100@50 or -40@65.
Open lots
| Lot | Shares | Cost per share | Cost basis | Unrealized P/L |
|---|---|---|---|---|
| #2 | 100 | $70.00 | $7,000.00 | +$1,000.00 |
| #3 | 100 | $66.00 | $6,600.00 | +$1,400.00 |
Sells and the lots they used
| Sell | Shares | Net proceeds | Cost basis | Gain or loss | Lots used |
|---|---|---|---|---|---|
| #4 | 100 | $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”.
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.
- FIFO — first in, first out. Each sell uses your oldest shares. In a stock that has risen over time those are the cheapest, so FIFO tends to show the largest gain and leave the highest cost basis behind.
- LIFO — last in, first out. Each sell uses your newest shares, the ones bought closest to today's price, so the gain is usually smaller.
- HIFO — highest in, first out. Each sell uses the shares with the highest cost per share, which gives the smallest gain (or the largest loss) that any choice of lots can produce for that sale.
- Average cost — no lots at all. Total cost is divided evenly across every share, and a sell removes shares at that average. This is the method the main stock calculator uses.
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.
- United States. For stocks, the shares you acquired first are treated as sold first unless you identify different shares at the time of the sale. Brokers therefore default to FIFO and let you choose specific lots, often through a standing instruction such as LIFO or highest cost. Averaging is generally reserved for mutual fund shares and certain dividend reinvestment plans. The rules are set out in IRS Publication 550.
- United Kingdom. You do not choose. A disposal is matched first with shares bought on the same day, then with shares bought in the following 30 days, and otherwise with your Section 104 holding, where every share carries the same average cost. Average above reproduces the Section 104 pool; the same-day and 30-day rules need dates, which this calculator does not take. See HMRC helpsheet HS284.
- Canada. Identical shares share one adjusted cost base, which is an average. Choose Average.
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.