The basic formula: sale price minus what you paid, times your tax rate

Capital gains tax is calculated on the profit you make when you sell an investment or property. The profit itself — called your capital gain — is the difference between what you paid for the asset and what you sold it for, minus any costs directly tied to the sale (like broker fees or title transfer costs).

The tax you owe depends on two things: how much your gain is, and how long you held the asset. If you held it for one year or less, the gain is taxed as short-term capital gain, which means it's taxed at your ordinary income tax rate — the same rate as your salary or wages. If you held it for more than one year, it's a long-term capital gain, and the tax rate is lower: either 0%, 15%, or 20%, depending on your total income for the year.

The math is straightforward: take your sale price, subtract your original purchase price and any sale costs, and you have your gain. Then multiply that gain by the tax rate that applies to you.

Key Takeaways

  • Your capital gain is the sale price minus your purchase price and selling costs — not the total sale price.
  • Short-term gains (held one year or less) are taxed at your ordinary income tax rate, which is higher than long-term rates.
  • Long-term gains (held more than one year) are taxed at 0%, 15%, or 20% depending on your total taxable income for the year.
  • You report capital gains on Schedule D (Form 1040) when you file your tax return, and the IRS matches it to your brokerage records.
  • Losses can offset gains dollar-for-dollar, and unused losses can carry forward to future years.

Short-term versus long-term: why the holding period matters

The IRS draws a hard line at one year. If you sell an asset you've owned for 365 days or less, any profit is a short-term capital gain. If you sell after holding it for more than one year, it's long-term. This distinction can mean a significant difference in what you owe.

Short-term gains are taxed at your marginal tax rate — the same rate applied to your wages or business income. For 2024, that ranges from 10% to 37% depending on your income bracket. Long-term gains are taxed at preferential rates: 0% if your taxable income is below a certain threshold, 15% for most middle-income filers, or 20% for high earners. The income thresholds that determine which rate applies to you change each year.

This is why timing matters. If you're close to the one-year mark on a holding period and you're in a high tax bracket, waiting a few months to cross into long-term status can reduce your tax bill substantially. Conversely, if you have losses to harvest, you might want to sell before the one-year mark to offset short-term gains.

The step-by-step calculation with a real example

Say you bought 100 shares of a stock for $50 per share in March 2023, spending $5,000 total. You sold those shares in April 2024 for $75 per share, receiving $7,500. Your broker charged a $10 commission on the sale.

Your capital gain is calculated as follows:

  1. Sale proceeds: $7,500
  2. Minus original purchase price: $5,000
  3. Minus selling costs (commission): $10
  4. Your capital gain: $2,490

Because you held the stock for more than one year (March 2023 to April 2024), this is a long-term gain. If your taxable income for 2024 puts you in the 15% long-term capital gains bracket, you owe $2,490 × 0.15 = $373.50 in federal capital gains tax on this sale. (You may also owe state tax, which varies by location.)

If you had sold the same stock in September 2023 instead — only six months after purchase — the gain would still be $2,490, but it would be taxed as short-term. If your ordinary income tax rate is 24%, you'd owe $2,490 × 0.24 = $597.60, a difference of $224.

How losses offset gains and carry forward

Capital losses work in your favor. If you sell an investment at a loss, you can use that loss to reduce your capital gains dollar-for-dollar. If you have $5,000 in long-term gains and $2,000 in long-term losses in the same year, your net long-term gain is $3,000, and you're taxed only on that $3,000.

If your losses exceed your gains in a year, you can deduct up to $3,000 of the excess loss against your ordinary income (wages, salary, interest, etc.). Any remaining loss carries forward to the next tax year, where it can offset future gains or ordinary income again. This carryforward continues indefinitely until the loss is fully used.

This is the basis for tax-loss harvesting — a strategy where you deliberately sell a losing investment to capture the loss, then buy a similar (but not identical) investment to maintain your market exposure. The loss reduces your tax bill in the current year, while you stay invested. The IRS has a "wash sale" rule that prevents you from buying back the exact same security within 30 days before or after the sale, so the similar-but-not-identical purchase matters.

Reporting capital gains on your tax return

You report all capital gains and losses on Schedule D (Form 1040), which you file along with your main tax return. Schedule D asks you to list each transaction separately: the asset, the date you bought it, the date you sold it, your cost basis, your sale price, and your gain or loss.

