Free tools

Capital gains and cost basis calculator.

A capital gain is what you sold for, less fees, minus what those units cost you. This capital gains calculator matches a sale against your earlier buys by FIFO, LIFO or average cost and shows the cost basis, gain and holding period of every lot used.

Buys
Sale

How is a capital gain calculated?

Each buy creates a lot: a parcel of units with its own date and cost. When you sell, the sale is matched against one or more lots, and the gain is the sale proceeds minus the cost of the units matched.

cost base of a lot = units × price + buy fees proceeds of the sale = units × price − sell fees gain or loss = proceeds − cost base of the units sold

When a sale uses part of a lot, the lot's cost is shared out per unit: selling 20 of 50 units uses 20/50 of that lot's cost, fees included. Proceeds are split across the lots used in proportion to units, so you can see the gain on each. Every figure is worked out exactly and rounded to the cent, and the lot figures always add up to the totals.

The holding period is counted for each lot. A lot sold more than one year after it was bought is marked long term. Some countries treat long-term gains differently, and the exact test varies, so check with your accountant.

FIFO, LIFO or average cost: which should you use?

Where you live often decides, not you, so check with your accountant. The method changes which units count as sold, and so the size of the gain and how much of it is long term.

MethodUnits sold firstWhat it does
FIFOThe oldestA common default at brokers worldwide. In a rising market it tends to give the biggest gain, with more of it held long term.
LIFOThe newestOften a smaller gain in a rising market, with shorter holding periods. Useful for seeing the other extreme.
Average costEvery unit costs the sameNo lot tracking: each unit sold carries the average cost of all units held, so the gain is a blend.

With average cost, the calculator still dates the units oldest first so it can show holding periods.

Worked example

The pre-filled figures are illustrative. You bought 100 units at 42.50 in March 2021, 50 at 38.00 in June 2022 and 60 at 55.20 in November 2025, paying 9.95 in fees each time. On 30 June 2026 you sell 120 units at 61.00, also paying 9.95.

proceeds = 120 × 61.00 − 9.95 = 7,310.05 FIFO: 100 from 2021 (4,259.95) + 20 of 50 from 2022 (763.98) cost base 5,023.93 → gain 2,286.12, all long term LIFO: 60 from 2025 (3,321.95) + 50 from 2022 (1,909.95) + 10 from 2021 (426.00) cost base 5,657.90 → gain 1,652.15, of which 333.08 short term Average: 9,491.85 ÷ 210 units = 45.199 per unit × 120 cost base 5,423.91 → gain 1,886.14

Same sale, three different gains. That's why you need to know which method applies to you and to keep a record of the lots left over, which set the cost base of your next sale.

What this calculator doesn't model

  • Specific-lot identification, where you choose exactly which lots a sale uses.
  • Country-specific matching rules, such as matching a sale with buys made shortly before or after it.
  • Corporate actions such as splits, return of capital or reinvested distributions that adjust cost base.
  • Currency. Everything is in one currency. For a foreign share, each buy and sale is generally converted at the rate on its own date.
  • Tax. It shows the gain or loss, not the tax on it. Check tax with your accountant.

This is general information, not financial or tax advice. For more depth, read the guide to cost basis and capital gains.

Questions

What is cost basis?

Cost basis (called cost base in Australia) is what you paid for an investment, including costs of buying it such as brokerage. It's what you subtract from the sale proceeds to work out a gain or loss.

Are brokerage fees included in the cost basis?

In most countries, yes: fees to buy are added to the cost base, and fees to sell are taken off the proceeds. The calculator does both.

What does FIFO mean for shares?

First in, first out: when you sell, the units you bought earliest are treated as sold first. Because older units have often risen the most, FIFO tends to give a bigger gain, but also more of it held long term.

What counts as long term?

In this calculator, a lot sold more than one year after it was bought. Countries that care about holding periods have their own tests, so check with your accountant.

Can I work out a capital loss?

Yes. If the proceeds are less than the cost base of the units sold, the result is a loss, shown in red. How you can use a loss is a tax question for your accountant.

Let your AI keep the books.

Worthbase tracks everything your household owns and owes, prices it daily and does every calculation exactly. Connect it to Claude or ChatGPT in two minutes.

by Sanjay