Capital Gains Tax on Investments

Last updated July 2026

Short answer

Capital gains tax is the tax on the profit when you sell an investment for more than you paid. The gain is your sale price minus your cost basis, and it is taxed only when the gain is realized, meaning only when you actually sell. A gain on paper, an unrealized gain, is never taxed while you hold. The rate turns on one line: hold an asset one year or less and the gain is short-term, taxed at your ordinary income rate; hold it longer than one year and it is long-term, taxed at the lower 0, 15, or 20 percent rates. Capital losses offset gains dollar for dollar, and up to 3,000 dollars of net loss a year can offset ordinary income, with the rest carried forward. Gains inside a 401k or IRA are not taxed yearly. Walnut, an AI investing app, can show you how your positions have moved, but it is not an investment adviser or a tax adviser. This is general information, not tax advice.

Capital gains tax is the single tax most investors will meet, and it is far less complicated than it sounds once you know the handful of rules that drive it. This guide covers what a capital gain actually is, the difference between a realized and an unrealized gain, why the one-year holding line matters so much, how losses reduce your bill, when the tax comes due, and why none of it applies year to year inside a retirement account. It is descriptive and educational, not a set of buy or sell calls, and it is not tax advice. Rates and dollar limits change over time, so verify current figures with the IRS or a licensed professional.

What a capital gain is: realized vs unrealized

A capital gain is simply the profit on an investment: what you sold it for minus what you paid, your cost basis. If you buy a stock at 100 dollars and sell it at 160, you have a 60 dollar capital gain. The crucial distinction is whether that gain is realized or unrealized. It is unrealized while you still own the asset, no matter how far it has risen, and the US does not tax unrealized gains. It becomes realized the moment you sell, and only then is it taxable.

This is why buy-and-hold investing is naturally tax-efficient. Every year you hold rather than sell is a year the gain stays unrealized and untaxed, so the money that would have gone to tax keeps compounding for you. It also means you have some control over timing: because the tax is tied to the sale, you decide which tax year the gain lands in. None of this is a reason to hold or sell any particular position; it is context, and your own circumstances may differ.

The one-year line: short-term vs long-term

When you do sell at a profit, how long you held the asset decides the rate. A gain on something held one year or less is a short-term capital gain, taxed at your ordinary income rate, the same brackets that apply to your wages. A gain on something held longer than one year is a long-term capital gain, taxed at the lower long-term rates of 0, 15, or 20 percent for most filers, based on your taxable income.

That difference can be large. A high earner might pay a much higher rate on a short-term gain than on the exact same gain held a few extra weeks to cross the one-year mark. This is why the holding period is one of the most practical things to check before selling a winner in a taxable account. The precise numbers behind the long-term rates, and the income thresholds that set them, are covered in capital gains tax rates, and those thresholds adjust every year, so verify current figures. This is not tax advice.

How losses offset gains, dollar for dollar

Losses are part of the same system, and they have real value. When you sell an investment for less than you paid, the resulting capital loss offsets your capital gains dollar for dollar. If you realized 5,000 dollars of gains and 3,000 dollars of losses in a year, you are taxed on 2,000 dollars of net gain, not the full 5,000. Short-term losses net against short-term gains first, and long-term against long-term, before the two categories combine.

If your losses exceed your gains, the tax code lets the excess do more work. You can deduct up to 3,000 dollars of net capital loss against your ordinary income in that year, and carry any remaining loss forward to future tax years, where it offsets future gains or another 3,000 dollars of income annually until it runs out. This mechanism is the engine behind tax-loss harvesting, with the wash-sale rule as its main constraint. Consult a tax professional before acting.

When the tax is due

Capital gains tax is owed for the tax year in which you sell and realize the gain, and it is reported on that year's return. There is no tax while you simply hold, and no partial tax for a gain that has built up over several years but has not been sold; the entire realized gain is taxed in the one year you sell. For most investors, capital gains flow into their annual return, though those with large gains may owe estimated quarterly payments.

Because the tax is tied to the sale date, the timing of when you sell is what you control. Selling in December versus waiting until January can move a gain from one tax year to the next, and holding a few extra weeks to cross the one-year mark can move a gain from ordinary rates to the lower long-term rates. These are genuinely individual decisions that depend on your income and full picture, so treat this as a framework and confirm the specifics with a tax professional.

Gains inside a 401k or IRA are not taxed yearly

Everything above describes a taxable brokerage account. Inside a tax-advantaged account, capital gains tax as such does not apply year to year. In a traditional 401k or IRA you can sell at a profit as often as you like with no yearly capital gains tax; you pay ordinary income tax only when you withdraw in retirement. In a Roth IRA, qualified withdrawals, including every dollar of gain, come out entirely tax-free.

This is why the account a position sits in changes its tax treatment completely. A holding you expect to trade or rebalance often can generate a string of taxable gains in a brokerage account, yet none inside a retirement account. Deciding what belongs where is the practice of tax-efficient investing, and the right split depends on your income and goals. This is general information, not tax advice.

Short-term vs long-term, at a glance

