Investors & landlords

Hi.  I don't think this qualifies as a 1031 Exchange question, but it's in the ballpark.  I'm trying to find a clear rule for avoiding capital gains on your rental property if it was formerly your primary residence.  So, here's the scenario:

  • Purchased as primary residence in 2002.
  • Became Investment property June 1st, 2019.
  • We are not renewing the lease, which expires on August 30th 2021. 
  • We anticipate putting it immediately on the market when the lease expires.

If the property is sold before the end of 2021, do we avoid capital gains penalties?  I'm having difficulty following the "If you have lived in the property at least 3 of the past 5 years" rule.  What's the impact on our capitals gains if we sell by the end of the year?