The short answer
The gain is split by time. Under section 121(b)(5), gain is allocated to periods of non-qualified use by the ratio of those periods to your total ownership, and that share cannot be excluded even if you meet the two-of-five-year test. Non-qualified use means time after 2008 when neither you nor your spouse lived there as a main home, but not time after you last moved out within the five-year window, and not qualifying duty or short temporary absences. Depreciation is pulled out first and taxed on its own.
At a glance
| What counts | Periods after 2008 when the house was not your or your spouse's main home |
|---|---|
| Ratio | Non-qualified periods divided by your total period of ownership |
| Not counted | Time after your last use as a home within the 5-year window |
| Duty exception | Up to 10 years of qualified official extended duty |
| Absence exception | Up to 2 years away for work, health or unforeseen circumstances |
| Depreciation | Removed first; taxed separately and not part of the ratio |
| Pre-2009 time | Never non-qualified, but still counts as ownership time |
The statute prorates by time, not by use test
Section 121(b)(5)(A) says the exclusion 'shall not apply to so much of the gain... as is allocated to periods of nonqualified use'. The allocation uses the ratio of 'the aggregate periods of nonqualified use during the period such property was owned by the taxpayer' to 'the period such property was owned by the taxpayer'.
Meeting the two-of-five-year test gets you in the door; the ratio then decides how much of the gain the exclusion can reach. The $250,000 or $500,000 cap applies to what is left after the non-qualified share is removed, and any unused cap is lost.
The rule took effect for periods after 2008. Ownership before January 1, 2009 still counts in the denominator, so long-time owners who rented the house only years ago lose a smaller share.
Three kinds of time never count against you
Section 121(b)(5)(C)(ii) excludes from non-qualified use 'any portion of the 5-year period... which is after the last date that such property is used as the principal residence'. Renting a house after you move out does not trigger the ratio; that timing question is in how long you can rent out your former home.
It also excludes up to 10 years of qualified official extended duty in the uniformed services, the Foreign Service or the intelligence community, and up to 2 years of 'temporary absence' due to a change of employment, health conditions or other unforeseen circumstances.
Everything else after 2008 counts: a rental before you moved in, a vacation home you later made your main residence, or a period the house stood empty before you occupied it.
Depreciation comes out first and is taxed on its own
Section 121(b)(5)(D) applies the ratio after section 121(d)(6) and 'without regard to any gain to which subsection (d)(6) applies'. You first remove the gain equal to depreciation after May 6, 1997, then prorate what remains.
Publication 523 builds this into Worksheet 3: Section A subtracts depreciation, Section B computes the non-qualified use gain, and Section C applies the exclusion to the rest. The depreciation slice is reported on Form 4797; the non-qualified gain is long-term capital gain on Schedule D.
Publication 523's own illustration: a house rented for two years and lived in for two, then sold a year after move-out. 40% of the gain after depreciation was allocated to non-qualified use, and the final year after move-out did not count against it.
Worked example: three years rented, three years lived in
Hypothetical, round numbers; run your own numbers with your CPA. A single owner bought a house on January 1, 2020 for $400,000, rented it until December 31, 2022 and claimed $30,000 of depreciation, then lived in it from January 1, 2023 until a sale on January 1, 2026 for $800,000.
Adjusted basis is $370,000, so the gain is $430,000. Remove the $30,000 of depreciation, taxed at up to 25%, leaving $400,000. Non-qualified use is 3 of 6 years owned, so $200,000 is allocated to it and taxable as long-term capital gain. The other $200,000 is excluded, and $50,000 of the $250,000 cap goes unused.
Had she lived there first and rented afterward for the same periods, the rent after move-out would not count, and the whole $400,000 would have faced only the $250,000 cap. The order of use is the variable that matters.
Where an exchange fits, and where it does not
On the sale date in the example, the house is a main home, so section 1031 cannot apply to it, and the $200,000 is simply taxed. An exchange only becomes available if the house is investment property when sold.
If you move out and rent the house again, Publication 523 notes the time after your last use is not non-qualified use, and Rev. Proc. 2005-14 then lets you exclude first and defer the rest, including the non-qualified share and the depreciation, by exchanging; see using the exclusion and a 1031 on the same property.
The same ratio is why moving into a former 1031 replacement shelters less than people expect: rental years after the exchange are non-qualified use, and section 121(d)(10) adds a five-year ownership rule. See moving into a 1031 replacement and section 1031 versus section 121.
Related questions
Does a vacation home I later moved into have non-qualified use?
Yes, for periods after 2008 before it became your main home. Personal vacation use is not use as a principal residence.
Is the ratio measured by days or years?
The statute speaks of periods, and Publication 523's worksheet uses the ratio of non-qualified time to total ownership time, so count days where the dates are uneven.
Does a year abroad for work count against me?
Not if it is a temporary absence due to a change of employment, health or unforeseen circumstances, up to an aggregate of 2 years. Qualifying military or foreign-service duty is excluded for up to 10 years.
If my spouse lived there while I was away, is that non-qualified use?
No. The definition covers periods when the house is not the principal residence of the taxpayer or the taxpayer's spouse or former spouse.
Does non-qualified use change my depreciation recapture?
No. The depreciation slice is computed first and taxed whatever the ratio; see depreciation recapture on a former home.
Sources
Checked against these publications on September 30, 2026. Rules and figures change; confirm the current version with your CPA or attorney before you act. This page is general information, not tax or legal advice.
