How to keep track of and calculate cost basis?
Article last updated: September 10, 2026

If you own stock, crypto or ETFs, average cost is one of the first numbers you look at. With a single purchase it is trivial. It gets complicated the moment there are several buys at different prices and then a sale, because you have to decide which shares you sold. This guide explains cost basis, the two popular methods for calculating it — FIFO and weighted average — and works the same example through both so they can be compared directly.
Key takeaways
- Cost basis is the total amount an investor paid for an asset, including commissions and fees, and it is the figure a gain or loss is measured against.
- Cost basis per share is calculated as a weighted average: the total amount paid across all purchases, divided by the total number of shares held.
- When only part of a holding is sold, a method is needed to decide which shares were sold; the two most common are First In, First Out (FIFO) and the weighted average method.
- FIFO assumes the earliest shares bought are the first sold, so the remaining average cost changes after a sale.
- The weighted average method assumes shares are sold proportionally from every purchase, so the remaining average cost per share is unchanged by a sale.
What is cost basis?
Cost basis is the total amount you paid to acquire an asset, including commissions, transaction fees and any other acquisition costs. It is the reference point every gain or loss is measured against: sale proceeds minus cost basis is your profit.
Cost basis is quoted two ways, and it is worth being clear which you mean. Total cost basis is the money you put into a position; cost basis per share, also called average cost, is that total divided by the number of shares you hold.
Cost basis is also the denominator behind several other portfolio figures. Yield on cost, for example, divides the dividend you now receive by what you originally paid, so an incorrect cost basis quietly corrupts it.
How do you calculate cost basis?
Cost basis per share is calculated as a weighted average of every purchase price, using the number of shares in each purchase as the weight. Total cost basis is simply everything you paid, including fees.
Total Cost Basis = (Shares1 x Price1) + (Shares2 x Price2) + ... + Fees
Average Cost per Share = Total Cost Basis / Total Shares Held
Imagine that you bought 10 shares of AAPL at $130, then the stock price dropped and you bought 30 shares more at $100. Calculating the average cost in this case is straightforward: take the weighted average of the prices, using the proportion of shares in each transaction as the weight.


Total Cost Basis = (10 x $130) + (30 x $100) = $1,300 + $3,000 = $4,300
Average Cost per Share = $4,300 / 40 shares = $107.50
Note that a simple average of the two prices, ($130 + $100) / 2 = $115, is wrong. It ignores the fact that three times as many shares were bought at $100, which is exactly what the weighting corrects for.
Why does the cost basis method matter when you sell?
The cost basis method matters when you sell because it decides which of your shares left the portfolio, and that determines both the gain you realise now and the average cost of what remains.
Take a position built from two purchases: 10 shares of AAPL bought at $130 and 30 more bought at $100, 40 shares in total at an average cost of $107.50. The price then rises and you sell 5 shares at $150. With 35 shares left, what is your average cost now?
There is no way to answer without an assumption about which 5 of the 40 shares were sold — the ones bought at $130, the ones bought at $100, or a mix. FIFO and the weighted average method both use the same average cost arithmetic and differ only in that assumption. Whichever you pick, the total of what you paid is still $4,300; the method only decides how much of that cost is used up by today's sale and how much stays with the shares you still hold.
How do you calculate cost basis using FIFO?
The First In, First Out (FIFO) method assumes the first shares you bought are the first shares sold. The earliest purchase is consumed first, and the remaining average cost is recalculated from what is left.

Working the example — 10 shares bought at $130, then 30 shares bought at $100, then 5 shares sold at $150 — FIFO takes all 5 sold shares from the first purchase, the one at $130. The first lot is left with 5 shares and the second lot still holds its full 30 shares:
Cost basis of the 5 shares sold = 5 x $130 = $650
Realised gain = (5 x $150) - $650 = $750 - $650 = $100
Remaining 35 shares = (5 x $130) + (30 x $100) = $650 + $3,000 = $3,650
Remaining average cost = $3,650 / 35 = $104.29
FIFO pulled the average cost down from $107.50 to $104.29, because the shares removed were the expensive ones. In a rising market FIFO generally sells the oldest and cheapest shares first, producing a larger realised gain; here the oldest shares happened to be the dearest, so the realised gain was small.
How do you calculate cost basis using the weighted average method?
The weighted average method assumes shares sold come proportionally from every purchase, which leaves the average cost per share unchanged by a sale.

