The basic formula: sale price minus what you paid, times your tax rate
Capital gains tax is calculated by taking the amount you sold an asset for, subtracting what you originally paid for it (plus any improvements you made), and then applying your tax rate to that difference. The difference between sale price and original cost is your capital gain. You only pay tax on the gain, not on the full sale price.
The calculation changes depending on how long you held the asset. If you owned it for one year or less, it is taxed as short-term capital gain at your ordinary income tax rate — the same rate you pay on wages or salary. If you owned it for more than one year, it is taxed as long-term capital gain at a lower rate: 0%, 15%, or 20%, depending on your income level.
Key Takeaways
- Capital gain equals the sale price minus your original purchase price and any capital improvements you made to the asset.
- Short-term gains (held one year or less) are taxed at your ordinary income tax rate; long-term gains (held over one year) are taxed at 0%, 15%, or 20%.
- Your long-term capital gains rate depends on your total taxable income for the year, not on the size of the gain itself.
- You report capital gains on Schedule D of your tax return, and the IRS matches it against your brokerage records.
- Losses can offset gains dollar-for-dollar in the same year, and unused losses can carry forward to future years.
How to calculate your capital gain step by step
Start with the sale price — the amount you received when you sold the asset. This is the gross proceeds, before any fees or taxes. If you sold stock, this is what you got after the broker's commission. If you sold real estate, this is the price before closing costs.
Next, subtract your cost basis. This is what you originally paid for the asset, plus the cost of any capital improvements. For a house, capital improvements include a new roof, a deck, or a major renovation — not routine maintenance like painting or repairs. For stock, cost basis is the price you paid per share times the number of shares, plus any fees you paid to buy it.
The result is your capital gain (or loss, if the sale price was lower). If you held the asset for more than one year, this is a long-term gain. If you held it for one year or less, it is a short-term gain. The holding period is measured from the date you bought it to the date you sold it.
Short-term capital gains: taxed at your income tax rate
Short-term capital gains are added to your other income for the year and taxed at your ordinary income tax bracket. In 2024, federal income tax brackets range from 10% to 37%, depending on how much total income you have. A short-term gain of $5,000 on stock you held for six months would be added to your wages, rental income, and other income, and the combined total determines your tax rate.
This is why short-term gains are often more expensive to you than long-term gains. If you are in the 24% tax bracket, a $10,000 short-term gain costs you $2,400 in federal tax. The same $10,000 long-term gain might cost you $1,500 (at the 15% long-term rate) or even $0 (if you are in the 0% bracket).
Long-term capital gains: the three federal tax rates
Long-term capital gains are taxed at one of three federal rates: 0%, 15%, or 20%. Your rate depends on your total taxable income for the year, not on the size of the gain. The income thresholds change each year and vary by filing status.
For 2024, the 0% rate applies if your taxable income is below $47,025 (single filer) or $94,050 (married filing jointly). The 15% rate applies to income between those amounts and $518,900 (single) or $583,750 (married). Income above those thresholds is taxed at 20%. These thresholds are adjusted annually for inflation, so the numbers will be different in 2025.
The rate applies only to the long-term gain itself, not to your entire income. If you are single with $40,000 in wages and a $20,000 long-term capital gain, your first $7,025 of the gain is taxed at 0%, and the remaining $12,975 is taxed at 15%.
State and local taxes on capital gains
Most states tax capital gains as ordinary income at their state income tax rate. A few states — including Alaska, Florida, Nevada, South Dakota, Tennessee, Texas, Washington, and Wyoming — have no state income tax at all. California taxes long-term gains at the same rate as short-term gains, with no preferential rate. New York taxes capital gains at ordinary income rates as well.
Some states have recently introduced capital gains taxes that apply only to high-income earners. Washington State, for example, taxes long-term capital gains above a certain threshold at a flat 7% rate. These state taxes are separate from federal tax and are calculated independently. You will owe both federal and state tax on the same gain.
Using losses to reduce your tax bill
If you sold an asset at a loss, you can use that loss to offset capital gains you had in the same year. If you sold stock for $8,000 that you paid $10,000 for, you have a $2,000 loss. If you also sold another stock for a $5,000 gain, your net capital gain for the year is $3,000, and you pay tax only on that $3,000.
If your losses exceed your gains in a year, you can deduct up to $3,000 of the net loss against your ordinary income. Any loss beyond $3,000 carries forward to the next year, where you can use it to offset future gains or deduct another $3,000 against income. This process continues until the loss is fully used. Many investors deliberately sell losing positions late in the year to offset gains and reduce their tax bill — a practice called tax-loss harvesting.
How the IRS tracks your gains and losses
When you sell stock, bonds, or other securities through a broker, the broker reports the sale to the IRS on Form 1099-B. The form includes the sale price, the date sold, and the date acquired. If you bought the security through that same broker, the broker also reports your cost basis. The IRS receives a copy of this form and matches it against your tax return.
For real estate, you report the sale on Form 8949 and Schedule D. You will need your original purchase documents, closing statements, and records of any improvements. The IRS does not automatically receive notice of real estate sales the way it does for securities, but if you do not report a sale, the buyer's title company or the county assessor may report it, and the IRS will follow up.
Keep records of all purchases, sales, and improvements for at least three years after you file your return. If you inherited an asset, the cost basis is "stepped up" to the fair market value on the date of death, which can significantly reduce your capital gains tax if you sell it later.
Frequently Asked Questions
Do I have to pay capital gains tax if I reinvest the money?
Yes. The tax is based on the gain itself, not on what you do with the proceeds. If you sell stock for a $10,000 gain and immediately buy different stock with the money, you still owe tax on the $10,000 gain. The only exception is if you sell real estate and reinvest in another property under Section 1031 of the tax code, which allows you to defer the tax — but this requires specific timing and rules.
What if I sold an asset at a loss — do I get a refund?
No refund, but you can use the loss to reduce other income. You can deduct up to $3,000 of net capital losses against your ordinary income in a single year. If your loss is larger, the excess carries forward to future years. If you have no gains or income to offset, the loss sits on your return until you have gains in a future year.
How do I know if my gain is short-term or long-term?
Count the days from the date you bought the asset to the date you sold it. If it is one year or less, it is short-term. If it is more than one year, it is long-term. The IRS counts the purchase date as day zero, so if you bought on January 1 and sold on January 2 of the next year, that is more than one year and qualifies as long-term.
Can I reduce my capital gains tax by donating the asset to charity instead of selling it?
Yes, and it is often the most tax-efficient choice. If you donate appreciated stock or real estate directly to a may have access to charity, you avoid the capital gains tax entirely and can deduct the fair market value of the asset as a charitable contribution. You get the deduction without paying tax on the gain. This works only if you donate the asset itself, not the proceeds from selling it.
What happens to capital gains tax if I inherit an asset?
Your cost basis is "stepped up" to the fair market value on the date of the person's death. If someone bought stock for $10,000 and it was worth $50,000 when they died, your cost basis is $50,000. If you sell it immediately for $50,000, you have no gain and owe no tax. This step-up applies to most inherited assets, including real estate, stocks, and bonds.