Illustrative example. The couple, the address and the figures are hypothetical. They show how the rules work; they are not a real client.

Can you move into a rental property for two years and then sell it without capital gains tax? Only partly. Since 2009, the years a home was rented out before you lived in it count as nonqualified use, and the share of the gain that belongs to those years cannot be excluded. Depreciation you took is never excludable either. This example works through the numbers for a couple who did exactly this.

The Result

  • Gain on the sale: $2,168,000
  • Excluded under Section 121: $369,654 — not the full $500,000
  • Federal tax: $438,906, against $526,884 if they had sold it as a rental — $87,978 less

The Property and the Timeline

  • March 2010: a married couple buy a house for $800,000 and rent it out.
  • 2010–2020: they claim $218,000 of depreciation over the rental years.
  • July 2020: the last tenants leave; they spend $50,000 on improvements and move in as their main home.
  • December 2022: they sell for $2,800,000, after about 29 months of living there.
  • They file jointly, are in the 20% capital gains bracket and owe the 3.8% net investment income tax.

To keep the arithmetic visible, the example ignores selling costs and state tax. Both would change the totals but not the method.

Two Rules That Change the Math

Nonqualified use (Section 121(b)(5))

Gain is split between the time the home was your main home and the time it was not, in proportion to the days in each. The part allocated to nonqualified use — periods after 2008 when the property was not your main home — cannot be excluded. Three periods do not count as nonqualified use: time after the last day you lived there (within the five-year window), up to 10 years of qualified official extended duty, and up to two years in total of temporary absence because of a job change, health or other unforeseen circumstances (IRS Publication 523).

Depreciation is always taxed

Gain equal to the depreciation you took after May 6, 1997 is not excludable. It is taxed as unrecaptured Section 1250 gain, at your ordinary rate but no more than 25%.

The Math

StepAmount
Sale price$2,800,000
Adjusted basis ($800,000 + $50,000 improvements − $218,000 depreciation)$632,000
Total gain$2,168,000
Depreciation part, taxed at up to 25%$218,000
Gain apart from depreciation$1,950,000
Days owned / days rented before moving in4,658 / 3,775 (81.04%)
Gain allocated to nonqualified use (taxable)$1,580,346
Gain eligible for the exclusion$369,654
Excluded (limit $500,000 for a married couple)$369,654

Federal tax: moving in vs. selling as a rental

TaxAfter moving inSold as a rental
Depreciation recapture (25% of $218,000)$54,500$54,500
Capital gains tax (20%)$316,069$390,000
Net investment income tax (3.8% of the taxable gain)$68,337$82,384
Total federal tax$438,906$526,884

Both columns use the same sale price and basis, so the $87,978 difference is the value of the exclusion alone: $369,654 × 23.8%. Had the full $500,000 been excludable, the saving would have been $119,000 — the nonqualified-use rule takes away about a quarter of it here, and more the longer a property was rented before the move.

What the Example Shows

Moving in late shrinks the benefit

The excludable share is roughly the time you lived there divided by the time you owned it. Ten years of renting followed by two and a half years at home leaves only about a fifth of the gain eligible.

The reverse order works better

If you live in a home first and rent it out afterwards, the rental years after you move out are not nonqualified use. Sell within three years of moving out and you can still meet the two-out-of-five-years test and exclude up to $250,000 (single) or $500,000 (married filing jointly) — though the depreciation from the rental years is still taxed.

Keep records of genuine use

The IRS looks at where you actually live. Keep evidence such as voter registration, driver's license and vehicle registration, the address on your tax returns, utility bills and bank statements.

Other Limits to Know

  • You must have owned and lived in the home for at least two of the five years before the sale.
  • You can use the exclusion once every two years.
  • In a duplex or other multi-unit building, the exclusion applies only to the unit you live in.
  • State rules can differ from the federal ones; check your state before relying on the exclusion.

Our calculators do not apply the nonqualified-use split, so for a home that was rented first, work out the excludable share with the day count above. The depreciation recapture calculator gives the depreciation layer that is always taxed, and the home sale exclusion guide covers the ownership and use tests in more detail.