I always find it interesting that our tax world keeps getting more and more convoluted. In fact I was just reading on Forbes Magazine that since 2001 Congress has made nearly 5,000 changes to the Tax Code. Want more articles like this? Create an account today to get BiggerPocket's best blog articles delivered to your inbox Sign up for free To make things worse, not only are the changes more frequent but the tax rules are also getting more complex by the minute. Let’s take the example of a simple real estate scenario: Did you know that turning a primary home into a rental has very different tax consequences than a turning a rental into a primary home? That’s right! If you have a property that you turn from a primary home into a rental property it can have significantly better tax benefits than a rental property that you later decide to move into. Just how do they differ? Well, let’s take a look at two fictitious taxpayers Mary and Jerry. Primary Home Turned Rental Mary and her husband lived in their home for over 6 years. Once they had their 4th child they decided they needed more room and needed to move into a bigger home. Being investors themselves, Marry and her husband decided it would be a good idea to keep their home as a rental property. Luckily for Mary, two years down the road the home appreciated in value and she was able to sell the home for a nice gain of $100,000. Related: Investing for Cash Flow or Appreciation – What’s the Difference? For Mary, she was able to get $100,000 of this gain free from taxes because she sold her house within the IRS allotted time frame. Mary was able to use a primary home gain exclusion on her home because the property was her primary residence in two of the preceding five years. In fact, had the real estate market sky-rocketed in value, Mary and her husband could have received up to $500,000 of gain free from taxes. Furthermore, there is no limitation on how many times the exclusion may be used during someone’s lifetime so a few years from now, Mary and her husband could potentially sell their new home and use the $500,000 gain exclusion again. As real estate investors, this is a nifty loophole that can help you to build up your wealth in a tax-free manner over time. In fact, I have a few clients that use this strategy consistently every few years to trade-up their home and lock in the appreciation free from taxes. The catch is of course that you should make sure that your family is on the same page with you in terms of moving every few years. To qualify for the home sale exclusion, you must own and occupy the home as your principal residence for at least two years before you sell it. Your two years of ownership and use can occur anytime during the five years before you sell—and you don’t have to be living in the home when you sell it. Rental Turned Primary Home Now let’s go to our next taxpayer Jerry. For Jerry, he had a rental property that he purchased back in 2010 for $150,000. In 2012, after two years of renting it out, Jerry and his wife decided that it made sense for them to move into this rental property as their primary home. Two years after moving in to the property, the home value appreciated significantly and Jerry decided to sell the property for $250,000 in 2014 and move his family into a nicer home. Unlike Mary, Jerry was not able to exclude the entire $100,000 gain from taxes. The reason was due to a special rule that was enacted in 2009 that puts limits on people who sell a primary home which initially started out as a rental property. Related: The 5 Things You Will Probably Forget When Rehabbing a House Flip The rule requires the property owner to reduce the amount of profit excluded from income based on the number of years after 2008 in which the property was used as a rental on a pro rata basis. In Jerry’s example, the property was a rental during two out of the 4 years that he owned the property. As such, the amount that he was able to exclude as taxable income to him was only $50,000. Now what if instead of selling the property in 2014 Jerry and his wife decided to move back into the property again and instead decide to sell it in 2015? The good news is that under the IRS regulations, a nonqualified use can occur only before the home was used as the taxpayers’ principal residence. So the time periods after the home was used as Jerry’s principal residence does not constitute a nonqualified use. Assuming that Jerry ended up selling the house for $250,000 in 2015 after having moved back into the property for another year, his taxable gain would then be reduced to two fifths of $100,000 or $40,000. As you can see, the tax world can get complex when you are considering moving into or out of a property as your primary home. In fact, if you have turned your primary home into a rental in the last few years, you may want to meet with your advisor to determine whether it makes sense to sell your old home and lock in some tax-free capital gains. Make sure you are planning ahead and meeting with your own tax advisor prior to making these moves to ensure that you maximize your tax savings.