Realized Gains, Unrealized Gains, and Cost Basis
When an investment gain becomes taxable, how cost basis decides the size of a gain, how the method for choosing which shares you sold changes the answer, and why reinvested dividends belong in your basis.
The short version
In a taxable account, a rise in value isn't taxed while you hold the investment. It becomes a realized gain, generally taxable, when you sell. The gain is what you received minus your cost basis, which is generally what you paid, including costs like commissions. If you bought shares at different prices, the shares you're treated as selling change the gain: you can name specific shares, otherwise the oldest are treated as sold first, and mutual funds can use an average. Dividends you reinvest are taxed when paid and then add to your basis, so leaving them out means paying tax twice.
By the end of this lesson, you'll be able to
- Distinguish realized from unrealized gains
- Calculate a gain from sale proceeds and cost basis
- Explain how specific identification, first in first out, and average basis change the gain on the same sale
Why this matters
Every tax question about selling an investment starts with two facts: whether a gain has been realized, and how big it is. This module covers US federal tax rules for investments held in ordinary taxable accounts. Inside IRAs and 401(k)s, as the previous module showed, these rules don't apply year to year.
Realized and unrealized
When an investment you own rises in value, you have an Unrealized gain. An increase in value on an investment you still own. It isn't taxed until you sell. Also called a paper gain. Glossary, sometimes called a paper gain. It isn't taxed. When you sell for more than you paid, the gain becomes a Realized gain. A gain you've locked in by selling. In a taxable account, realized gains are generally taxed for the year of the sale. Glossary, a Capital gain. The profit when you sell an investment for more than you paid for it, adjusted for certain costs. Selling for less gives a capital loss. More on this term that generally has to be reported. Sell for less, and you have a capital loss.1
That gives investors control over timing: in a taxable account, you generally choose when to realize a gain by choosing when to sell. Dividends and interest are different. They're generally taxed in the year you receive them, whether or not you sell anything, as How Dividends and Interest Are Taxed explains.
Cost basis
The size of a gain depends on your Cost basis. What you paid for an investment, including costs such as commissions. Your gain or loss when you sell is the sale proceeds minus the basis. More on this term. For stocks and bonds you buy, basis is the purchase price plus costs such as commissions and transfer fees.2 The gain or loss is what you receive from the sale minus that basis.
| Bought 100 shares at $30, plus a $5 commission | Basis: $3,005 |
|---|---|
| Sold all 100 shares at $42 | Proceeds: $4,200 |
| Realized gain | $1,195 |
If your broker charges no commission, the basis is simply the price paid. Settlement, Fees, and Fractional Shares covers trading costs.
Investments you didn't buy follow different rules. Inherited investments generally take their value on the date of the owner's death as their basis, while a gift generally keeps the giver's basis.3 Tax Considerations When Selling looks at why that matters.
Which shares did you sell?
If you bought the same investment at different times and prices, and sell only part of it, the gain depends on which shares count as sold. The IRS allows:4
- Specific identification. You tell your broker which shares to sell at the time of the sale and get written confirmation. Their basis is used.
- First in, first out. If you don't identify the shares, the ones you bought first are treated as sold first.
- Average basis. For mutual fund shares, and shares in some dividend reinvestment plans, you can use the average basis of all the identical shares in the account.
The shares were bought in three lots: 10 at $40, then 10 at $60, then 10 at $50. Total cost $1,500, an average of $50 a share.
| Method | Basis of the 10 shares sold | Realized gain |
|---|---|---|
| First in, first out (the $40 lot) | $400 | $300 |
| Specific identification (the $60 lot) | $600 | $100 |
| Average basis ($50 a share) | $500 | $200 |
The same sale, three different gains. Choosing the highest-cost shares lowers this year's gain, but leaves the cheaper shares, and their larger gains, for later.
Reinvested dividends add to your basis
If dividends are used to buy more shares, you still report them as income for the year.4 Those new shares cost you the amount of the dividend, so that amount is part of your basis. Leaving reinvested dividends out of your basis would mean paying tax on the same money twice: once as a dividend, and again as part of the gain when you sell.
For most stocks bought since 2011 and fund shares bought since 2012, brokers must report your basis to the IRS on Form 1099-B when you sell.5 For older shares, you may need your own records.
You bought 40 shares for $1,000 in total. Reinvested dividends later bought 2 more shares for $60. You sell all 42 shares for $1,400. What's your realized gain?
Your basis is $1,000 + $60 = $1,060, so the gain is $1,400 − $1,060 = $340. Forgetting the reinvested $60 would overstate the gain at $400, and you'd already have paid tax on the $60 as a dividend.
Key takeaways
- Unrealized gains aren't taxed. A gain is realized, and generally taxable, when you sell.
- Gain equals sale proceeds minus cost basis, which includes costs like commissions.
- Specific identification, first in first out, and average basis can give different gains on the same sale.
- Reinvested dividends are taxed when paid and add to your basis.
Check your understanding
Your shares rose from $5,000 to $8,000 this year, and you didn't sell. In a taxable account, what capital gain do you owe tax on for this year?
An unrealized gain isn't taxed. If you sold at $8,000, you'd have a $3,000 realized gain. Any dividends paid during the year would still be taxable for the year.
You sell part of a stock you bought in several lots and don't tell your broker which shares to sell. Which shares are treated as sold?
Without specific identification, first in, first out applies: the oldest shares are treated as sold first. To sell a particular lot, specify it at the time of the sale and get written confirmation.
What's next
Once a gain is realized, how long you held the investment decides the tax rate. Short-Term vs. Long-Term Capital Gains explains the difference.
Go deeper
- Short-Term vs. Long-Term Capital GainsPart 6: Strategy, Behavior, Accounts, and Taxes
- Tax Considerations When SellingPart 6: Strategy, Behavior, Accounts, and Taxes
- Taxable vs. Tax-Advantaged AccountsPart 1: Foundations
Notes and sources
- Internal Revenue Service. Topic no. 409, Capital gains and losses. Checked 2026-09-30. Back to text
- Internal Revenue Service. Topic no. 703, Basis of assets. Checked 2026-10-06. Back to text
- Internal Revenue Service. Publication 551, Basis of Assets. Checked 2026-10-06. Back to text
- Internal Revenue Service. Publication 550 (2025), Investment Income and Expenses. Checked 2026-10-11. Back to text
- Internal Revenue Service. Instructions for Form 1099-B (2026). Checked 2026-10-06. Back to text