Capital Gains Calculator

Disclaimer: This calculator is provided for informational and educational purposes only and does not constitute financial, medical, legal, or other professional advice. Always consult a qualified professional before making decisions based on these results.

The Legal and Financial Mechanics of Capital Gains Taxation

A capital gain arises when a capital asset (public equities, mutual funds, exchange-traded funds, corporate bonds, real estate, cryptocurrency, precious metals, or private business equity) is sold or exchanged for a price exceeding its adjusted cost basis. Under the United States Internal Revenue Code (IRC Sections 1221 and 1222) and international tax jurisprudence, capital gains are categorized according to holding period:

  • Short-Term Capital Gains: Assets held for one year or less (365 days or fewer). Short-term gains receive zero preferential tax treatment and are taxed at ordinary income tax rates (ranging from 10% to 37% at the federal level).
  • Long-Term Capital Gains: Assets held for more than one year (at least 366 days). Long-term gains benefit from preferential statutory tax rate brackets: 0%, 15%, or 20%, depending on the taxpayer's taxable income and filing status.

Mathematical Formulation of Net Capital Gain and Adjusted Basis

The realized capital gain or loss is determined by deducting the adjusted cost basis and allowable transaction fees from the gross sales proceeds:

1. Adjusted Cost Basis Equation:
Adjusted Basis = Original Purchase Price + Brokerage Commissions + Capital Improvements (for Real Estate) − Depreciation Claimed

2. Realized Capital Gain / Loss:
Realized Gain/Loss = Gross Sale Proceeds − Selling Commissions/Closing Costs − Adjusted Cost Basis

3. Net Capital Gains Tax Liability:
Total Tax = (Long-Term Gain × LTCG Rate) + (Short-Term Gain × Ordinary Tax Rate) + (Net Investment Income × 3.8% NIIT) + State Tax

Federal Long-Term Capital Gains Tax Rate Brackets

LTCG Tax Rate Single Filers Taxable Income Married Filing Jointly (MFJ) Head of Household (HOH)
0% Tax Rate $0 – $47,025 $0 – $94,050 $0 – $63,000
15% Tax Rate $47,026 – $518,900 $94,051 – $583,750 $63,001 – $551,350
20% Tax Rate Over $518,900 Over $583,750 Over $551,350

The Net Investment Income Tax (NIIT) Surtax

Under Section 1411 of the Internal Revenue Code, high-earning taxpayers are subject to an additional 3.8% Net Investment Income Tax (NIIT) on the lesser of their net investment income (including capital gains, dividends, interest, and rental income) or the amount by which their Modified Adjusted Gross Income (MAGI) exceeds statutory threshold levels:

  • Single / Head of Household: MAGI threshold of $200,000.
  • Married Filing Jointly: MAGI threshold of $250,000.
  • Married Filing Separately: MAGI threshold of $125,000.
  • Effective Top Federal Rate: For high earners subject to the 20% bracket and 3.8% NIIT, the top marginal federal capital gains rate is 23.8% (plus applicable state income taxes).

Section 121 Primary Residence Capital Gains Exclusion

Homeowners selling their primary residence benefit from IRC Section 121, which provides an exclusion of up to $250,000 of capital gains for single filers and $500,000 for married couples filing jointly:

Section 121 Qualification Criteria:
1. Ownership Test: You owned the home for at least 2 of the 5 years preceding the sale date.
2. Use Test: You lived in the home as your principal residence for at least 2 of the 5 years (730 days).
3. Frequency Limit: The exclusion can be claimed once every two years.

Step-by-Step Practical Calculation: Stock Portfolio Sale

An investor filing as Married Filing Jointly with an ordinary taxable salary of $180,000 sells two stock positions:

  • Asset 1 (Stock A): Purchased 2 years ago for $20,000; sold for $50,000 → $30,000 Long-Term Capital Gain.
  • Asset 2 (Stock B): Purchased 6 months ago for $15,000; sold for $25,000 → $10,000 Short-Term Capital Gain.
  • Taxable Income Context: Total income = $180,000 + $30,000 + $10,000 = $220,000 (below the $250,000 NIIT threshold).
  • Long-Term Tax: $30,000 falls within the 15% LTCG bracket → $30,000 × 0.15 = $4,500.
  • Short-Term Tax: $10,000 taxed at the marginal 22% ordinary rate → $10,000 × 0.22 = $2,200.
  • Total Federal Tax Liability: $4,500 + $2,200 = $6,700 total tax (effective rate = 16.75% on $40,000 total gain).

