We're the LiteFolio team. A lot of investors get stuck on average cost basis calculation the moment they buy more of a stock they already own. The short answer: average cost basis is calculated with one simple formula — total cost divided by total shares. In this article, we work through buying in multiple lots, fees, partial sales, and stock splits with real numbers we double-check as we go, plus why doing this by hand or in a spreadsheet gets harder over time, and an easier alternative: recording it once and letting it calculate automatically.
Want your average cost basis calculated automatically as you log your holdings?
See LiteFolio →The short answer: average cost basis = total cost ÷ total shares
Average cost basis is calculated by dividing the total amount you've spent buying a stock by the total number of shares you hold. Because the price you pay changes with each purchase, you can't just average the prices themselves — you need a cost-weighted average instead.
For example, let's say you bought 100 shares at $50, then bought 100 more shares at $40.
As long as you remember the formula total cost ÷ total shares, you can calculate it the same way no matter how many times you buy more. In the next section, we'll go case by case through fees, partial sales, and stock splits.
Average cost basis calculation, case by case
The core idea stays the same, but once fees, sales, or splits enter the picture, it's easy to get confused about "what do I add" and "how does the price change." Here we work through four common cases, each with real numbers we verify along the way.
â‘ A simple additional purchase
Starting from the 200 shares at an average of $45 above, say you buy 100 more shares at $60. You simply add the new purchase to your existing total cost.
Real-world numbers usually won't divide this evenly — how you round fractions of a cent varies by broker, so check your brokerage statement for the exact convention it uses.
â‘¡ Including fees
Any fee paid on a purchase gets included in the cost. Let's apply a $5 fee per trade to our very first example.
That's five cents higher than the $45.00 we got without fees. Sell-side fees are usually deducted from sale proceeds rather than added to cost basis, but exactly how this is presented varies by broker, so it's worth checking your account statements to confirm your actual cost basis.
â‘¢ What happens after a partial sale
Selling part of a position does not change the average cost basis of the shares you have left. Let's check this starting from 200 shares at an average of $45, selling 50 shares at $55.
Selling reduces your cost and share count together in proportion, so the per-share average doesn't move. The only thing that moves your average cost basis is a new purchase.
â‘£ What happens after a stock split
In a stock split, your share count increases while your total cost stays exactly the same, so your average cost basis drops in proportion to the split ratio. Let's check this on 100 shares with an average cost basis of $45 (total cost $4,500) undergoing a 2-for-1 split.
After the split, 200 shares × $22.50 still equals $4,500 — matching your pre-split total cost. The same check works for any ratio, like 3-for-1 or 3-for-2: adjust the share count and price by the ratio, then verify the total cost still matches.
Why average cost basis is hard to maintain by hand or in a spreadsheet
Every calculation above is simple on its own, but the more buys, sells, and splits pile up, the more work it takes to maintain by hand or in a spreadsheet. Every additional purchase means rewriting your totals, every partial sale means tracking your remaining shares, and every split means adjusting entire rows of past data.
This gets especially messy if you hold the same stock across multiple brokerage accounts, since you first need to total up the cost from each account before you can average them together. We cover this challenge in more depth in our guide to tracking investments across multiple brokerage accounts.
For concrete spreadsheet formulas — including a weighted-average setup using SUMPRODUCT, and the limits that remain even with well-built formulas — see our stock portfolio spreadsheet template guide.
Record it and it calculates itself: logging buys, sells, and splits
The calculation itself is simple, but updating it by hand every time you trade is a real burden. If you keep a record of each transaction and let the average cost basis recalculate itself automatically every time, that burden disappears.
LiteFolio is a manual-entry investment portfolio tracker where you log buys, sells, dividends, deposits and withdrawals, fees, stock splits, taxes, and notes. It never connects to any brokerage account — as a portfolio tracker without account linking, it automatically calculates your share count, average cost basis, total cost, and realized gains from what you record. Your data is stored local-first, saved on your device first.
Just log your buys, sells, and splits — average cost basis is calculated automatically
See LiteFolio →LiteFolio is a record-keeping and visualization tool and does not provide investment advice.
LiteFolio
An investment portfolio tracker that automatically calculates average cost basis, realized gains, and asset allocation as soon as you log your buys, sells, dividends, splits, and fees. It never connects to any brokerage account, and your data is stored on your device first. Available now on iOS and Android.
Learn more about LiteFolioFrequently asked questions
Does selling part of a position change my average cost basis?
No. A sale reduces your total cost and share count together in proportion, so the average cost basis of your remaining shares stays the same. It only changes when you make a new purchase.
Should fees be included in average cost basis?
Buy-side fees are generally included in the cost basis calculation. Sell-side fees are more often deducted from sale proceeds rather than folded into cost basis, but the exact presentation varies by broker, so check your account statements too.
What happens to average cost basis after a stock split?
It drops in proportion to the split ratio. Since total cost doesn't change, doubling your share count halves your average cost basis. You can verify this by checking that shares × average cost basis still equals your pre-split total cost.
Is LiteFolio free to use?
LiteFolio is available now for iOS and Android. Your data is stored on your device first, and features like cloud sync are planned as part of a paid Pro tier. Check the App Store or Google Play for current details.