If your home's value has soared, congratulations. If you decide to sell, beware.

Financial advisor James Guarino says some clients don't realize that home-sale profits are potentially taxable until their returns are prepared — and by that time, they may have spent the windfall or invested the money in another house.

"They're not happy campers when they find out that Uncle Sam not only is going to tax this as a capital gain, but they're also going to have some exposure at the state level," says Guarino, a certified financial planner in Woburn, Mass.

Longtime homeowners who took advantage of previous tax rules, which allowed people to roll the gains from one home into the next, could be in for a particularly nasty surprise. Those old rules could trigger taxes even if you're under the current $250,000-per-person exemption limits.

Understanding how home sale profits are calculated — and how you can legally reduce your tax bill — could save you money and stress if you're planning to cash in on the current home price boom.

How tax rules have changed

Until 1997, home sellers didn't have to pay taxes on their profits if they bought another home of equal or greater value within two years. In addition, people 55 and older could use a one-time exclusion to avoid paying taxes on up to $125,000 of home-sale profits.

The Taxpayer Relief Act of 1997 changed the rules so that instead of rolling profits into another home, homeowners could exclude up to $250,000 of home-sale profits from their income. To qualify for the full exclusion, home sellers must have owned and lived in the home at least two of the five years prior to the sale. Married couples could shelter up to $500,000.

Those exclusion limits haven't changed in 25 years, while home values have nearly tripled. The median home-sale price when the law passed was $145,800, according to the Federal Reserve Bank of St. Louis. The median was $428,700 in the first three months of this year. (Median means half of homes sold for less and half for more.)

Having a taxable gain on a home sale used to be relatively rare outside of high-end properties and high-cost cities, but that's no longer true, financial advisors say.

Why your tax basis matters

Your first step in determining your gain is to identify the amount you realized from the sale. That's the sales price minus any selling costs, such as real estate commissions. Then, figure your tax basis. That's generally the price you paid for the home, plus certain closing costs and improvements. The higher the basis, the lower your potentially taxable profit.

Let's say you realized $600,000 from your home sale. You originally bought it for $200,000 and remodeled the kitchen for $50,000. You'd subtract that $250,000 from the $600,000 to get $350,000 in capital gains.

If you're single, you could exclude $250,000 of the gain and pay tax on the remaining $100,000. (Long-term capital gains are normally taxed at 15% on the federal level, although a big enough profit could push you into the higher 20% capital gains bracket. State tax rates vary.) If you're married and can exclude up to $500,000 of gain, you wouldn't owe any tax.

How to reduce your gains

Another way to beef up your basis: home improvements. To qualify, the improvements must "add to the value of your home, prolong its useful life, or adapt it to new uses," according to IRS Publication 523, Selling Your Home.

Room additions, updated kitchens and new plumbing count; repairs or maintenance, such as painting, typically don't. You also can't count improvements that were later torn out or replaced.