Frequently Asked Questions About Capital Gains

What is the IRS Wash-Sale Rule and how does it affect capital losses?

Under IRC Section 1091, a wash sale occurs if you sell a security at a loss and purchase a "substantially identical" security within a 61-day window (30 days before the sale, the day of the sale, or 30 days after). When triggered, the loss is disallowed for immediate tax deduction and is instead added to the cost basis of the newly acquired replacement security.

How much net capital loss can I deduct against ordinary income each year?

Capital losses first offset capital gains dollar-for-dollar without limit. If your total capital losses exceed total capital gains, you can deduct up to $3,000 of net capital loss per year ($1,500 if married filing separately) against ordinary wage income. Any remaining unused capital loss rolls forward indefinitely to future tax years.

What is the step-up in basis for inherited assets?

When an individual inherits capital assets (stocks, real estate) upon the owner's death, the tax cost basis of the asset is "stepped up" to its fair market value on the date of the decedent's death. All built-in unrealized capital gains accrued during the decedent's lifetime are permanently eliminated from income tax.

Are cryptocurrencies subject to capital gains tax?

Yes. The IRS treats cryptocurrencies and digital assets as property (IRS Notice 2014-21). Selling cryptocurrency for fiat currency, exchanging one cryptocurrency for another, or using cryptocurrency to purchase goods and services triggers a taxable capital gain or loss event based on your holding period.

Cost Basis Methodologies and Specific Share Identification

When an investor liquidates a partial position in a stock, mutual fund, or ETF acquired across multiple purchase dates and prices (tax lots), selecting the optimal cost basis accounting method directly dictates the realized capital gain or loss:

  • First-In, First-Out (FIFO): The default IRS method. Shares purchased earliest are sold first. In a rising market, FIFO generates the largest taxable capital gain because oldest shares typically have the lowest cost basis.
  • Specific Identification (Spec ID): The investor explicitly designates which specific tax lots are sold. This is the gold standard for tax efficiency, enabling customized tax outcomes.
  • Highest-In, First-Out (HIFO): An automated variant of Spec ID that sells shares with the highest purchase price first, minimizing immediate realized capital gains or maximizing realized tax losses.
  • Average Cost Method (AvgCost): Permitted exclusively for mutual funds and dividend reinvestment plans. Sums total capital invested and divides by total shares owned. Once elected for a fund, AvgCost cannot be switched to Spec ID for existing lots.

Tax-Loss Harvesting and Cross-Asset Pair Trading

Tax-loss harvesting is the strategic realization of capital losses to offset realized capital gains and up to $3,000 of ordinary wage income:

Tax-Loss Harvesting Offset Order (IRS Ordering Rules):
1. Short-term capital losses first offset short-term capital gains.
2. Long-term capital losses first offset long-term capital gains.
3. Net short-term losses offset net long-term gains (or vice versa).
4. Any remaining net capital loss offsets up to $3,000 of ordinary wage income per year ($1,500 if married filing separately).
5. Unused excess capital losses carry forward indefinitely to future tax years.

To avoid the 30-day Wash-Sale Rule while maintaining continuous market exposure, investors execute cross-asset replacement trades by swapping into correlated but not "substantially identical" assets (e.g., selling Vanguard S&P 500 ETF / VOO at a loss and immediately purchasing Vanguard Total Stock Market ETF / VTI or Schwab US Large-Cap ETF / SCHX).

Section 1031 Like-Kind Exchanges in Real Estate

Under Internal Revenue Code Section 1031, real estate investors can defer 100% of federal capital gains taxes and depreciation recapture taxes when selling investment property by rolling the proceeds into replacement real estate:

Section 1031 Requirement Statutory Rule Critical Risk Factor
45-Day Identification Window Must formally identify up to 3 potential replacement properties in writing within 45 calendar days of closing the relinquished property. Strict deadline; zero extensions granted under any circumstance.
180-Day Exchange Horizon Must close on and acquire the replacement property within 180 calendar days of selling the initial property. Failure to close within 180 days triggers immediate full capital gains taxation.
Qualified Intermediary (QI) Sale proceeds must be held by an independent third-party Qualified Intermediary; the seller cannot touch or hold funds. Constructive receipt of funds by seller instantly disqualifies the exchange.
Reinvestment Value Equality Replacement property purchase price and debt must equal or exceed relinquished property value. Any cash taken out or net debt reduction ("boot") is fully taxable.

