Skip to content

Capital Gains Tax When You Sell: The Arithmetic of a Sale

A gain is not taxed when the price rises, only when the position is sold — and the rate applied depends on how long it was held. This walkthrough covers cost basis, holding periods, loss offsets, and the after-tax arithmetic of a single sale.

By the editorial team at The Long View How we check our guides 11 min read
A person reviewing printed account statements at a kitchen table with a pen and a calculator nearby

One of the most common misunderstandings in investing is when tax on an investment gain is actually triggered. It is not when the price rises. A paper gain sitting in an account is not a taxable event in most jurisdictions; the tax arises when the position is sold, and the amount taxed is the difference between what was received and what the asset originally cost. This guide sets out the mechanics with a worked example, then covers the provisions that most often change the answer.

Cost basis: the number most people get wrong

Cost basis is the total amount you paid to acquire the position, including the purchase price plus any commissions or fees directly attributable to the acquisition. It is the anchor for the whole calculation.

Gain or loss on a sale is:

Gain (or loss) = proceeds − cost basis, where proceeds is the sale price times the quantity, minus any selling costs, and cost basis is the total acquisition cost.

Two points follow immediately. Fees on both sides of the trade reduce the taxable gain, because they reduce proceeds (on the way out) or increase basis (on the way in). And the calculation is done per sale, against the basis of the specific shares sold — which matters once you have bought the same security more than once at different prices.

Worked example: one sale, two tax rates

Assume a simplified jurisdiction with two brackets for investment gains — a lower rate for positions held long enough to qualify, and a higher rate that treats the gain as ordinary income. Real jurisdictions differ in detail; the point here is the structure of the arithmetic, not the specific rates.

  • Bought 100 shares at $40.00 each: cost basis = 100 × $40.00 = $4,000
  • Sold all 100 shares at $62.00 each: proceeds = 100 × $62.00 = $6,200
  • Holding period: long enough to qualify for the lower rate

The gain is $6,200 − $4,000 = $2,200, which is 55% of the $4,000 basis. Now apply the two possible rates:

TreatmentRateTaxNet proceedsAfter-tax return on $4,000
Long-term (qualifying holding period)15%$330$5,87046.8%
Short-term (ordinary)22%$484$5,71642.9%

Read the last column carefully, because this is where the difference bites. Under the long-term rate the after-tax return is $5,870 ÷ $4,000 − 1 = 46.8%. Under the short-term rate it is $5,716 ÷ $4,000 − 1 = 42.9%. The pre-tax gain was 55% in both cases; the holding period alone accounts for roughly 4 percentage points of the outcome. On the same trade, the difference in tax is $484 − $330 = $154.

The pre-tax return is identical. Only the holding period and the resulting rate differ.

Losses, and how they offset gains

A loss is the same calculation with a negative sign, and in most systems realised losses can offset realised gains within the same period. If in the same year you sold one position at a $2,200 gain and another at a $1,500 loss, the net taxable gain falls to $2,200 − $1,500 = $700, and at the long-term rate the tax is $700 × 15% = $105.

Many systems go further and allow excess losses to be carried forward to future years, or to offset a limited amount of ordinary income. The rules differ substantially by jurisdiction, including how long a carry-forward lasts and whether it is adjusted for inflation. The practical implication is that the timing of a sale can matter as much as the price at which it happens.

Things that change the answer

  • Reinvested distributions. Each reinvested dividend or distribution creates a new lot with its own basis and its own holding-period clock, even though no new money was contributed.
  • Wash sale and similar rules. Some jurisdictions deny a loss if a substantially identical security is bought back within a defined window, to prevent selling purely for the tax deduction. Where they apply, they replace the loss rather than remove it — the disallowed amount is typically added to the basis of the replacement position.
  • Tax-advantaged accounts. Gains inside a retirement account are generally not taxed on each sale; instead the account is taxed when money is withdrawn, under whatever rules apply to that account type.
  • Exemptions and thresholds. Some jurisdictions exempt a band of gains entirely, or apply a lower rate to a first slice, which means the same gain can face an effective rate well below the headline one.
  • Currency. Where a security is priced in a foreign currency, the taxable gain may be computed in the reporting currency, so the exchange rate at purchase and sale becomes part of the calculation.

What this does not decide

Nothing here says whether to sell. A high tax bill on a position that has done well is not a reason to keep holding it, and a low tax bill is not a reason to keep a holding that no longer fits. The arithmetic simply prices the decision: a sale converts a paper gain into a known after-tax amount, and that number is the one to compare against whatever the money would be used for instead.

The total return guide explains why the taxable part is only one component of a return, and the retirement account comparison covers how the wrapper changes what arrives after tax. The articles page indexes the archive and the tools page has calculators for the figures above.

This guide is general educational information, and it is neither financial, tax, nor legal advice. It recommends no specific security, fund, or provider, and it describes no individual's situation. All rates, brackets, thresholds and holdings above are simplified illustrations with the assumptions stated; they are not current rates for any jurisdiction and do not depict any real investor's outcome. Capital gains rules — including rates, holding periods, loss offsets, wash sale provisions, exemptions and reporting requirements — vary widely by jurisdiction and change over time, so verify against current official guidance and consult a licensed tax professional about your own circumstances before acting.