Selling an investment for a profit feels simple until tax time, when the date you bought it, the date you sold it, your taxable income, and your other capital gains or losses can all change the result. A capital gains tax calculator helps turn those moving parts into an estimate before you sell, so you can compare what might happen if a gain is short-term, long-term, offset by losses, or large enough to interact with the 3.8% net investment income tax.

The formula in plain language

The starting formula is straightforward: capital gain equals sale proceeds minus adjusted cost basis. In everyday terms, sale proceeds are what you receive after the sale, while adjusted basis usually starts with what you paid and may include commissions, reinvested dividends, improvements for certain property, or other adjustments. The IRS says a capital gain exists when you sell a capital asset for more than your adjusted basis, and a capital loss exists when you sell for less than your adjusted basis (IRS, 2026).

The second variable is holding period. If you held the asset for one year or less, the gain is usually short-term. If you held it for more than one year, the gain is usually long-term. The IRS explains that the holding period generally starts the day after you acquire the asset and includes the day you dispose of it (IRS, 2026). That one-day difference can matter because net short-term gains are taxed as ordinary income, while most net long-term capital gains use preferential 0%, 15%, or 20% federal rates.

The third variable is your broader tax picture. A calculator has to know filing status, taxable income before the sale, expected gain, and capital losses because long-term capital gains stack on top of other taxable income. For 2025 tax years, the IRS lists the 0% long-term capital gains threshold at taxable income of $48,350 or less for single filers and $96,700 or less for married couples filing jointly, with the 20% rate applying above the top 15% bracket thresholds (IRS, 2026). Thresholds can change each tax year, and state taxes may apply, so treat any estimate as a planning number, not a final tax bill.

A worked example

Assume Maria is a single filer who bought shares in a taxable brokerage account for $20,000 and sells them for $32,000 after brokerage costs. Her capital gain is $12,000. She has $70,000 of taxable income before counting the gain and no capital losses.

If Maria held the shares for 10 months, the $12,000 gain is short-term. Because net short-term capital gains are taxed as ordinary income, the gain is added to her taxable income and taxed through her ordinary federal brackets. The calculator would estimate the added federal tax by applying the ordinary income brackets that match her filing status and tax year, then show that her after-tax gain depends on her marginal bracket.

Read also: How to Report Investment Income on Your Tax Return

If Maria held the same shares for 14 months, the gain is usually long-term. Her taxable income including the gain would be $82,000. Using the IRS long-term capital gains framework for 2025, a single filer at that income level would generally fall in the 15% long-term capital gains range for most common investment gains, so the estimated federal capital gains tax on the $12,000 gain would be about $1,800 before considering state tax or special rules. That leaves an after-tax federal gain of about $10,200.

Now add losses. If Maria also sold another investment at a $3,000 capital loss in the same year, her net gain would fall from $12,000 to $9,000. The calculator should apply the loss against gains first. If capital losses exceed capital gains, the IRS generally lets taxpayers deduct the lesser of $3,000, or $1,500 if married filing separately, or the total net loss against other income, with unused losses carried forward (IRS, 2026).

What the calculator cannot know by itself

Some assets do not fit the simple stock-and-fund example. The IRS notes exceptions where certain gains can be taxed at rates above 20%, including some qualified small business stock, collectibles such as coins or art, and unrecaptured section 1250 real estate gain (IRS, 2026). IRS Publication 550 also covers investment income issues that can affect reporting, including dividends, mutual funds, bonds, options, and other investment transactions (IRS Publication 550, 2025).

High-income households also need to watch the net investment income tax. The IRS states that a 3.8% NIIT may apply to individuals with net investment income above threshold amounts, including $200,000 for single filers and $250,000 for married couples filing jointly (IRS, 2026). A calculator can flag that possibility, but a CPA or qualified tax professional should review cases involving large gains, business ownership, real estate, stock options, cryptocurrency, or multistate tax exposure.

Use the estimate as a decision aid: compare selling now versus after the one-year mark, test how losses change the result, and set aside cash before the tax bill arrives. This article is educational and is not personalized tax, legal, or investment advice.