Qualified Small Business Stock (QSBS / Section 1202) Exclusions

One of the most powerful tax provisions in the Internal Revenue Code is Section 1202, which grants a 100% federal capital gains exclusion on the sale of Qualified Small Business Stock (QSBS):

  • Statutory Exclusion Limit: Eligible non-corporate taxpayers can exclude up to $10 million in capital gains or 10 times the taxpayer's aggregate adjusted basis (whichever is greater) per issuing corporation.
  • Key Qualification Criteria: The stock must be acquired at original issuance from a domestic C-corporation with aggregate gross assets ≤ $50 million before and immediately after issuance, and the taxpayer must hold the stock for more than 5 consecutive years while the corporation actively conducts a qualified trade or business (excluding professional services, finance, hospitality, and mining).

Special Capital Gains Rates: Collectibles and Real Estate Section 1250

Certain asset categories are subject to unique statutory federal capital gains maximum rate caps rather than standard LTCG brackets:

Asset Classification Maximum Federal Tax Rate Underlying Statutory Section Representative Assets
Collectibles & Physical Metals 28.0% Maximum Rate IRC Section 1(h)(4) Physical gold/silver bullion, rare coins, fine art, stamps, vintage cars, precious gems, gold ETFs (e.g., GLD).
Unrecaptured Section 1250 Depreciation 25.0% Maximum Rate IRC Section 1250 Cumulative depreciation deductions claimed on investment real estate over the ownership lifetime.
Standard Long-Term Capital Assets 0%, 15%, or 20% (plus 3.8% NIIT) IRC Section 1(h)(1) Public corporate equities, index funds, mutual funds, corporate and municipal bonds, land.

The 10-Point Evidence-Based Tax-Efficient Investing Protocol

  1. Hold Assets for > 365 Days: Never sell a winning investment position at 364 days; crossing the 1-year mark drops marginal federal tax rates from up to 37% down to 15% or 20%.
  2. Select Spec ID / HIFO Accounting: Instruct your brokerage to use Specific Identification or Highest-In, First-Out (HIFO) for tax lots to minimize realized taxable gains.
  3. Harvest Capital Losses Annually: Conduct portfolio tax-loss harvesting in November and December to lock in losses that offset realized gains and up to $3,000 of ordinary wage income.
  4. Avoid the 30-Day Wash-Sale Rule: When selling at a loss, do not repurchase substantially identical securities within 30 days before or after the sale; use correlated alternative ETFs.
  5. Utilize Tax-Advantaged Accounts for High-Turnover Trading: Execute active short-term trading, high-turnover strategies, and REIT investments inside Roth IRAs, traditional IRAs, or 401(k)s.
  6. Leverage Section 121 Primary Residence Exclusions: Occupy real estate for at least 2 of the 5 years preceding sale to shield up to $250k (single) or $500k (married) of net equity gains.
  7. Donate Appreciated Stock Directly to Charity: Transfer shares with large built-in gains directly to a 501(c)(3) charity or Donor-Advised Fund (DAF), claiming the full fair market value deduction while bypassing 100% of capital gains taxes.
  8. Monitor State-Level Capital Gains Exposure: Account for state income taxes (e.g., California up to 13.3%, New York up to 10.9%, New Jersey up to 10.75%) which tax capital gains as ordinary income.
  9. Preserve Capital Improvements Receipts for Real Estate: Document all capital improvements (remodeling, roof replacement, additions) to increase your real estate cost basis and lower future taxable gains.
  10. Plan Estate Step-Up in Basis: Hold highly appreciated assets until death to allow heirs to receive a stepped-up cost basis, permanently eliminating lifetime capital gains taxes.

Detailed Capital Gains Tax FAQs

How are Restricted Stock Units (RSUs) taxed when they vest and sell?

When RSUs vest, their full market value is taxed immediately as ordinary wage income (reported on Form W-2). That vesting value becomes your new tax cost basis. If you sell the shares immediately upon vesting, you realize zero capital gains. If you hold the shares after vesting, subsequent price growth is taxed as short-term or long-term capital gains from the vesting date.

What is depreciation recapture on investment real estate?

The IRS requires real estate investors to depreciate residential rental properties over 27.5 years. When the property is sold, the cumulative depreciation claimed is "recaptured" and taxed at a maximum federal rate of 25% (Section 1250), regardless of your long-term capital gains bracket. Any remaining profit above the original purchase price is taxed at standard LTCG rates.

