How Capital Gains Tax Works on Stocks and Real Estate
Capital gains tax is the tax you pay on the profit when you sell an investment for more than your adjusted cost basis. How much you owe depends on what you sold, how long you owned it, your income, and, for real estate, whether you claimed depreciation.
What Is Capital Gains Tax?
A capital gain is the profit you make when you sell an asset for more than its adjusted cost basis. Stocks, mutual funds, investment real estate, and other investments can all generate capital gains.
The basic calculation is simple: Selling price minus adjusted cost basis equals capital gain.
Your cost basis generally starts with what you paid for the investment, including certain acquisition costs. It can increase with qualifying improvements or decrease through deductions such as depreciation.
For stocks, the calculation is usually straightforward. If you buy shares for $10,000 and sell them for $16,000, you have a $6,000 gain, assuming no other adjustments or transaction costs.
Real estate is more complicated. Improvements can increase your property’s basis, while depreciation deductions reduce it. As a result, your taxable gain may differ considerably from the cash you receive when you sell.
Your mortgage balance does not determine your taxable gain. You can have relatively little equity in a property and still owe taxes on a substantial gain.
Short-Term vs. Long-Term Capital Gains
How long you own an investment before selling it is one of the most important factors in determining your capital gains tax rate.
Short-Term Capital Gains
If you own an investment for one year or less, your profit is generally considered a short-term capital gain. Short-term gains are taxed at your ordinary federal income tax rate, using the same general rate structure that applies to wages and other ordinary income. This can make a substantial difference for someone who frequently buys and sells stocks. A profitable investment sold after several months may generate a higher tax bill than one held long enough to qualify for long-term treatment.
Long-Term Capital Gains
If you own an investment for more than one year before selling it, the gain generally qualifies for long-term capital gains treatment. The general federal long-term capital gains rates are 0%, 15%, and 20%. Which rate applies depends on your taxable income and filing status. These rates are not necessarily applied to every dollar of investment profit at the same rate. You may have ordinary income taxed at a higher rate while qualifying for a lower rate on your long-term capital gains. State income taxes and additional federal taxes may also apply. For current income thresholds and tax-year details, check IRS.gov. Waiting for long-term treatment can reduce the tax bill, though you should not hold a poor investment just to save on taxes.
How Capital Gains Tax Works on Stocks
Stocks are generally easier to calculate than real estate because your brokerage typically maintains records of your purchase price and adjusted cost basis.
Stock sale example: Suppose you purchase $20,000 worth of stock and sell it several years later for $32,000.
| Original purchase price | $20,000 |
| Sale price | $32,000 |
| Capital gain | $12,000 |
| Illustrative federal tax rate | 15% |
| Illustrative federal tax | $1,800 |
You have a $12,000 long-term capital gain. At an assumed 15% federal rate, your federal tax would be $1,800. This simplified example assumes the entire gain qualifies for that rate and excludes state and additional federal taxes.
You generally owe capital gains tax when you sell an investment, not simply because its value increases. If your $20,000 investment grows to $32,000 but you continue holding it, you generally have an unrealized gain rather than a taxable sale.
How Capital Gains Tax Works on Real Estate
Real estate follows many of the same capital gains principles as stocks, but depreciation adds another layer.
When you own rental property, you can generally deduct depreciation over time. This noncash expense reduces your taxable rental income and your property’s adjusted tax basis. This is where some property owners get surprised. Depreciation can increase your taxable gain when you eventually sell.
Understanding Adjusted Basis
Suppose you purchase a rental property for $300,000 and claim $60,000 in depreciation over the years. Your adjusted basis becomes $240,000. If you sell the property for $400,000, your taxable gain is $160,000, ignoring selling costs and other adjustments. That does not mean you made $160,000 in cash profit. Your mortgage payoff and transaction costs affect how much money you actually receive. Taxable gain is calculated using tax basis, not mortgage equity.
What Is Depreciation Recapture?
Depreciation recapture is one of the most misunderstood parts of real estate taxation. In plain English, the IRS requires you to account for depreciation deductions when you sell depreciable property. You received a tax benefit from those deductions while owning the property, and the tax treatment of your gain reflects that history.
For residential rental buildings depreciated under the straight-line method, the depreciation-related gain is generally treated as unrecaptured Section 1250 gain. It can be taxed at a federal rate of up to 25%, rather than the ordinary long-term capital gains rates of 0%, 15%, or 20%. The 25% rate is a maximum, not a fixed rate. The rate that actually applies depends on the individual taxpayer’s situation.
Certain equipment and other components classified as Section 1245 property can receive different treatment, including ordinary income recapture. Buildings generally fall under different rules. This distinction matters for commercial real estate owners and investors who have completed cost segregation studies.
The important takeaway is that depreciation does not disappear when you sell a property. You need to account for it when calculating your taxable gain.
Rental property sale example: You purchase a rental property for $300,000, claim $60,000 in depreciation, and later sell it for $400,000.
| Original purchase price | $300,000 |
| Depreciation claimed | $60,000 |
| Adjusted tax basis | $240,000 |
| Sale price | $400,000 |
| Total taxable gain | $160,000 |
| Depreciation-related portion | $60,000 |
| Remaining gain | $100,000 |
In this simplified example, the $60,000 depreciation-related portion may qualify as unrecaptured Section 1250 gain, subject to the applicable maximum rate. The remaining $100,000 may qualify for long-term capital gains treatment, assuming the applicable holding-period and tax rules are satisfied.
The 3.8% Net Investment Income Tax
The Net Investment Income Tax, commonly called NIIT, is an additional 3.8% federal tax that may apply to certain investment income, including capital gains and rental income, and it is separate from regular capital gains tax.
The Home-Sale Capital Gains Exclusion
Selling your primary residence is different from selling stocks or rental property. Qualifying homeowners can generally exclude up to $250,000 of gain if single or $500,000 if married filing jointly. To qualify under the general ownership and use tests, you must have owned the home and used it as your main residence for at least two years during the five-year period ending on the sale date.
For married couples filing jointly, both spouses generally must meet the residence-use requirement, while only one needs to meet the ownership requirement. For example, a married couple selling their home for a $450,000 profit may be able to exclude the entire gain from federal income tax if they meet the requirements. Additional eligibility rules apply, including restrictions on using the exclusion for another home sale during the preceding two years. The exclusion generally applies to your primary residence, not a vacation property or ordinary rental property. Special rules also apply when a home has been used for business or rental purposes.
Legal Ways to Reduce Your Capital Gains Tax
Several legitimate strategies can help investors reduce or defer capital gains tax. The right approach depends on the investment and what you plan to do with the proceeds.
Hold Investments Longer Than One Year
Holding an investment for more than one year can qualify the gain for long-term capital gains treatment instead of ordinary income tax rates. However, taxes should not be the only reason to hold an investment. A poor investment does not become a good one simply because selling it creates a tax bill.
Tax-advantaged retirement accounts can also change the picture. Gains inside a retirement account are treated differently from gains in a taxable brokerage account — see our comparison of the Roth IRA vs. a traditional IRA.
Use Capital Losses to Offset Gains
Selling an investment at a loss may help offset gains elsewhere in your portfolio. For example, a $10,000 gain combined with a $4,000 loss generally produces a $6,000 net capital gain, assuming the transactions receive the same general tax treatment. If losses exceed gains, you may also be able to deduct a limited amount against ordinary income, with unused losses generally carried forward. Be aware of wash-sale rules, which can prevent you from immediately claiming a loss when you buy a substantially identical security within the restricted period.
Consider a 1031 Exchange for Investment Real Estate
A Section 1031 like-kind exchange allows investors to defer qualifying gains when they sell investment or business real estate and acquire qualifying replacement property. The key word is defer. The deferred gain generally carries into the replacement property’s tax basis and may become taxable when that property is eventually sold. There are strict timing, identification, and transaction requirements. The exchange generally needs to be structured before the original sale closes, using a qualified intermediary. A 1031 exchange can make sense when an investor wants to move equity into another property without immediately recognizing qualifying gain. It is not automatically the best choice. Sometimes paying the tax and keeping the proceeds makes more financial sense.
Donate Appreciated Investments
If you already plan to make charitable contributions, donating appreciated stock directly to a qualified charitable organization may be worth considering. Depending on the circumstances, this can avoid realizing the capital gain and may provide a charitable contribution deduction, subject to applicable rules and limitations.
Keep Accurate Cost-Basis Records
Maintain stock purchase and distribution records, along with real estate records for qualifying improvements, acquisition costs included in basis, selling expenses, and depreciation claimed. Qualifying improvements can increase basis, while routine maintenance and repairs generally receive different tax treatment.
Consider an Installment Sale
An installment sale allows a seller, in qualifying circumstances, to receive payments over multiple years. Eligible gain may be recognized as payments arrive, potentially spreading taxable income over time. However, depreciation recapture generally must be recognized in the year of sale, even when payments arrive later. You also take on financing risk by allowing the buyer to pay over time.
Plan Before You Sell
The biggest mistake investors make is focusing only on the sale price and overlooking the tax consequences. Before selling, calculate your adjusted basis, estimate the taxes, and determine how much money you will actually keep.
For a broader end-of-year review, see our Year-End Tax Planning Checklist.
Bottom Line
Capital gains tax is part of investing, but the amount you pay depends on what you sell, how long you own it, and how the investment has been treated for tax purposes. For stocks, the biggest consideration is generally whether your gain is short-term or long-term. For real estate, depreciation adds another layer that can make the calculation considerably more complicated. The home-sale exclusion, capital loss deductions, charitable contributions, and 1031 exchanges are legitimate tools that may help reduce or defer taxes. My advice is straightforward: know your adjusted basis, understand your holding period, and calculate your after-tax proceeds before selling. A little planning can make a meaningful difference in what you actually keep.
Disclaimer: This article is for general educational purposes only and is not personalized financial, tax, or legal advice; consult a qualified tax professional regarding your circumstances.