Most people don't fill this out by hand. If you use a brokerage account (stocks, mutual funds, ETFs), your broker sends you a Form 1099-B each January showing all your sales from the previous year. You can read this from your brokerage account or have it mailed to you. If you use tax software like TurboTax or H&R Block, you can import the 1099-B directly, and the software populates Schedule D for you.

The IRS receives a copy of your 1099-B as well, so they can cross-check your reported gains against what your broker reported. If the numbers don't match, you'll hear about it. This is why accuracy matters, even on small transactions.

Cost basis: what you actually paid, including reinvested dividends

Your cost basis is not always just the price you paid per share times the number of shares. It includes any fees you paid to buy the investment, and it includes reinvested dividends and capital distributions.

If you own a mutual fund and you've chosen to reinvest dividends automatically, each dividend payment bought you additional shares at the price on that dividend date. When you sell the fund, your cost basis includes the original purchase price plus the cost of all those reinvested shares. Your broker tracks this for you and reports it on the 1099-B, but you should verify it, especially if you've owned the investment for many years.

You can also choose how to calculate cost basis if you have multiple purchases of the same security. The most common methods are "first in, first out" (FIFO), where you assume you sold the oldest shares first, and "specific identification," where you specify which shares you're selling. Specific identification often results in a lower tax bill because you can choose to sell the shares with the highest cost basis, leaving the lower-basis shares in your account. Your broker can help you elect this method when you place a sell order.

State and local taxes on capital gains

Federal capital gains tax is only part of the picture. Most states tax capital gains as ordinary income, meaning your state tax rate applies 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, so residents pay only federal capital gains tax.

Some states have special rates for capital gains. California, for example, taxes long-term capital gains at the same rate as ordinary income, which can be as high as 13.3%. New York taxes them as ordinary income too, up to 10.9%. Other states explore a flat rate or a lower rate than ordinary income.

A few cities and counties also impose local income taxes that explore to capital gains. New York City, for instance, adds a local tax on top of state and federal. If you live in a high-tax state or city and you're considering a large sale, it's worth calculating your total tax burden — federal plus state plus local — before you sell.

When to consider professional information

For a single stock sale or a small mutual fund redemption, the calculation is straightforward enough to handle yourself. But certain situations warrant a conversation with a tax professional or financial advisor before you sell:

If you're selling a large position and the gain is substantial, a tax advisor can model different timing strategies — selling this year versus next year, or spreading the sale across two years — to see which minimizes your total tax. If you have significant losses to harvest, they can help you structure the sales to maximize the benefit. If you own real estate, inherited assets, or investments held in a trust, the cost basis calculation becomes more complex, and mistakes can be costly.

A tax professional can also help you understand the impact of capital gains on other parts of your return. Large gains can push you into a higher tax bracket, which can affect your may be able to access for certain deductions or credits, or increase your Medicare premiums if you're on Medicare. These ripple effects are worth understanding before you commit to a sale.

Frequently Asked Questions

Do I owe capital gains tax if I sell at a loss?

No. If you sell an investment for less than you paid for it, you have a capital loss, not a gain. You don't owe tax on a loss. Instead, you can use the loss to reduce any capital gains you have in the same year, or to reduce up to $3,000 of your ordinary income. Any unused loss carries forward to future years.

What if I inherit an investment — do I owe capital gains tax when I sell it?

Inherited investments receive a "step-up in basis," meaning your cost basis is the value of the investment on the date of the person's death, not what they originally paid for it. If you sell shortly after inheriting it, you typically owe little or no capital gains tax. This is a major tax advantage of inherited assets and is one reason to hold inherited investments for at least a short time before selling.

How do I know if my gain is short-term or long-term?

Count the days from the purchase date to the sale date. If it's 365 days or fewer, it's short-term. If it's more than 365 days, it's long-term. The IRS counts the purchase date as day zero, so if you buy on January 1 and sell on January 2 of the next year, that's short-term. You need to hold until January 2 of the year after that for it to be long-term.

Can I deduct investment losses against my salary or wages?

Yes, but only up to $3,000 per year. If you have more than $3,000 in net capital losses, the excess carries forward to future years, where you can deduct another $3,000 against ordinary income, and so on until the loss is exhausted. Capital losses can't reduce your ordinary income by more than $3,000 in any single year.

What happens if I don't report a capital gain?

The IRS will likely catch it. Your broker sends Form 1099-B to both you and the IRS, so the IRS knows about the sale. If your tax return doesn't report the gain, the IRS will send you a notice and bill you for the unpaid tax plus interest and penalties. It's much better to report it correctly the first time.