It depends. You need to have lived in the house for a minimum of 2 years (730 days) out of the last 5 years. So, the sale would need to occur no later than 3 years from when you last occupied the home as a primary residence, assuming you lived there for at least 2 continuous years. You can't delay changing your mailing address to meet this rule.
Refer to Publication 523 for details of the eligibility test to determine if you can exclude the gain of $250,000 (or $500,000 if married filing jointly) on the sale of a principal residence.