When buying a home, it takes an average of four years to break even on the upfront costs of the purchase, such as a down payment and closing costs. The study also shows that the rate of return is expected to fall between 8% and 10% each year. These figures demonstrate that buying a house may not be worth it if you plan on living there for less than five years, otherwise you risk losing money. A piece of advice to help increase the rate of return is to refrain from stretching your budget and not buying more house than you need.
Source: https://www.forbes.com