How are cryptocurrency airdrops, staking rewards, and hard forks taxed?

Under IRS Revenue Ruling 2019-24, cryptocurrency received via airdrops, staking rewards, or hard forks is taxed as ordinary income at fair market value on the date of receipt. That fair market value becomes the cost basis. When you subsequently sell or trade those tokens, capital gains rules apply from that acquisition date.

Do mutual funds distribute capital gains even if I did not sell any shares?

Yes. When active mutual fund managers sell underlying holdings at a profit throughout the year, federal law requires the fund to distribute those realized net capital gains to shareholders in December. Shareholders must pay tax on these capital gains distributions even if they reinvested the cash and never sold fund shares (a tax inefficiency avoided by Exchange-Traded Funds / ETFs due to in-kind creation/redemption mechanisms).

Can I use capital losses to offset ordinary retirement account withdrawals?

No. Capital losses realized in taxable brokerage accounts can only offset capital gains and up to $3,000 of ordinary wage/salary income per year. They cannot offset distributions from tax-deferred accounts (Traditional IRAs, 401ks), which are taxed strictly as ordinary income.

What happens if I sell stock gifted to me by a living person?

When you receive gifted stock from a living person, you inherit the donor's carryover cost basis and original holding period. If the donor bought the stock for $10 and it is worth $100 when gifted, selling it for $100 triggers capital gains on the full $90 gain.

Net Unrealized Appreciation (NUA) in Employer 401(k) Plans

When an employee retires or separates from service holding highly appreciated company stock inside a qualified employer 401(k) plan, utilizing the Net Unrealized Appreciation (NUA) strategy provides extraordinary tax savings:

  • Standard 401(k) Rollover (Status Quo): Rolling company stock into a Traditional IRA defers tax, but all subsequent withdrawals are taxed at high ordinary income tax rates (up to 37%).
  • The NUA Alternative: The employee transfers the physical company stock into a taxable brokerage account while rolling the non-company stock balance into an IRA. The employee pays ordinary income tax only on the original cost basis of the stock at distribution. The entire accumulated appreciation (the NUA) is permanently converted into long-term capital gains taxed at 0%, 15%, or 20% whenever the shares are sold.

Qualified Opportunity Zone Funds (IRC Section 1400Z-2)

Investors realizing substantial capital gains from stock, real estate, or private business sales can roll capital gains into a Qualified Opportunity Fund (QOF) within 180 days:

Opportunity Zone Tax Incentives:
1. Tax Deferral: Realized capital gains invested in a QOF are deferred from federal income tax until the investment is sold or December 31, 2026.
2. Permanent Tax Elimination: If the investor holds the QOF investment for at least 10 years, 100% of the new capital appreciation generated within the Opportunity Zone fund is completely exempt from federal and state capital gains tax upon sale (stepped-up basis to fair market value).

Additional Capital Gains Tax FAQs

How are Incentive Stock Options (ISOs) taxed compared to Non-Qualified Stock Options (NQSOs)?

NQSOs trigger ordinary income tax on the spread between the exercise price and fair market value immediately upon exercise. In contrast, exercising ISOs does not trigger ordinary income tax (though the spread is an Alternative Minimum Tax / AMT preference item). If ISO shares are held for at least 2 years from grant and 1 year from exercise, the entire gain from the strike price is taxed at long-term capital gains rates.

Does the 3.8% Net Investment Income Tax (NIIT) apply to real estate sales?

Yes. Capital gains from the sale of investment real estate (second homes, rental properties) are included in Net Investment Income. If your Modified Adjusted Gross Income exceeds $200,000 (single) or $250,000 (married filing jointly), the 3.8% NIIT surtax is added to your statutory long-term capital gains rate.

How do capital gains work on inherited real estate owned by multiple siblings?

When multiple heirs inherit real estate, the property receives a full step-up in basis to fair market value at the date of death, divided equally among heirs. If the siblings sell the property shortly after death for approximately the appraised estate value, zero or negligible capital gains tax is owed.

Can capital losses from previous tax years offset short-term capital gains this year?

Yes. Unused capital loss carryovers from prior tax years retain their character (short-term or long-term) and are applied against current-year capital gains on Form 1040 Schedule D, first offsetting gains of the same character and then offsetting opposite-character gains.