In order to qualify for the capital gains tax exclusion, you must have lived in the property for at least 720 days of the last 1826 days you owned it, counting backwards from the closing date of your sale.
If you are the sole owner and meet the above requirement, you can exclude a maximum of $250,000 of gain from taxation. If you are married, filing a joint return and both you and your spouse individually meet the requirement, then you can exclude a maximum of $500,000 of your gain from taxation.
Note I stated "maximum". Your allowed exclusion could actually be less.
When the last person to move out of the house prior to the sale is the owner of the house, you will not qualify for the full amount of the exclusion. It will be prorated based on the period of "unqualified use" prior to the time you moved in. That period of unqualified use goes back to when you purchased the property, or 1986 - Whichever is **SOONER**. In your case, the period of unqualified use would be from the date you purchased the property until the date you converted it back to personal use.
So you will only be able to exclude a percentage of your "actual" gain - not a percentage of the maximum exclusion allowed.
Also understand that depreciation recapture is not included as a part of the exclusion. You *WILL* pay taxes on 100% (one hundred percent) of the recaptured depreciation, no matter what.
All of this is covered in IRS Publication 523. But I can tell you right now, trying to read it and figure it out all in one shot *WILL* result in you being committed to a metal institution. 🙂 Best method is to read it through once to "Know it". Then the 2nd read through black out that information that does not apply to your specific situation. Then the 3rd read-through will hopefully not result in total brain failure.