Home Sale Exclusion Calculator: Methodology
Last updated: November 2026
What it answers
Given a home sale, how much of the gain can be left out of income under section 121, how much is taxable, and what federal income tax and net investment income tax the taxable part brings, on top of your other income for the year.
Inputs
- Sale price, selling costs, purchase price, improvements: amount realized is the price less selling costs; adjusted basis is purchase price plus improvements less depreciation (Pub. 523, Worksheet 2).
- Depreciation after 6 May 1997 for a home office or a rental part, if any.
- Months owned and months used as the main home in the 60 months before the sale, months since the exclusion was last used, and the reason for the sale if the tests are not met.
- Months of nonqualified use after 2008, and total months owned, for the share of gain that cannot be excluded.
- Filing status, adjusted gross income and other investment income, for the tax and the net investment income tax.
Method
- Gain = amount realized less adjusted basis. A zero or negative result means no tax and no deduction.
- Tests. Full exclusion if owned and used for at least 24 of the last 60 months and the exclusion was not used on another home in the last 24 months. The limit is $250,000; $500,000 for a joint return when both spouses meet the use test, either spouse meets the ownership test, and neither spouse used the exclusion on another home in the last 2 years; or for an unmarried surviving spouse, not remarried, selling within 2 years of the death when the tests were met just before it.
- Partial exclusion when the tests are not met and the main reason was work, health or an unforeseen event: limit = shortest of (months used, months owned, months since the last exclusion) ÷ 24, times the full limit (Pub. 523, Worksheet 1 part B). Publication 523 repeats the steps for a spouse and adds the two results on a joint return; the calculator assumes both spouses have the same months, so with both spouses having lived there a joint return gets twice the single reduced limit, and otherwise one single reduced limit (a spouse who never lived there adds nothing).
- Depreciation. Gain up to the depreciation after 6 May 1997 is not excluded (section 121(d)(6)). It is unrecaptured section 1250 gain, taxed at ordinary rates up to 25% (section 1(h)(1)(E)).
- Nonqualified use. The remaining gain times (months of nonqualified use ÷ total months owned) is not excluded (section 121(b)(5)). Periods before 2009 are left out of the count, and so is any part of the 5-year period before the sale that falls after the last day it was your main home or your spouse's (or former spouse's) main home.
- Excluded = the smaller of the gain left after steps 4 and 5 and the limit. Taxable gain = gain less the excluded part.
- Tax. The taxable gain is added to adjusted gross income and the standard deduction is taken. Long-term gain is taxed by the IRS Schedule D Tax Worksheet (0%, 15%, 20%, and the 25% rate on unrecaptured section 1250 gain). A home owned a year or less is taxed as ordinary income. The tax shown is the increase over the same return without the sale.
- Net investment income tax: the taxable gain counts as net investment income. The tax shown is the increase over the NIIT on your other income and investment income without the sale.
Worked examples (from the engine, and each one is a unit test)
Publication 523's example. Bought for $400,000, rented 2 years with $20,000 of depreciation, lived in 2 years, moved out a year before selling, sold for $700,000. Gain $320,000. Depreciation gain $20,000 is not excluded. Of the remaining $300,000, 2 of 5 years were nonqualified use: $120,000 is not excluded. Excluded $180,000, taxable $140,000. The publication gives the same figures: $120,000 of nonqualified use gain reported as long-term capital gain, $180,000 excluded, and $20,000 of depreciation recaptured under section 1250.
A partial exclusion. $500,000 sale of a home that cost $200,000, after 12 months, for a new job. Gain $300,000. The limit is 12 ÷ 24 of $250,000, or $125,000. Taxable $175,000.
Limitations
- Federal tax only. States differ, and some do not follow the federal exclusion.
- No business use of part of the home, no home destroyed or condemned, no special periods for the military, Foreign Service or intelligence community, no divorce or separation rules, no expatriate rule.
- A home acquired in a section 1031 exchange cannot use the exclusion for 5 years after the exchange (section 121(d)(10)); the calculator does not ask, so check it first.
- It assumes the standard deduction, no other capital gains or losses, no qualified dividends and no collectibles gain (taxed at a higher rate).
- The NIIT uses adjusted gross income as modified adjusted gross income. The foreign earned income add-back is not modelled.
- Months are whole months; the IRS accepts days (730 for the 2 years) too, which can differ by a few days.
Sources
- 26 U.S.C. 121, Exclusion of gain from sale of principal residence. Subsection (a): owned and used as the principal residence for periods aggregating 2 years or more in the 5-year period ending on the sale. (b)(1) and (b)(2): the exclusion limit and the higher limit substituted for a joint return. (b)(3): one use every 2 years. (b)(4): the surviving spouse. (b)(5): gain allocated to periods of nonqualified use. (c): the reduced limit. (d)(6): gain up to depreciation after 6 May 1997 is not excluded. (d)(10): property acquired in a section 1031 exchange. Read on 19 November 2026 from the 2024 edition of the Code on govinfo.gov.
- IRS Publication 523 (2025), Selling Your Home. Eligibility Steps 1 to 6, Worksheet 1 (the maximum and the partial exclusion, with the "shortest of the following 3 periods" divided by 24 months), Worksheets 2 and 3 (gain and nonqualified use), and its own example of a rental that became a home. Read on 19 November 2026.
- 26 U.S.C. 1(h), Maximum capital gains rate. Paragraph (1)(E): the 25% maximum rate on the unrecaptured section 1250 gain. Paragraph (6): the definition. Read on 19 November 2026.
- IRS Instructions for Schedule D (Form 1040), Schedule D Tax Worksheet. The worksheet lines 1 to 47 the tax on the gain follows (2025 edition; the 2026 thresholds come from Rev. Proc. 2025-32 and the 2027 thresholds from Rev. Proc. 2026-35 through the same data module as the other tax calculators).
- IRS Instructions for Form 8960, Net Investment Income Tax. 3.8% of the smaller of net investment income and the modified adjusted gross income over the threshold for your filing status (read from the same data module as the other tax calculators). Gain from the sale of a home is investment income only to the extent it is taxable.
Change history
- November 2026: first version. Statute read on govinfo.gov (2024 edition) and Publications 523 and 544, the Schedule D instructions and the Form 8824 instructions read on 19 November 2026.
The exclusion limits, the 2-year tests and the 25% rate are not indexed. This page changes only if Congress amends the law or the IRS changes its worksheets; the tax brackets and capital gains thresholds update with the yearly Revenue Procedure.
This calculator is for educational purposes only and does not constitute financial advice. Results are estimates from the numbers you enter. Check with a licensed professional before you act on them. Full disclaimer →