Working the same example — 10 shares bought at $130, then 30 shares bought at $100, then 5 shares sold at $150 — the first purchase is 10 of the 40 shares, or 25%, and the second is 30 of 40, or 75%. Selling 5 shares therefore removes 1.25 shares from the $130 lot and 3.75 shares from the $100 lot:
Average cost per share before the sale = $4,300 / 40 = $107.50
Cost basis of the 5 shares sold = 5 x $107.50 = $537.50
Realised gain = (5 x $150) - $537.50 = $750 - $537.50 = $212.50
Remaining 35 shares = $4,300 - $537.50 = $3,762.50
Remaining average cost = $3,762.50 / 35 = $107.50
Because both lots shrink by the same proportion, their weights in the position are identical before and after the sale. That is why the average cost stays at $107.50: under the weighted average method, a sale never moves your average cost per share. Only a new purchase does.
FIFO vs weighted average: how do they compare?
FIFO and the weighted average method produce different realised gains and different remaining average costs from identical transactions, but the total cost basis they account for is the same.
Both columns below describe the same position: 10 shares of AAPL bought at $130, then 30 shares bought at $100, then 5 shares sold at $150.
| FIFO | Weighted average | |
|---|---|---|
| Which shares are assumed sold | The 5 earliest, all from the $130 lot | 1.25 from the $130 lot, 3.75 from the $100 lot |
| Cost basis of the 5 shares sold | $650 | $537.50 |
| Realised gain on the sale | $100 | $212.50 |
| Remaining 35 shares, total cost basis | $3,650 | $3,762.50 |
| Remaining average cost per share | $104.29 | $107.50 |
| Effect of a sale on average cost | Changes it | Leaves it unchanged |
| Record-keeping needed | Every purchase lot, with dates | One running total |
The two columns differ by $112.50 of realised gain, and by exactly the same $112.50 in remaining cost basis. Nothing is gained or lost overall — the cost is either used now or carried forward.
Which to use is often not your decision. Several jurisdictions mandate a method rather than offering a choice; the UK, for example, pools identical shares at an average cost. Where you do have a choice, weighted average is simpler to maintain and FIFO gives a more precise record of what each lot cost. Confirm the rules that apply to you before choosing, because tax treatment varies by country and by account type.
The choice also compounds with how often you trade. Every sale locks in a gain, so a portfolio with high portfolio turnover realises far more of its gains along the way, and rebalancing back to a target asset allocation is one of the most common reasons investors sell at all.
What other cost basis methods exist?
Besides FIFO and weighted average, several other cost basis methods exist, and they differ only in which shares they assume were sold. Portseido does not support these methods, but they are worth knowing:
- Last In, First Out (LIFO). The opposite of FIFO: the most recently bought shares are the first sold. In the running example — 10 shares at $130, then 30 at $100, then 5 sold at $150 — LIFO takes all 5 from the $100 lot, giving a cost basis of $500, a realised gain of $250, and a remaining average cost of $3,800 / 35 = $108.57.
- High-cost method. The highest-priced shares are sold first, which minimises the realised gain on each sale.
- Low-cost method. The lowest-priced shares are sold first, which maximises the realised gain on each sale.
- Specific identification. You nominate exactly which lot is being sold at the time of the trade, which gives the most control and requires the most record-keeping.
Frequently asked questions
Do dividends and fees change my cost basis?
Commissions and transaction fees are added to cost basis, because they are part of what you paid to acquire the asset. Ordinary cash dividends do not change cost basis — they are income. Reinvested dividends do: each reinvestment is a new purchase at that day's price, and it enters the weighted average like any other buy.
Does a stock split change my cost basis?
A stock split changes your cost basis per share but not your total cost basis. In a 2-for-1 split, your share count doubles and your average cost per share halves, leaving the total unchanged. For example, 40 shares at an average cost of $107.50, total $4,300, becomes 80 shares at $53.75, still $4,300 in total.
How do I calculate cost basis across two brokers holding the same stock?
Cost basis is tracked per account, so two brokers holding the same stock each report their own average cost, and neither shows your true overall figure. To get it, combine every purchase from both accounts into one weighted average: add all the amounts paid, add all the shares, and divide. Currency conversions must be applied at the rate on each transaction date.
What is the difference between cost basis and market value?
Cost basis is what you paid for a holding; market value is what it is worth today. The difference between the two is your unrealised gain or loss. Cost basis is fixed by your transactions and only changes when you buy, sell or receive a corporate action, while market value changes every trading day.
How to track cost basis in Portseido
Portseido tracks cost basis for every holding automatically from your transaction history, so you do not have to rebuild a weighted average each time you buy, sell or reinvest a dividend. It consolidates holdings across multiple brokers and multiple currencies, which is where manual cost basis tracking usually breaks down, and it uses the same figures to report dividends, yield on cost, asset allocation, drawdown, and time-weighted and money-weighted returns. Transactions can be imported from brokers or from a CSV.
Portseido supports the FIFO and weighted average methods, not LIFO, high-cost or low-cost, and it tracks and reports on your portfolio rather than giving buy or sell recommendations or tax advice. There is a free plan, and paid features come with a 14-day trial that does not need a credit card. Existing users can change the cost basis method in the calculation method settings. Try Portseido free