Real estate investing is so simple I can explain it in a few sentences.
You have a property. You have a price. You have an NOI (net operating income–the money the property produces before you figure in interest and taxes). NOI/price is essentially the ROA (return on asset(s)) or in RE parlance, the “cap rate.” If a property is producing income, the bank will loan you money to buy it with the property itself as collateral. You pocket the percentage difference between the loan percent and the cap rate, deduct for interest expense, pay taxes on that amount, and voila, you’ve made money. The fact that you used the bank’s money instead of your own to buy the property is called “leverage.” This is how most RE deals work.
The same principle applies to buying a home. As everyone knows, you are allowed to deduct the home loan interest from your personal taxes, much in the same way that a business can deduct interest expense. Now imagine you had a home that was free and clear worth $100k. A home loan will run you 6% interest. If you mortgage your house and get $100k, you can then invest that money. If you can earn a return of more than 6%, then you are profiting. But the government further sweetens the deal by making that interest, in this case $6,000 for the first year, deductible. If your tax rate were 33%, then you would save $2,000 on taxes, so it is really as though you were paying 4% in interest. If you can get a return of over 4%, you are in the black. (There is no way the above numbers are going to be that simple, but this illustrates the idea: the deductibility of the interest effectively lowers the return you need to make the transaction profitable for you).
If you can earn a capital gain on your home, so much the better. The government also sweetens that deal in a major way by making up to $500k free of capital gains tax (for a married couple, $250k for a single person) if you live in the home for 2 of 5 years or something like that (check with people who know all this cold before investing!). So you can make a mint on your house and not pay a dime in tax!
What takes away the sweetness of the above deal is additional costs such as maintenance, taxes, and insurance (noted by previous poster). BUT, you have to live somewhere, and it still usually beats renting (freedom, etc., noted by previous poster).
The above, ceteris paribus, will generally make owning a home preferable to renting. But there are plenty of potential and, in certain US markets, actual exceptions. We looked at houses in Tokyo where houses are considered fully depreciated and trashable in 30 years (i.e., you never get a capital gain on the building) and where average land prices are 50% OF what they were 10 years ago. You are almost certain to take a capital loss on anything you buy. In such a market you buy for QoL and usually intend to settle down for good in that house.
In certain US markets, the market is such that it is cheaper to rent the asset than to buy it. When you consider in, out, risk, mobility, and total lifetime value of the transaction. I can’t imagine it being a good idea to buy a condo in Manhattan as opposed to renting a similar space, but I would like to see the numbers.