Free cost basis calculator - compute gain or loss per lot using FIFO, LIFO, or average cost methods for stocks, ETFs, and mutual funds.
When you sell shares purchased at different times and prices, the lot-identification approach you use directly affects your taxable gain or loss. FIFO (first in, first out) sells the oldest shares first, reverse-order matching sells the newest shares first, and average cost spreads total basis evenly across all shares. Each approach can produce a different tax result.
Our Cost Basis Calculator lets you enter multiple purchase lots and a sale quantity, then compares the gain or loss under FIFO, a newest-lot comparison, and average cost. Use it to see how lot selection changes taxable results before you place a sell order. Tax-lot selection affects not just the current tax bill but also which low-basis or high-basis shares remain in the account after the trade.
Choosing the right basis method can materially change the taxable gain on a sale. Selling high-basis lots first reduces the current gain, while selling low-basis lots leaves more high-basis shares for later. This calculator makes those tradeoffs visible before you execute the order with your broker.
FIFO: sell oldest lots first. Newest-lot comparison: sell newest lots first. Average Cost: basis per share = total cost of all shares / total shares owned. Gain = (Sale Price - Cost Basis) x Shares Sold.
Result: FIFO gain: $2,250 / Newest-lot gain: $1,350 / Avg gain: $1,770
You own 100 shares in three lots. Selling 60 shares at $80: FIFO sells the 50 shares at $40 and 10 at $55 for a $2,250 gain. The newest-lot comparison sells 20 at $70, 30 at $55, and 10 at $40 for a $1,350 gain. Average cost basis is $50.50 per share, so the gain on 60 shares is $1,770. In this setup, selling the newest shares first produces the smallest gain.
The way shares are identified for sale directly affects reported gain or loss. In a portfolio built through multiple purchases, the difference between FIFO and a higher-basis share selection can materially change the tax outcome.
FIFO sells the oldest shares first. In steadily rising markets, those are often the cheapest shares and can create the largest gain. A newest-lot comparison does the opposite and shows what happens when the most recently purchased shares are used first. Average cost divides the entire portfolio cost by total shares and is mainly relevant for eligible fund holdings.
For individual stocks and ETFs, specific identification with your broker gives the most control over which lots leave the account. For mutual funds in taxable accounts, average cost is commonly available and simplifies record-keeping. In tax-advantaged accounts, basis method is usually less important because the account structure drives the tax treatment.
Last updated:
This calculator totals the entered purchase lots, then compares three basis scenarios for the entered sale quantity: oldest lots first (FIFO), newest lots first, and average cost. It multiplies the shares sold by the entered sale price to compute proceeds, then subtracts the selected basis to show gain or loss under each scenario.
The newest-lot comparison is a planning aid, not a substitute for broker-level specific identification. For individual stocks, actual tax reporting depends on the lot-identification method your broker records for the sale. Average-cost rules are also narrower for individual securities than for mutual-fund or DRIP shares.
Cost basis is the original purchase price of an investment plus adjustments such as commissions or reinvested amounts where applicable. It is subtracted from sale proceeds to determine capital gain or loss for tax purposes.
It depends on your tax situation. In a rising market, selling higher-basis shares first usually minimizes the current gain. For individual stocks, that is often handled through specific identification with the broker. Average cost simplifies record-keeping for eligible fund holdings but offers less tax-planning flexibility.
If you sell shares at a loss and repurchase substantially identical shares within the wash-sale window, the loss may be disallowed and added to the basis of replacement shares. This page does not model wash-sale adjustments.
For stocks and ETFs, lot identification usually has to be established with the broker at or before the sale. For mutual funds, average-cost elections have separate IRS rules and may limit later changes. Check your broker records and IRS guidance before assuming a past sale can be reclassified.
Each dividend reinvestment creates a new lot with its own basis equal to the amount reinvested. Over time this can create many small lots, which is why accurate record-keeping matters for partial sales.
In a stock split, the total basis stays the same but is spread across more shares. For example, in a 2-for-1 split, the share count doubles and the per-share basis is halved.