How the gain is calculated
Adjusted basis = purchase price + buying costs + improvements − depreciation
Gain = amount realized − adjusted basis
Selling costs include the real estate agent's commission, advertising, legal fees, and loan charges you paid that would normally be the buyer's. Buying costs you can add to basis include abstract and title search fees, legal fees, recording and survey fees, transfer taxes and owner's title insurance (but not points or other loan costs). Improvements are work that adds value, extends the home's life or adapts it to new uses, such as a new roof or an addition. Keep the receipts: every dollar of basis is a dollar of gain you don't pay tax on.
The home sale exclusion (Section 121)
You can exclude up to $250,000 of gain, or $500,000 on a joint return, if:
- Ownership test: you owned the home for at least 24 months in the 5 years before the sale, and
- Use test: you lived in it as your main home for at least 24 months in those 5 years. The months don't have to be in a row.
- You didn't exclude the gain on another home in the 2 years before this sale.
For the $500,000 joint exclusion, either spouse can meet the ownership test, but both must meet the use test. If you fall short because of a move for a new job at least 50 miles farther away, health, or an unforeseeable event, you may get a partial exclusion: the shortest of the months you owned it, lived in it, or since your last excluded sale, divided by 24, times $250,000 (or $500,000). Depreciation you took after May 6, 1997 for renting the home or a home office can't be excluded; it's taxed at up to 25%.
How the tax is estimated
The taxable gain on a home you owned more than a year is a long-term gain, taxed at 0%, 15% or 20% depending on your total taxable income. The calculator stacks the gain on top of your other taxable income using the 2026 thresholds, then adds the 3.8% net investment income tax (NIIT) where your income is over $200,000 (single or head of household), $250,000 (joint) or $125,000 (married filing separately). The excluded part of the gain isn't subject to NIIT.
Worked example
A married couple sells for $1,200,000 and pays $60,000 of selling costs. They bought for $400,000, paid $10,000 of closing costs and spent $100,000 on improvements. Basis = $510,000; amount realized = $1,140,000; gain = $630,000. They meet both tests, so $500,000 is excluded and $130,000 is taxable. With $150,000 of other taxable income, all of it falls in the 15% band: $19,500. Their income of about $280,000 is $30,000 over the NIIT threshold, adding $1,140, for $20,640 in all.
Limitations
- An estimate, not a tax return. It doesn't include state tax, the nonqualified-use rules for time the home was rented before you lived in it, or special rules for military and other service members.
- NIIT is based on modified AGI, which is usually higher than taxable income, so the NIIT shown may be low.
- You can't deduct a loss on the sale of your main home.
- For a rental or investment property that was never your home, or stocks, use the capital gains tax calculator.
Sources
- IRS Topic 701: Sale of your home
- IRS Publication 523: Selling Your Home
- IRS: Sale of residence – real estate tax tips
- IRS Topic 409: Capital gains and losses
- IRS Topic 559: Net investment income tax
- IRS Rev. Proc. 2025-32: 2026 tax rate tables (§4.01), capital gains rate amounts (§4.03) and standard deduction (§4.14)