Even with today's generous rules, selling a home could trigger an ugly tax bill. Here are four ways to avoid that.

These days, most homeowners are in a pretty comfy spot. Home prices across the country have appreciated considerably in recent years — and in many cases, those gains will be tax free once it comes time for owners to sell.

Unfortunately, sellers with truly substantial gains as well as those who don't meet the home-gain exclusion requirements could be left out in the cold. Ditto for those who simply aren't familiar with what qualifies for the tax-favorable treatment, and wind up missing out on potentially tax-friendly moves.

But don't despair. Some creative maneuvering here and there can make all the difference between a big tax hit and no hit at all. What follows are four tax-slashing strategies. But first, bear with us while we review the rules that allow a home sale to be a tax-free transaction.

Gain Exclusion Basics
For federal income-tax purposes, an unmarried person can sell a principal residence for a profit of up to $250,000 and exclude the entire gain from taxes. That's right, Uncle Sam gets nothing. Married folks who file jointly can exclude up to $500,000. But to qualify, you generally must pass both of the following tests:

1. The ownership test. You must have owned the property for at least two years during the five-year period ending on the sale date.

2. The use test. You must have used the property as a principal residence for at least two years during the same five-year period. (If it's less than that, the exclusion can often be pro-rated. Click here for more on this.)

To be eligible for the larger $500,000 joint-filer exclusion, at least one spouse must pass the ownership test, and both spouses must pass the use test. Also, the $500,000 exclusion is available only when neither spouse has claimed an exclusion for an earlier sale within two years of the sale date in question.

Don't think you'll qualify? Think again. Here are some strategies that could make you eligible for this terrific tax break.

1. Get Hitched for Greater Home Sale Tax Savings
Say you're single and own a home that could be sold for a profit well above the $250,000 gain exclusion for unmarried folks. I have two words of advice: Get married!

Am I crass for recommending marriage just to reduce your tax bill? Perhaps. But the fact is, you could take advantage of the larger $500,000 joint-filer gain exclusion by selling your home in the year you get married or in a later year. This could reduce your federal income-tax bill by as much as $37,500 ($250,000 times the 15% maximum rate on long-term capital gains). Remember: This is a permanent savings; not just a timing difference.

Unfortunately, this strategy may require some patience, because both you and your new spouse must have used the home as your principal residence for at least two years during the five-year period ending on the sale date. The good news: If your spouse lived in the home before your marriage, you can count this time toward the two-year requirement.

2. Plan Ahead for Home Sale After a Divorce
After a divorce, your ex-spouse might still live in your former principal residence while you continue to own all or part of the property. Here's the rub: After three years of being out of the house, you'll automatically fail the use test explained above. This could potentially be very costly because once the home is sold, you won't have any gain exclusion break to shelter your share of the profit. In other words, you'll be taxed on 100% of your portion of the home sale gain.

Fortunately, you can avoid this outcome by taking action before your divorce is finalized. What you need to do is make sure your divorce or separation agreement specifically grants your soon-to-be-ex permission to continue living in the home for whatever period is reasonable — five years, or until the youngest child graduates from high school, or whatever makes sense. (Naturally, your ex isn't actually required to remain in the home any longer than he or she desires.)

Putting these magic words into your divorce paperwork allows you to take credit for your ex-spouse's continued use of the home as his or her principal residence. When the property is finally sold, you can claim a $250,000 gain exclusion — assuming your ex used the home as his or her principal residence for at least two years during the five-year period ending on the sale date. You can do this even though you haven't actually lived in the home for years.

3. Claim Tax Break for Sale of Land Next to Your House
Most people think the home-sale exclusion applies only to their houses. Not so. The IRS also allows home-sale gain exclusions from the sale of vacant land adjacent to your house. In fact, you can do this even when the land sale occurs in one or more transactions that are completely separate from your house sale.

In order to qualify, the land must: 1) be adjacent to the parcel that contains your house and 2) have been used as part of your principal residence (as opposed to being used for business or rental purposes) for at least two years during the five-year period ending on the sale date. So the gain exclusion break isn't available for land you've always used for a horse farm or tenant farming operation. In addition, you must sell the adjacent land within two years before or after selling the parcel that contains your house.

Assuming you pass these tests, you can use your gain exclusion ($250,000 or $500,000, whichever applies) to shelter the combined profits from selling the parcel that contains your house and the parcel (or parcels) of adjacent land.

How much vacant land can you sell under this loophole? According to an example in the IRS regulations, you could sell at least 29 acres and still take advantage of the gain exclusion privilege.

4. Don't Sell Your Greatly Appreciated Home
If you are fortunate enough to own a hugely appreciated home, selling could trigger a taxable gain far in excess of your gain exclusion break ($250,000 or $500,000, whichever applies). Should you fall into this category, your best bet may simply be to stay put, if you can bear the thought of doing so.

Say, for example, you and your spouse own a home worth $3 million. You've lived there for years and your tax basis in the property (original cost plus cost of improvements) is only $700,000. If you sell, you would face a whopping $1.8 million taxable gain even after claiming the $500,000 joint-filer exclusion ($3 million value minus $700,000 tax basis minus $500,000 exclusion equals $1.8 million taxable gain). The combined federal and state capital gains tax hit would probably be at least 20%, which translates into $360,000. Not pretty.

You would get a much better tax result by hanging onto the home until the bitter end. Then, when you or your spouse dies, the tax basis of the deceased spouse's share of the property is stepped up to fair market value as of the date of his or her death. The surviving spouse then could sell the home shortly after the first spouse's death. In this case, the survivor is entitled to the $500,000 joint-filer gain exclusion (based on the stepped-up tax basis of the home), provided the sale occurs during the year of the first spouse's death. If the sale happens later, the survivor can still claim the $250,000 exclusion for unmarried taxpayers. By taking advantage of the stepped-up basis rule, chances are all or most of the profit can be sheltered by the gain exclusion break.

Alternatively, the house could be kept until the second spouse dies as well, in which case the tax basis of that person's share gets stepped up, too. So your heirs (probably your kids) could then sell the property and owe little or nothing in capital-gains taxes.