The basic calculation: sale price minus what you paid, then apply your tax rate

Long-term capital gains tax is calculated on the profit you make when you sell an asset you've held for more than one year. The math itself is straightforward: subtract your original purchase price (plus any improvements or fees) from the sale price. That number is your gain. Then multiply that gain by your tax rate, which depends on your income bracket and filing status.

The tricky part isn't the arithmetic—it's knowing which numbers to use and which tax rate applies to you. The IRS has three long-term capital gains rates: 0%, 15%, and 20%. Your rate depends on your total taxable income for the year, not just the gain itself. A $50,000 gain doesn't automatically mean you pay 15% on all of it; some of it might be taxed at 0% and some at 15%, depending on where your income falls.

Key Takeaways

  • Your long-term capital gain equals the sale price minus your cost basis (original price plus improvements and fees).
  • The tax rate—0%, 15%, or 20%—is determined by your total taxable income and filing status, not by the size of the gain alone.
  • You may owe tax at multiple rates on the same gain if your income straddles a tax bracket boundary.
  • You must hold the asset for more than one year (not one year exactly) for the long-term rate to apply; otherwise the gain is taxed as ordinary income.
  • State and local taxes on capital gains are separate from federal tax and vary significantly by location.

Finding your cost basis: what counts as what you paid

Cost basis is the starting number for every capital gains calculation. For most people, it's simply what you paid for the asset. If you bought 100 shares of stock at $50 per share, your basis is $5,000. If you bought a rental property for $200,000, that's your basis.

But basis can include more than the purchase price. Add any fees you paid to buy the asset—broker commissions, title insurance, closing costs on real estate. If you made improvements to a property (a new roof, a deck, major repairs), those costs add to basis too. Improvements must add value or extend the life of the property; routine maintenance does not count. Keep receipts and records for all of these, because the IRS will ask if you're ever audited.

Inherited assets get a "step-up" in basis. If your parent bought a house for $100,000 and it's worth $300,000 when they die and you inherit it, your basis is $300,000, not $100,000. This is one of the few times the IRS lets you start fresh. If you then sell it for $310,000, your gain is only $10,000, not $210,000.

Determining your tax rate: income brackets for 2024

The 0%, 15%, and 20% long-term capital gains rates are tied to ordinary income tax brackets, but they're not the same brackets. For 2024, here's where each rate begins, depending on your filing status:

Filing Status0% Rate Ends15% Rate Ends20% Rate Begins
Single$47,025$518,900$518,901+
Married Filing Jointly$94,050$583,750$583,751+
Married Filing Separately$47,025$291,875$291,876+
Head of Household$62,700$551,350$551,351+

These numbers are your taxable income, which is your total income minus deductions. If you're single, earn $40,000 in wages, and have a $20,000 long-term capital gain, your taxable income is $60,000. The first $47,025 of that is taxed at 0%, and the remaining $12,975 is taxed at 15%. You don't pay 15% on the whole gain.

These brackets change every year for inflation. The IRS publishes updated numbers in late 2023 for the following tax year, so check the current year's rates before you calculate.

Working through a step-by-step example

Say you're single, you earned $35,000 in wages last year, and you sold stock for $60,000 that you bought for $40,000 five years ago. Here's how to calculate the tax:

Step 1: Calculate the gain. Sale price ($60,000) minus cost basis ($40,000) = $20,000 gain.

Step 2: Find your taxable income. Wages ($35,000) plus capital gain ($20,000) = $55,000 taxable income (assuming no other income or deductions).

Step 3: Apply the brackets. For a single filer in 2024, the 0% rate covers income up to $47,025. You have $55,000, so $47,025 is taxed at 0% and the remaining $7,975 is taxed at 15%.

Step 4: Calculate the tax. $47,025 × 0% = $0. Then $7,975 × 15% = $1,196.25. Your federal long-term capital gains tax is $1,196.25.

This is why timing matters: if you could push some of that gain into the next year, or reduce your other income, you might keep more of the gain in the 0% bracket.

When you owe tax at multiple rates in the same year

If you sell multiple assets in one year, or if you have other income, your gains can be taxed at different rates. The IRS fills up the lower brackets first. Long-term gains are treated as the top layer of your income, so they're the last thing to be taxed.

Example: You're single with $50,000 in wages and two stock sales. The first sale is a $10,000 long-term gain; the second is a $15,000 long-term gain. Your taxable income is $75,000. The first $47,025 of that is wages (taxed at ordinary rates). The next $2,975 of the first gain ($47,025 to $50,000) is taxed at 0%. The remaining $7,025 of the first gain plus all $15,000 of the second gain ($50,000 to $75,000) is taxed at 15%. You don't pay one rate on one gain and another rate on the other; the brackets apply to your total income.

This layering is why it helps to know your total income before year-end. If you're close to a bracket boundary, selling an asset in December versus January can change your tax bill significantly.

State and local taxes on capital gains

Federal long-term capital gains tax is only part of the picture. Most states tax capital gains as ordinary income, meaning you'll owe your state income tax rate on top of the federal rate. A few states—including Alaska, Florida, Nevada, South Dakota, Tennessee, Texas, Washington, and Wyoming—have no state income tax at all. Others, like California and New York, tax capital gains at rates as high as 13% or more.

A handful of states have introduced capital gains taxes separate from income tax. Washington State, for example, taxes long-term gains on assets worth over $250,000 at a flat 7%. These rules are newer and still being litigated, so check your state's revenue department website for current rules.

The federal calculation is the same everywhere, but your total tax bill depends heavily on where you live and where you sell the asset. If you're considering a large sale, it's worth understanding your state's rules before you proceed.

Net investment loss and carryover

If you have capital losses in the same year as capital gains, you can subtract the losses from the gains. If your losses exceed your gains, you can deduct up to $3,000 of the net loss against your ordinary income in that year. Any loss beyond $3,000 carries forward to future years indefinitely, so you can use it to offset future gains or income.

This is why some people "harvest" losses late in the year—they sell losing positions to offset gains from winning positions, reducing their tax bill. You can then buy back a similar (but not identical) asset 31 days later without triggering the wash-sale rule, which prevents you from claiming a loss and immediately repurchasing the same security.

Frequently Asked Questions

What's the difference between long-term and short-term capital gains tax?

Long-term gains (held over one year) are taxed at 0%, 15%, or 20% depending on income. Short-term gains (held one year or less) are taxed as ordinary income at your regular tax bracket rate, which can be as high as 37%. The holding period is measured from the day after you buy to the day you sell; one year exactly is not long enough.

Do I have to report capital gains if they're small?

Yes. Any capital gain, no matter how small, must be reported on your tax return. The IRS matches sales reports from brokers (Form 1099-B) to your return, so underreporting is easily detected. Report it even if you owe no tax.

Can I deduct losses from a failed investment?

Yes, but only if you sold the investment. Unrealized losses—assets that have dropped in value but you still own—cannot be deducted. Once you sell, you can use the loss to offset gains or up to $3,000 of ordinary income per year, with excess losses carrying forward indefinitely.

What if I inherited stock and sold it right away?

You owe tax only on the gain from the date you inherited it. Your cost basis is the value on the date of death (or six months later if the estate chose that valuation date). If the stock was worth $100,000 when you inherited it and you sold it for $102,000 a month later, your gain is $2,000, taxed at long-term rates because inherited assets are treated as long-term regardless of how long you held them.

Do I owe capital gains tax if I reinvest the money?

Yes. The tax is based on the gain, not on what you do with the proceeds. Reinvesting the money does not reduce or defer the tax. You owe it in the year you sell, whether you spend the money, hold it in cash, or buy something else.