Bought the same stock, fund or coin several times and sold part of it? Enter every buy and sell and see the cost basis and realized gain under each method side by side, split into short-term and long-term, with the lots you still hold.
Last updated:
Compare methods
Details for
Sales matched to lots
Shares still held
Advertisement
Advertisement
How to use the Cost Basis Calculator
Add each buy and sell with its date, number of shares, price per share and fees, or paste them with Import CSV.
Optionally enter the current price to see the unrealized gain on shares you still hold.
Compare the methods in the summary table: realized gain, short- and long-term amounts and remaining basis.
Open a method's details to see which lots each sale used; for Specific ID, choose the lots yourself.
Download the sales CSV for your records or your tax software.
How each method picks the shares you sold
Method
Shares sold first
Typical effect when prices have risen
FIFO
Oldest purchases
Largest gains, but more of them long-term
LIFO
Newest purchases
Smaller gains, more likely short-term
HIFO
Highest cost per share
Smallest gains (or largest losses) now, lower basis left for later
Average cost
All shares at one average basis; oldest first for holding period
Between FIFO and HIFO
Specific ID
The lots you choose
Whatever you select, as confirmed with your broker
Formulas used
Lot cost basis = shares × price + buy fees. Cost per share = lot basis ÷ shares.
Net proceeds = shares sold × sale price − sell fees.
Realized gain = net proceeds − cost basis of the shares matched to the sale.
Average cost per share = total basis of shares held ÷ shares held, recalculated after each purchase.
Long-term when the sale date is more than one year after the purchase date.
Worked example
The example loaded on this page buys 100 shares at $40, 50 at $55 and 80 at $48 (each with a $5 fee), sells 120 at $60, buys 40 more at $52, then sells 60 at $70 (sale fees $7). With all 90 remaining shares valued at $66:
Method
Realized gain
Short-term part
Basis of 90 shares held
FIFO
$3,184.13
$96.83
$4,488.13
Average cost
$2,990.17
$276.66
$4,294.17
LIFO
$2,300.50
$1,854.33
$3,604.50
HIFO
$2,300.50
$1,783.96
$3,604.50
The total gain over the whole holding is the same in the end; the method only moves gain between this year and later years, and between short-term and long-term. A smaller realized gain now leaves a lower basis, and a larger unrealized gain, in the shares you keep.
Frequently asked questions
What is cost basis?
Cost basis is what you paid for an investment, including purchase fees and commissions. When you sell, your capital gain or loss is the sale proceeds (after selling fees) minus the cost basis of the shares sold. If you bought at different prices, the method used to decide which shares were sold changes the basis and the gain.
What is the difference between FIFO, LIFO and HIFO?
FIFO (first in, first out) sells your oldest shares first, LIFO (last in, first out) sells the newest first, and HIFO (highest in, first out) sells the shares with the highest cost first. In a rising market FIFO usually gives the largest gain and HIFO the smallest. LIFO and HIFO are applied through specific identification of lots with your broker.
How does the average cost method work?
Average cost divides the total cost of all shares you hold by the number of shares, so every share sold has the same basis. After a sale the average stays the same for the remaining shares; a new purchase changes it. In the US it is allowed for mutual fund shares and shares in dividend reinvestment plans, and the shares sold are treated as the oldest for the holding period.
When is a gain long-term?
In the US a gain is long-term when you held the shares for more than one year: the holding period starts the day after you bought them, so shares bought on March 5, 2024 become long-term if sold on or after March 6, 2025. Long-term gains are usually taxed at lower rates than short-term gains, which are taxed as ordinary income.
Can I choose any method I like?
You can generally pick specific lots at the time of each sale if your broker confirms the identification, otherwise brokers default to FIFO. Once you use average cost for a mutual fund, switching usually requires notifying the broker. Rules differ by country and by asset, so check with your broker or a tax professional.
Does this calculator handle wash sales, splits or dividends?
No. It does not adjust for wash-sale disallowed losses, stock splits, return of capital or reinvested dividends. For a split, enter the lots with split-adjusted shares and prices; record each reinvested dividend as a separate buy. Treat the results as an estimate and compare them with your broker's 1099-B.
Is my data private?
Yes. All calculations run in your browser and your transactions are saved only in this browser's local storage on this device. Nothing is uploaded.
Are all the tools on FreeToolCabin tested for quality and accuracy?
Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.