Please see for reference IRS publication 523 - http://www.irs.gov/pub/irs-pdf/p523.pdf
To claim the exclusion, you must meet the ownership and use tests. This means that during the 5-year period ending on the date of the sale, you must have:
Owned the home for at least 2 years (the ownership test), and
Lived in the home as your main home for at least 2 years (the use test).
If you have more than one home, you can exclude gain only from the sale of your main home. You must include in income gain from the sale of any other home. If you have two homes and live in both of them, your main home is ordinarily the one you live in most of the time.
In addition to the amount of time you live in each home, other factors are relevant in determining which home is your main home. Those factors include the following.
Your place of employment.
The location of your family members' main home.
Your mailing address for bills and correspondence.
The address listed on your:
Federal and state tax returns,
Car registration, and
Voter registration card.
The location of the banks you use.
The location of recreational clubs and religious organizations of which you are a member.