There isn't an exact amount of time, because so many factors can change this from person to person, from place to place, etc.
However, I was in this exact situation about a year ago and solved it by considering as many factors as possible. Here is a list of several factors you should consider...
- Expected real-estate growth (I used the national average of about 3%)
- Expected investment growth (I used the historical average of about 7%)
- How long you expect to stay in the area (I wasn't sure how long I would stay in it, so I considered it for every month over the first 3 years)
- The cost for the home (including costs when you resell the house someday)
- The cost for rent
- Expected cost of owning a home (taxes, maintenance, etc.)
- Let's say your rent is $1500, but your mortgage would be $2000 (roughly $500 to principle and $1500 to interest over the first couple years). If you just rented and invested the $500, would this change the situation?
- Any other factors that could be specific to your situation (for me, I had a signing bonus that I could consider investing or placing toward a home downpayment)
I'm a software engineer, so I wrote a small program that considered all these factors for me. You can also do it via excel, or just with pen and paper. I live in the Philladelphia area. With all these factors considered, the break even point was roughly 2 years. If I lived in this area for less than 2 years, I should rent. Otherwise, I should buy.