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.

Lesson 1 of 5 · 5 min read · Intermediate · Free · Last reviewed October 2026

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 , sometimes called a paper gain. It isn't taxed. When you sell for more than you paid, the gain becomes a , a 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 . 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.

A single purchase and sale (hypothetical)
Bought 100 shares at $30, plus a $5 commissionBasis: $3,005
Sold all 100 shares at $42Proceeds: $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.
Selling 10 of 30 fund shares at $70 (hypothetical)

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.

MethodBasis of the 10 shares soldRealized 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?

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?

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?

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

Notes and sources

  1. Internal Revenue Service. Topic no. 409, Capital gains and losses. Checked 2026-09-30. Back to text
  2. Internal Revenue Service. Topic no. 703, Basis of assets. Checked 2026-10-06. Back to text
  3. Internal Revenue Service. Publication 551, Basis of Assets. Checked 2026-10-06. Back to text
  4. Internal Revenue Service. Publication 550 (2025), Investment Income and Expenses. Checked 2026-10-11. Back to text
  5. Internal Revenue Service. Instructions for Form 1099-B (2026). Checked 2026-10-06. Back to text

Saved to this browser in the prototype. On the live site, progress saves to your account.

This lesson is general education, not personalized investment, tax, or legal advice. Examples use fictional people and companies, and hypothetical numbers.