Stock cost basis calculator
Enter the lots you bought and the shares you sold. The calculator shows the cost basis and the taxable gain under FIFO, average cost, and specific-lot — and which of those a stock sale is actually allowed to use.
Your purchase lots (oldest first)
Taxable gain, lowest method (specific-lot)
—
Enter your lots and a sale above.
How the math works
Cost basis is what you paid for the shares, commissions included. The gain the IRS taxes is the sale proceeds minus that basis. The only hard part is deciding which shares you sold when you bought the same stock at different prices, and that choice is the whole point of this tool.
Each method picks the basis differently. FIFO draws from your oldest lots first. The average-cost method divides your total dollars paid by your total shares and uses that single per-share figure. Specific identification lets you name the exact lots to sell — and the gain-minimizing version of it sells your highest-cost shares first.
The sale price and the number of shares are identical across all three. Only the basis moves, so the method you pick sets the gain and therefore the tax.
Worked example
Take an investor who bought the same stock in three lots: 100 shares at $40, then 100 at $55, then 100 at $70. That's 300 shares for $16,500 — an average of $55 a share. They now sell 100 shares at $90, for $9,000 in proceeds.
The basis of those 100 shares depends entirely on the method:
- FIFO: the oldest lot, 100 at $40 — basis $4,000, gain $5,000.
- Average cost: 100 at $55 — basis $5,500, gain $3,500.
- Specific-lot, highest cost first: the newest lot, 100 at $70 — basis $7,000, gain $2,000.
Same stock, same sale, three different gains. The spread between FIFO and the specific-lot choice is $3,000 of reported gain. At the 2024 single-filer long-term capital gains rate of 15%, that's a $450 difference in tax — $750 if you let FIFO run, $300 if you picked the high-cost lot.
When this calculator is wrong
The biggest trap isn't the arithmetic — it's that two of these three methods may not be available to you, and the one most calculators default to showing is the one you often don't want.
- Average cost is off the table for individual stock. The IRS only permits the average-cost method for mutual fund shares and shares bought through a dividend reinvestment plan. For individual stock, your choices are FIFO or specific identification — full stop. A calculator that averages your stock lots and hands you one number is computing a figure you can't legally report.
- You have to elect specific-lot before the trade settles. You can't reconstruct it at tax time. The broker's default is FIFO, so unless you identify the lots at or before the sale and get written confirmation, FIFO is what lands on your
1099-B— the higher gain in the example above. - It ignores the wash-sale rule. If you sell at a loss and buy the same security back within 30 days on either side, the loss is disallowed and rolled into the basis of the replacement shares. The calculator treats each sale in isolation and won't flag that.
- It doesn't know your holding period. Shares held a year or less are taxed as a short-term gain at your ordinary rate, not the long-term rate used above. Selling the highest-cost lot to shrink the gain can backfire if that lot is the short-term one.
And the method that minimizes this year's gain isn't always the right call. Selling the highest-cost lots now leaves you holding the cheapest shares — the largest unrealized gains — for later. That defers tax rather than erasing it. The exception is when you expect to be in a lower bracket later, or you're harvesting around a specific threshold; then pulling the gain forward or back has a real point.
What to do with the result
If the gap between the FIFO gain and the specific-lot gain is more than a token amount, log in to your brokerage before you place the sell order and set the lot-selection method on the account — or name the specific lots on the order ticket. Do it at the trade, not in April. Once the sale settles under FIFO, that's the basis you're reporting, and the $450 in the example is gone.
If the shares are in a mutual fund or a DRIP, average cost is allowed and is usually the least-effort choice, but check whether your fund is already using it as the default and whether you've ever sold from the account before — switching methods after a prior sale has its own rules.
Common questions
- What is cost basis?
- It's the amount you paid for an investment, including commissions and fees, used to measure the taxable gain or loss when you sell. Sale proceeds minus cost basis is the gain. A higher basis means a smaller gain and less tax.
- Which cost basis method is best for stocks?
- There's no single best method, but for a sale at a gain, specific identification using your highest-cost lots reports the smallest gain this year. FIFO, the default, reports your oldest and often cheapest shares first, which usually produces the largest gain. Average cost isn't an option for individual stock.
- Can I use the average cost method for individual stocks?
- No. The IRS allows average cost only for mutual fund shares and shares in a dividend reinvestment plan. For individual stock you must use FIFO or specific identification.
- What happens if I don't choose a method?
- Your broker applies its default, which is almost always FIFO, and reports that basis on your Form 1099-B. To use specific lots you have to identify them at or before the sale and get written confirmation from the broker.
- Does the wash-sale rule change my cost basis?
- Yes. If you sell at a loss and buy the same or a substantially identical security within 30 days before or after, the loss is disallowed and added to the basis of the replacement shares. This calculator doesn't account for wash sales.