Two costs eat into the early years the most: legal fees of $800 to $1,500 at purchase, and a mortgage's interest-heavy early payments, which build equity far more slowly than a payment made in year eight or ten of the same loan.
Rent working against you is the other half of the equation. Rent that rises even modestly every year compounds, while a fixed-rate mortgage payment on the same home does not, so the longer you stay after the breakeven point, the more owning pulls ahead.
If you can see yourself in the home past that three-to-five-year mark, the breakeven math tends to favour buying; sell sooner and the upfront costs are harder to recover. Get your hand-reviewed valuation from Joel Dyck.