Skip to content

Free calculator

Cost Basis Calculator

Work out the cost basis of shares you sold and the gain or loss on the sale. Enter each lot you bought with its date, shares and price, then the sale, and the calculator shows the result under two methods side by side: FIFO and average cost.

It also shows which lots FIFO used and the cost basis left on the shares you still hold. The starting values are a fictional example.

Lots you bought
The sale

FIFO (first in, first out)

Gain or loss, FIFO
Gain of $220.00
Cost basis of shares sold, FIFO
$880.00
Cost basis remaining, FIFO
$1,200.00
Lots used, earliest first
LotShares soldCost
Jan 15, 2025 at $42.0015$630.00
Mar 10, 2025 at $50.005$250.00

Average cost

Gain or loss, average cost
Gain of $268.00
Cost basis of shares sold, average cost
$832.00
Cost basis remaining, average cost
$1,248.00

Average price of all lots: $41.60 a share.

Sale proceeds
$1,100.00
Shares held before the sale
50
Shares remaining
30

Runs in your browser. Nothing you enter is sent or stored.

How the two methods work

Cost basis is what you paid for the shares you sold. When you bought at different prices, the answer depends on which shares count as sold. The gain or loss is the sale proceeds minus that cost.

FIFO: first in, first out

The earliest lots are sold first. The calculator sorts your lots by date, takes shares from the oldest lot until it is used up, then moves to the next. If you leave every date empty, it uses the order you entered.

Average cost

Every share carries the same cost: the total paid for all lots divided by the total shares. The cost of the shares sold is that average multiplied by the number sold.

Worked example

Fictional example: three lots, then a sale of 20 shares at $55.00
ItemFIFOAverage cost
Lots held15 at $42.00 (Jan 15, 2025), 10 at $50.00 (Mar 10, 2025), 25 at $38.00 (Jun 2, 2025)50 shares for $2,080.00, average $41.60
Sale proceeds20 × $55.00 = $1,100.00$1,100.00
Cost basis of shares sold15 × $42.00 + 5 × $50.00 = $880.0020 × $41.60 = $832.00
Gain$1,100.00 − $880.00 = $220.00$1,100.00 − $832.00 = $268.00
Cost basis remaining on 30 shares$2,080.00 − $880.00 = $1,200.00$2,080.00 − $832.00 = $1,248.00

These are the calculator's starting values. The two methods give different gains on a partial sale. If you sell every share, both give the same total.

What this calculator leaves out

  • Which method you may use. That depends on your country, your account and the type of asset. Check the rules that apply to you or ask a tax professional.
  • Fees and commissions. To include them, add buy fees to the price per share and subtract sale fees from the sale price.
  • Other methods, such as choosing specific lots or last in, first out.
  • Adjustments such as stock splits, reinvested dividends, returns of capital and wash sale rules.
  • Holding periods. The calculator does not split gains into short term and long term.

Calculator questions

What is cost basis?

It is the amount you paid for an investment, used to work out the gain or loss when you sell. For shares bought at different times, it depends on which shares count as sold.

What is the difference between FIFO and average cost?

FIFO treats your earliest shares as sold first, so the cost comes from your oldest lots. Average cost gives every share the same cost: the total paid divided by the total shares.

Do I need to enter dates?

Dates decide the FIFO order. Enter a date for every lot, or leave them all empty and the calculator uses the order you entered. Average cost does not need dates.

Why do the two methods show different gains?

On a partial sale they assign different costs to the shares sold. Over the whole position the totals match: selling every share gives the same gain under both.

Is anything I enter saved?

No. The calculation runs in your browser. Nothing you type is sent to Fillfolio or stored.

This calculator gives estimates from the values you enter. It is not tax, legal or investment advice.