Section 1031 of the Internal Revenue Code allows you to roll the gain from the sale of your old property over to your new property without paying taxes. To qualify for this great benefit, both the old property and the new property have to be property held for investment or used in a trade or business. If you meet this requirement, you could sell your purple duplex and buy an office building, or an apartment building, a warehouse or even bare land -- you do not need to buy another purple duplex.
What does the term "held for investment, or used in a trade or business" mean? Well, first of all, it does not mean your personal residence -- the one in which you are living. And it does not mean property held for resale. A prime example of a property held for investment, then, would be one you are renting (such as your purple duplex).
One rental property can always be exchanged for another rental property. This is why you can sell a rental duplex and buy an office building. Bare land is pretty much always investment property and can be exchanged for a rental property or visa-versa. Renting property is not the only example of a transaction that will classify a property as one held for investment -- trying to rent the property also counts.
Just make sure you hang on to proof of your rental attempts in case the IRS audits you and questions your motives for purchasing the property.
Property used in a trade or business is real estate that is part of your business. For example, if you personally own the land and building that houses your real estate business, that property is now part of your real estate business and qualifies for a 1031 exchange. Similarly, if you are an agent for a real estate company, but operate out of an office in your home, that home office is now property used in a trade or business and could be part of an exchange when you sell your house.
Your personal residence, with the exception of the home-office situation referenced above, does not qualify for a 1031 exchange. Nor does "property held for resale." What is property held for resale?
Prime examples are "fix and flips" -- those ugly properties you buy, fix up, and put back on the market a few months later. These properties are bought with the intention of immediately reselling them, so they do not qualify.
Does that mean that you can’t buy ugly properties, fix them up, and do an exchange? It does not. You can do a 1031 exchange on "fix and flips," but you have to hold them long enough to qualify them as investment property. Typically this means that you have to hold them for at least a year and a day. The principal reason for this is that the IRS does not want you to turn short-term capital gains (which typically are taxed at higher tax rates) into long-term capital gains (which typically are taxed at much lower rates) by doing a 1031 exchange.
Their fear is that you would do a series of short-term "fix and flip" 1031 exchanges, decide several years later that you are tired of the "fix and flip" game, sell your last property, and then claim long-term capital gain treatment because the whole scheme, from first property to last, had taken longer than a year.
Note these final points: Both the old property and the new property have to be located within the United States. And it is possible to sell one old property and buy several new properties. Or you can sell several old properties and buy one new property. Keep in mind, however, multiple property transactions must still meet the 45-day and 180-day time frame requirements.