I lived in a house for almost 2 years then rented it for another 2 and sold it. I moved out of state due to health reasons. How do I show that on my tax return?

The house was my primary residence for 23 months. I rented it afterward for just over 2 years and sold it last year. I moved because of my wife's health issues (though not officially documented or advised by a physician - so I don't have anything that would state so). I would like to be able to count the 23 months that it was my primary residence towards my gains. How would I do that?