Principal Residence exclusion and Depreciation Recapture

In 2001 I purchased a 2 family home for my family as our main home. In 2006 we moved out and made it a 2 family rental. I moved back in 2014 to one of the two apts (50% rental). I sold the property in 2020. How do I figure out principal residence exclusion? Is the entire rental period excluded because I lived in it for 5 years first?  How do I determine depreciation recapture?  Do i included 100% of depreciation claimed from 2006 to 2014 and then the 50% claimed from 2014 to 2020?