How Is Capital Gains Tax Calculated? Cost Basis, Holding Periods, and Real Examples
Your tax bill on an investment sale isn't always just sale price minus purchase price. Here's how cost basis, holding periods, and a few other pieces actually combine to set your capital gains tax.
This article provides general educational information only and is not tax, legal, or financial advice. Tax rates, thresholds, and rules change periodically with legislation and inflation adjustments. Confirm current IRS figures and any state-specific rules with a qualified adviser before making decisions.
You buy an investment for one price. Later, you sell it for more. It seems like your tax bill should just be the difference between those two numbers.
Sometimes it is. Often it isn't quite that simple. Your cost basis, how long you held the investment, and a few other details can all change the final number. None of this is complicated once you see the pieces laid out. It's just more pieces than most people expect.
The three numbers behind every gain
Nearly every capital gains calculation starts with the same three numbers: what you paid for the asset, what you sold it for, and how long you owned it.
The basic formula is:
Capital Gain = Sale Price − Adjusted Cost Basis
The holding period doesn't change that gain at all. What it changes is how the gain gets taxed, which we'll come back to in a moment.
Cost basis isn't always what you paid
This is where most of the confusion starts. Cost basis usually begins with your purchase price, but it doesn't always stay there.
A few common things can adjust it. Commissions and other acquisition or selling costs you paid can factor in. Major improvements you made to a property, like a renovation, generally get added to your basis. Routine repairs, however, generally do not increase basis, so it's important to distinguish between an improvement that adds lasting value and a repair that simply maintains the property's current condition. Reinvested dividends are another one worth knowing about: if you're enrolled in a dividend reinvestment plan, each reinvested dividend is treated as a small new purchase, and it adds to your overall basis in that investment, the same way buying more shares outright would.
All of these adjustments work in your favor. They increase your basis, which lowers the gain you're taxed on, since the government only taxes the actual increase in your investment, not money you already put in.
A full example, start to finish
Here's how it looks with real numbers.
Say you buy shares for $20,000, and you pay $100 in commissions to buy them. Your adjusted cost basis is $20,100.
Later, you sell the shares for $32,000, but you pay $150 in commissions to sell. Your sale proceeds, after costs, come to $31,850.
Subtract your adjusted cost basis from your sale proceeds: $31,850 minus $20,100 leaves a capital gain of $11,750.
That's the whole calculation. The math itself is addition and subtraction. The part that takes more care is making sure you've included every adjustment that actually applies to your basis.
Why holding period matters
How long you owned an investment decides which set of tax rules applies to your gain.
Generally, if you held the asset for one year or less before selling, the gain is short-term. If you held it for more than one year, the gain is long-term. The gain itself stays exactly the same either way. Only the tax treatment changes.
Long-term gains are generally taxed at lower rates than short-term gains under federal rules. For 2026, long-term capital gains are taxed at 0%, 15%, or 20%, depending on your income and filing status. Short-term gains are taxed at your regular income tax rate instead, which can run quite a bit higher. These rates are adjusted periodically for inflation, so confirm current figures with the IRS or a qualified adviser. The exact rate that applies to you depends on details specific to your situation, which is exactly what a calculator is useful for.
Why your taxable gain isn't always your real profit
Here's something that surprises a lot of people the first time they run the numbers.
Say you bought a property for $100,000. Over the years, you spent $40,000 on real improvements, a new roof, an addition, a major renovation. Later, you sell the property for $170,000.
Your economic profit, the actual extra money in your pocket, is $30,000: the $170,000 sale price, minus the $100,000 you paid, minus the $40,000 you spent improving it.
Surprisingly, your taxable gain matches this exact economic profit, $30,000, rather than the raw $70,000 price difference, because the roof and renovation work raised your adjusted cost basis from $100,000 to $140,000. The IRS only taxes the gain above that adjusted basis.
This is exactly why adjusted cost basis matters so much. Skip the adjustment, and you'd think you owe tax on a much bigger number than you actually do.
What happens if you sell at a loss
A lot of people assume a loss just disappears once it happens. It doesn't.
If you sell an investment for less than your adjusted cost basis, you have a capital loss. That loss can offset capital gains you had elsewhere, which lowers your overall taxable gain for the year. If your losses are bigger than your gains, up to $3,000 of the remaining loss can offset ordinary income per year under current federal law. This limit may differ under state law, so don't assume the federal figure applies everywhere. Anything left over after that doesn't just vanish either. It generally carries forward, so you can use it in a future year.
This is a real and useful part of the tax code, but it has its own detailed rules. Treat this section as an introduction, not a full guide to using losses strategically.
Why two people can owe different tax on the same profit
This is one of the clearest ways to see how all these pieces fit together.
Picture two people, each with a $15,000 gain on an investment.
Person A held their investment for 8 months before selling. Because that's a year or less, the gain is short-term, and it gets taxed at their regular income tax rate.
Person B held a similar investment for 3 years before selling. Because that's more than a year, the gain is long-term, and it gets taxed at the lower long-term rate instead.
Same profit. Different tax treatment, just because of how long each person waited to sell.
Holding period isn't the only thing that can make two people's tax bills differ on the same size gain. Income level and filing status both affect which rate applies. Some states tax capital gains on top of the federal tax, while others don't tax it at all. And certain sales, like a primary home that qualifies for an exclusion, can reduce or even erase the taxable gain entirely.
It's worth knowing this isn't only a federal question. States don't all treat capital gains the same way. Some tax it just like any other income. Others have no state income tax at all, which usually means no state-level capital gains tax either. If you're trying to estimate your full tax bill, not just the federal piece, your state matters just as much as your income and holding period do.
A few situations with their own rules
A handful of situations come up often enough that they're worth knowing exist, even though each one has its own detailed rules beyond what we can cover here.
Selling inherited property. When you inherit an asset, your cost basis is generally adjusted to the asset's value at the time you inherited it, a rule often called a stepped-up basis. In many cases, this can significantly reduce the taxable gain if you sell soon after inheriting. However, not every inherited asset receives a stepped-up basis, for example, certain assets held in irrevocable trusts or subject to special tax rules may be treated differently. If you're dealing with an inherited asset, confirm the basis rules that apply with a tax professional.
Selling your primary home. Many homeowners can exclude a portion of their gain when selling a primary residence, as long as they meet IRS requirements around ownership and how long they lived there. Under current federal rules, qualifying single filers may exclude up to $250,000 of gain, and qualifying married couples filing jointly may exclude up to $500,000. This exclusion is a major reason many home sales don't trigger much, or any, capital gains tax.
Receiving property as a gift. Property you receive as a gift generally keeps the original giver's cost basis, rather than resetting to the value on the day you received it. That's a different rule than inherited property, which is exactly why it's worth knowing the two aren't treated the same.
Crypto and other digital assets. The IRS generally treats cryptocurrency as property, not currency, for tax purposes. That means selling, trading, or otherwise disposing of crypto can trigger a capital gain or loss, calculated the same basic way as a stock sale.
Each of these has real complexity behind it. The goal here is awareness, knowing these special rules exist so you know to look closer when one applies to you, not a full guide to any single one.
Quick answers
Do you pay capital gains tax if you don't sell? Generally no. Gains are usually taxed when you actually sell or otherwise dispose of an asset, not while you're simply holding it and its value goes up on paper.
What if I sell at a loss? A capital loss can offset gains you had elsewhere, and within IRS limits, up to $3,000 per year can offset ordinary income at the federal level.
Does reinvesting the money avoid the tax? Usually no. Simply reinvesting your sale proceeds into something else doesn't eliminate the tax on the original sale for most investments.
Do states tax capital gains? Some do, taxing it like ordinary income. Others don't, often because they have no state income tax at all. It varies a lot by state.
Can home improvements reduce the tax when I sell? Often yes, since qualifying improvements generally increase your cost basis, which lowers your taxable gain when you sell. Routine repairs generally don't count.
The bottom line
Most capital gains calculations follow the same basic path. Start with your adjusted cost basis. Subtract it from your sale proceeds to get your gain. Then figure out whether that gain is short-term or long-term, since that decides how it's taxed.
The math itself is usually simple addition and subtraction. The part that takes real care is making sure you've got the right numbers in the first place, especially your adjusted basis.
Once you understand how the calculation works, our Capital Gains Tax Calculator can give you a starting estimate based on your own numbers, your income, your state, and your holding period.