The “Primary Residence Exclusion” can help owners avoid liability on a home profit. (Michael Nagle/Bloomberg)

Are you a homeowner who wants to tap into the spring house buying season? Or perhaps you were a seller who benefited from the rise in home sales last year.

If so, you may have realized or will soon enjoy a sizeable financial gain. Home prices rose 6 percent last year. And according to economist Lawrence Yun of the National Association of Realtors, they are also expected to increase 4 to 5 percent in 2016.

Like winning the lottery — or investing in an undervalued stock — an unexpected rise in house values can make owners feel like they have hit the jackpot. But it’s important to remember that — like any windfall of cash or capital gains profit — the government will take its share. And it will do so often before the money hits the owners’ hands. Is there a practical way for homeowners to sell their appreciated valued house and reinvest the money without giving all their gains away?

Here’s a clue — two is the magic number. That’s the number of years that homeowners are given to prove that they lived in the house and have claimed it as their primary residence.

The “Primary Residence Exclusion” is one of the most common tax exemptions that owners use to avoid a tax liability on their homes. A single home owner is allowed to exclude $250,000 (married couple $500,000) any number of times, as long as it is not claimed more than once every two years. The key requirement is that the homeowner must have lived in the residence two consecutive years — but the two years can occur anytime during the five years before the date of the sale.

Let’s look at homeowners who want to rent out their residence for a few years. Perhaps the homeowners are not sure if they will like the new house in a different area or state. The owners may want to keep the existing house as a back up just in case things don’t work out at the new location.

Under IRS rules, the owners are allowed to rent out the home for up to three years, and still qualify for the primary-residence exclusion. (The owners need only have used the home as a primary residence for at least two of the five years prior to the sale). Owners, however, need to be sure that they have only one principal residence at a time.

Homeowners who have a second or vacation home that may have appreciated in value and who want to sell and take advantage of the gain will need to qualify — and insure that the second home was used as a principal residence for at least two years before the sale.

What can you do if your gain exceeds the legal limits ($250,000/$500,000) to qualify for the home exemption? Fortunately, owners are allowed to make improvements (like those that add value to the home or adapt the property to new uses) that will increase the basis or value of the property. (The higher the “basis” of the house, the less gain will be realized on the sales price). IRS Form 530 (https:www.irs.gov/uac/About-Publication-530) lists examples of improvements that increase the basis for your house; however those are only guidelines.

There is no time restriction regarding when the improvement needs to have been made. For example, you may have remodeled your kitchen 15 years ago, added a new bathroom 10 years ago, installed a small patio or stone retaining wall three years ago, or swapped out the windows for energy efficient ones last year, and still qualify for an adjustment in the cost basis of the house.

Tax preparers (such as Turbo Tax) or a certified public accountant will be better to advise you how to take advantage of this tax exemption to its fullest. Deductions — such as property taxes, closing costs, sales commissions, etc. — will reduce the realized gain.

If, after taking all the allowable exemptions, you still realize a taxable gain, there is another option that has increased in popularity over the last several years. The 1031 Tax-Deferred Exchange rule allows an owner to buy a replacement property that is considered “like kind” and potentially pay no tax. To qualify, the property must be considered an investment — generally a rental building, commercial property, house or land.

Homeowners with a sizeable capital gain on their residence — and who may want to “downsize” to a smaller property may opt to rent out their house for two years, then sell or “exchange” the property for another home that is of either equal or greater value than the existing house.

There are several ways to structure the 1031 exchange that can include taking partial gain (“boot”) out of the sale or trade. Additionally, there are other creative solutions that will help minimize the tax burden until the properties are eventually sold outright.

For many years, tax-deferred exchanges were considered complicated and confusing. Specialized exchange companies, such as the Private Exchange Group in Fort Lauderdale, Fla., now provide information, knowledge and assistance to accomplish the exchange. They act as a “hands on” facilitator or “qualified intermediary” to insure that the transaction — the sale and subsequent purchase or exchange — goes smoothly and conforms to IRS guidelines and rules.

One popular option, according to Drew Monaghan, president of the Private Exchange Group, allows owners to “transition” into the exchanged property (previously established as a rental) after two years. They then are legally allowed to establish the property as their primary or secondary residence.

In order to defer payment of any capital gains tax that may be due, the owner must not sell the property for five years.

“The structuring of a 1031 tax-deferred exchange depends on many variables,” Monaghan says, and “sellers should consult with their tax adviser or legal specialist when completing an exchange.”

Other special tax cases — such as the sale of property acquired by inheritance or a divorce decree — carry unique rules that may mitigate the payment of tax when the property is sold. Your accountant or a tax attorney can best estimate the tax, if any, you are likely to incur and offer advice on how to best structure the sale to your advantage.