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.
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.
| Method | Units sold first | What it does |
|---|---|---|
| FIFO | The oldest | A common default at brokers worldwide. In a rising market it tends to give the biggest gain, with more of it held long term. |
| LIFO | The newest | Often a smaller gain in a rising market, with shorter holding periods. Useful for seeing the other extreme. |
| Average cost | Every unit costs the same | No 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.
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.