Deductions & credits

You're eligible for the exclusion if you have owned and used your home as your main home for a period aggregating at least two years out of the five years prior to its date of sale. You can meet the ownership and use tests during different 2-year periods. However, you must meet both tests during the 5-year period ending on the date of the sale.

 

See https://www.irs.gov/taxtopics/tc701