Selling a Rental That Was Your Primary Residence: 121 Rules
If you lived in the property as your main home for at least 2 of the 5 years before you sell, you can usually still exclude up to $250,000 of gain ($500,000 for most married couples filing jointly) under IRC §121, even though it is a rental on the day you sell. Two things are never fully excluded: the depreciation you took after May 6, 1997, which is taxed at up to 25%, and, if you rented the property before you lived in it, the share of gain allocated to those rental years after 2008. The order of your years, living first or renting first, changes the answer.
This guide walks through the 2-of-5-year test, the depreciation rule, the nonqualified use rule, two worked examples, how §121 combines with a 1031 exchange, and what happens to suspended rental losses.
The basic test: 2 of the last 5 years
Under §121(a), gain is excluded if, during the 5 years ending on the sale date, you owned the home and used it as your principal residence for periods adding up to at least 2 years. The two years do not have to be consecutive, and they do not have to be the last two years.
| Filing status | Maximum exclusion |
|---|---|
| Single, or married filing separately | $250,000 (§121(b)(1)) |
| Married filing jointly | $500,000 (§121(b)(2)), if either spouse meets the ownership test, both meet the use test, and neither used the exclusion in the prior 2 years |
A few automatic disqualifiers apply. The main one for investors: if you acquired the property in a 1031 exchange, you cannot use the exclusion on a sale within 5 years of that acquisition (§121(d)(10); IRS Pub. 523).
Depreciation is never excluded
If you rented the home, you claimed (or should have claimed) depreciation. Under §121(d)(6), the exclusion does not apply to gain up to the depreciation adjustments attributable to periods after May 6, 1997. That slice is taxed as unrecaptured Section 1250 gain: ordinary rates capped at 25%. "Allowable" matters: if you rented the home and never claimed depreciation, the IRS still reduces your basis by what you could have taken. The mechanics of that up-to-25% layer are in depreciation recapture explained.
Nonqualified use: why the order of your years matters
Since 2009, §121(b)(5) carves out gain allocated to periods of nonqualified use. A period of nonqualified use is any time after December 31, 2008 when neither you nor your spouse used the property as a principal residence.
The key exception (§121(b)(5)(C)(ii)(I)): time after your last use as a main home, within the 5-year window, is not nonqualified use. So:
| Pattern | Nonqualified use? | Effect |
|---|---|---|
| Lived there, then rented it, and sold within 3 years of moving out | No. Rental after your last use is excepted | Full exclusion available (minus depreciation) |
| Rented it first, then moved in, and later sold | Yes, for rental years after 2008 before you moved in | Part of the gain cannot be excluded |
| Lived there, rented, moved back in, sold | The rental years in the middle count, if after 2008 | Part of the gain cannot be excluded |
The nonqualified share is a simple time ratio: gain times (nonqualified use periods after 2008 divided by total ownership period) (§121(b)(5)(B)). Under §121(b)(5)(D), the depreciation gain comes out first and is left out of this ratio.
Other exceptions exist for qualified official extended duty (military, Foreign Service, intelligence community) and for temporary absences up to 2 years due to a change of employment, health or other unforeseen circumstances.
Example 1: lived first, then rented
Simple example. Married filing jointly, both spouses meet the tests, no selling costs.
A couple bought a home in 2014 for $400,000 and lived in it until July 2023. They rented it from July 2023 and sell it in June 2026 for $900,000. Depreciation on the rental years: $36,000.
- Adjusted basis: $400,000 - $36,000 = $364,000
- Gain: $900,000 - $364,000 = $536,000
- 2-of-5 test: the window runs June 2021 to June 2026. They lived there from June 2021 to July 2023, just over 2 years. Met.
- Nonqualified use: none. The rental came after their last use as a main home, inside the 5-year window.
- Depreciation slice (not excludable): $36,000, taxed at up to 25%
- Remaining gain: $500,000, fully covered by the $500,000 joint exclusion
Taxable gain: $36,000. Had they waited until after July 2026, their 2 years of use would have slipped out of the 5-year window, the entire gain would have been taxable. Timing the sale against the 3-year clock is the whole game in this pattern.
Example 2: rented first, then moved in
Simple example. Married filing jointly, both spouses meet the tests, no selling costs.
A couple bought a rental in January 2016 for $500,000 and rented it for 6 years (2016 through 2021). They moved in January 2022, lived there 4 years, and sell in January 2026 for $1,100,000. Depreciation on the rental years: $80,000.
| Step | Amount |
|---|---|
| Adjusted basis: $500,000 - $80,000 | $420,000 |
| Total gain: $1,100,000 - $420,000 | $680,000 |
| Depreciation slice, not excludable (§121(d)(6)) | $80,000 |
| Remaining gain | $600,000 |
| Nonqualified use ratio: 6 rental years / 10 years owned | 60% |
| Gain allocated to nonqualified use: $600,000 x 60% | $360,000 (taxable) |
| Gain eligible for exclusion: $600,000 - $360,000 | $240,000 (under the $500,000 cap, excluded) |
| Taxable gain | $440,000: $80,000 unrecaptured §1250 + $360,000 long-term capital gain |
The couple passes the 2-of-5 test easily, and the $500,000 cap is far above what they can use. The time ratio is what limits them. The full set of taxes on a rental sale, including the 3.8% NIIT and state tax, is in capital gains on rental property.
Combining §121 with a 1031 exchange
A property that was your home and is now a rental can qualify for both the exclusion and a like-kind exchange. Rev. Proc. 2005-14 sets the order:
- Apply §121 first to the gain realized.
- Apply §1031 to the rest. The depreciation slice that §121 cannot exclude can still be deferred under §1031.
- Boot (cash or other non-like-kind property) is taxed only to the extent it exceeds the gain excluded under §121.
- Basis in the replacement property treats the excluded gain as if it had been recognized, so the excluded gain is not pushed into the new property.
In Example 1, that means the couple could take up to $500,000 of cash out tax-free under §121 and exchange the rest into a replacement rental, deferring the $36,000 depreciation slice, if the property qualifies as held for investment at the time of the exchange. That is a CPA and qualified intermediary conversation before closing, not after. For 1031 boot rules generally, see 1031 boot.
One direction does not work: you cannot 1031 a rental into a home you will move into as your residence, because the replacement must be held for investment or business use. Rev. Proc. 2005-14 notes that §1031 does not apply to property used solely as a personal residence. Selling a rental to buy a primary residence is a taxable sale of the rental.
What about suspended passive losses?
Losses from the rental years that you could not deduct stay suspended on Form 8582. If you still rent the property on the sale date, the gain is passive income and a fully taxable sale to an unrelated buyer frees the property's suspended losses under §469(g). See what happens to suspended passive losses when property is sold.
If you converted the rental back to your home before selling, two points matter. Taxable gain on a personal residence above the §121 exclusion is not passive income, so other suspended passive losses cannot offset it; capital losses can. And whether the sale of the converted home releases that property's own suspended losses depends on how the activity is treated after conversion. Get your CPA's view before you move back in.
Other ways owners handle this sale
- Sell inside the 3-year window after moving out, if you lived there first.
- Carry a note. An installment sale can spread the taxable part (the depreciation slice and any nonqualified gain) over several years. See installment sales of real estate.
- Keep it and hold. At death, the basis steps up and the built-in gain and depreciation are generally erased. The trade-offs are in alternatives to selling a rental property.
Bottom line
A rental you once lived in can still get the home sale exclusion, but the order of your years decides how much. Lived first, then rented: sell within 3 years of moving out and you usually lose only the depreciation. Rented first, then moved in: the rental years after 2008 shrink the exclusion by a time ratio, no matter how long you then live there. In both cases the depreciation is taxed at up to 25%. Run the numbers on the taxable part in the calculator, and get the free book for timing gain against rental losses.
Questions to ask your CPA
- Do I meet the 2-of-5-year ownership and use tests on my planned sale date, and what is the last day I can sell and still qualify?
- Do both spouses meet the use test for the $500,000 exclusion?
- How much depreciation was allowed or allowable after May 6, 1997?
- Do I have any periods of nonqualified use after 2008, and what is my ratio?
- Did I acquire this property in a 1031 exchange within the last 5 years?
- Could Rev. Proc. 2005-14 let me exclude part and exchange the rest?
- What happens to my suspended passive losses on this property if I sell now versus after moving back in?
Get the full playbook. The Waterfall Strategy, the 20-minute version and the one-page Cliff Notes, free.
Educational only, not tax, legal or investment advice. Examples are illustrative. Have your CPA or tax attorney review your facts before you act. Hans Goldstein is a licensed insurance agent (CA Insurance License #4273294) and is not a CPA or attorney. He is paid a commission only if a structured installment sale is funded; seller financing pays him nothing. Disclosures.