Held one year or lessHeld more than one year
Holding periodOne year or lessMore than one year
NameShort-term capital gainLong-term capital gain
Taxed atYour ordinary income rate (same as wages)Lower long-term rates: 0, 15, or 20 percent for most filers
When dueIn the tax year you sellIn the tax year you sell
Inside a 401k or IRANot taxed yearlyNot taxed yearly

The structure is simple: the tax applies only when you sell, and the longer you held, the lower the rate tends to be. Short-term gains ride your ordinary brackets; long-term gains get the reduced 0, 15, or 20 percent schedule; and inside a retirement account neither is taxed as it happens. Every figure here can change from year to year and depends on your individual circumstances, so verify current details with the IRS or a licensed professional before making any decision.

Where Walnut fits

Reasoning about capital gains means knowing how far each holding has moved from what you paid and how long you have held it, which is a question about your real positions rather than a generic rule. That is where an AI assistant that can read across your accounts helps. Walnut lets you connect any major US broker, then chat in plain words through Claude, ChatGPT, or its built-in AI to see how each position has performed and which ones carry the largest gains or losses. You can build baskets around a plan, track every position against the S&P 500, and place trades that Walnut only sends to your broker after you approve them. It reads your accounts by default and does not move money on its own. Walnut is not an investment adviser or a tax adviser, it does not calculate your tax, and it does not tell you what to buy.

Try Walnut on top of your broker

Walnut connects your accounts, then helps you see how each position has moved and which carry the largest gains or losses, by chatting through Claude, ChatGPT, or its built-in AI. Walnut is not an investment adviser or a tax adviser and does not tell you what to buy.

FAQ

What is capital gains tax?

Capital gains tax is the tax on the profit when you sell an investment for more than you paid for it. The gain is the sale price minus your cost basis, and it is taxed only in the year you sell. If you held the asset one year or less the gain is short-term and taxed at your ordinary income rate; if you held it longer than one year it is long-term and taxed at the lower long-term rates. This is general information, not tax advice.

What is the difference between realized and unrealized gains?

An unrealized gain is a profit on paper: your investment is worth more than you paid, but you still own it. It is not taxed. A realized gain happens when you actually sell and lock in the profit, and that is the moment capital gains tax applies. A stock can rise for years with no tax owed as long as you keep holding it; selling is what triggers the bill. This is descriptive, not tax advice.

When do I have to pay capital gains tax?

You owe capital gains tax for the tax year in which you sell the investment and realize the gain, and you report it on that year's return. There is no tax while you simply hold, no matter how much the value rises. Because it is tied to the sale, the timing of when you sell, and whether you have crossed the one-year mark for the lower rate, is what controls the bill. Verify current details and consult a tax professional.

How do capital losses offset gains?

Capital losses offset capital gains dollar for dollar. If you have 5,000 dollars of gains and 3,000 dollars of losses, you are taxed on 2,000 dollars of net gain. If your losses exceed your gains for the year, you can deduct up to 3,000 dollars of the excess against ordinary income, and carry the rest forward to future years. This netting is the basis of tax-loss harvesting. Consult a tax professional for your situation.

How much of my losses can I deduct in a year?

After your capital losses cancel out your capital gains, you can use up to 3,000 dollars of any remaining net loss to reduce your ordinary income in that tax year (1,500 dollars if married filing separately). Anything above that limit carries forward to future years, where it can offset future gains or another 3,000 dollars of income each year until it is used up. Verify current figures with the IRS or a tax professional.

Are capital gains taxed in a 401k or IRA?

Not year to year. Selling at a profit inside a traditional 401k or IRA triggers no capital gains tax; you can trade freely and pay ordinary income tax only when you withdraw in retirement. Inside a Roth IRA, qualified withdrawals including all the gains are tax-free. Capital gains tax as described here applies to a taxable brokerage account. This is general information, not tax advice.

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

Yes. If you sell an investment at a profit in a taxable account, the gain is taxed for that year even if you immediately reinvest the proceeds into another investment. The tax is triggered by the sale, not by what you do with the cash afterward. The one exception is trades inside a tax-advantaged account, where no yearly capital gains tax applies. Consult a tax professional.

Does Walnut calculate my capital gains tax?

No. Walnut is not a registered investment adviser or a tax adviser, and it does not prepare returns or tell you what to buy or sell. It can read your connected accounts so you can see, in plain words, how each holding has moved and which positions carry large gains or losses, which is useful context for a conversation with a tax professional. Your official figures come from your brokerage tax forms.

From here, see the actual rate brackets in capital gains tax rates, how the gain is measured in what is cost basis, the loss strategy in tax-loss harvesting, and the broader picture in how stocks are taxed.

Walnut is informational and is not a registered investment adviser or a tax adviser. This page explains how capital gains tax works in general; it is not a recommendation to buy, sell, or hold any security, and it is not tax advice. Investing involves risk, including the possible loss of principal, and past performance does not indicate future results. Tax rules, rates, brackets, and dollar limits change and depend on your individual circumstances; verify current details with the IRS or a licensed professional before making any decision. Do your own research or consult a licensed financial or tax professional.

Related articles

    Capital Gains Tax on Investments: How It Works (2026), Walnut