People often aspire to own a home for reasons that have little to do with money, and rental options are limited in some communities. Yet owning property can limit your flexibility to move when you want and ties up a lot of your money.

The median sales price of existing single-family homes rose 11.4% in 2013 from the previous year—the highest yearly increase since 2005, according to the National Association of Realtors. Prices in many places, including Los Angeles, Baltimore and Portland, Ore., rose even more last year.

The monthly cost of renting was lower than buying in 20 large metropolitan areas.

Renting had been less expensive than buying on average across all the areas the Deutsche Bank tracks since at least the early 1990s.

But that changed during the financial crisis, as home prices plummeted and interest rates on mortgages dropped. The current rally in home prices appears to be pushing the housing market back toward the historical norm.

The five markets where renting recently became cheaper than buying include some popular cities and suburbs where home prices are climbing fastest: Sacramento, Calif.; Phoenix; San Bernardino and Riverside, Calif.; Austin, Texas; and Northern Virginia.

Buying is still cheaper in 34 metropolitan areas.

The buying advantage was slight in some places. Miami, San Antonio and Las Vegas are among the hot markets where renters appeared to be on the verge of being better off than buyers at year-end, according to the bank’s figures.

Buyers, of course, can build up equity as they pay down a mortgage, which can compensate for higher monthly costs.

Here is what you need to know to help figure out the most cost-effective way to keep a roof over your head. The first step is to understand the arguments in favor of buying and renting.

The Case for Buying

Many Americans see buying a home as an essential step in a successful life, and owning one can bring significant financial benefits.

The most obvious upside is that a home can significantly increase in value. The median sales price of existing single-family homes rose 81% from 1993 through 2013, according to the NAR.

The potential payoff can loom large in a buyer’s mind when home prices are going up rapidly, as they have recently.Many homeowners also can deduct mortgage interest from their income-tax bills along the way.

In addition, homeowners can tap into the equity in their homes for big-ticket expenses, such as college tuition, at interest rates that can be lower than other financing options.

Homeowners also don’t have to worry about a spike in rents.

Owning a home can be well worth it for personal and psychological reasons that go beyond financial calculations.

The Case for Renting

Given the wide array of potential benefits, homeowners are sometimes surprised to learn that buying isn’t always the smartest financial option.

To begin with, the monthly cost of renting can be lower, even for a home of similar size and quality in the same community.

Renters, for example, don’t pay property taxes, homeowner’s insurance and, in most cases, maintenance costs. These expenses can cost homeowners about 3% of the price of their home annually, experts say.

While those costs can be folded into monthly rent, apartment renters often pay a smaller share as landlords spread the costs among many tenants, says Stijn Van Nieuwerburgh, director of the Center for Real Estate Finance Research at New York University. If a window breaks or the toilet plugs up, your landlord—not you—pays for the repairs.

Renters don’t end up with a valuable asset, as buyers do when they pay off a mortgage. But renters might be able to make more money by investing the monthly savings, as well as the cash they would otherwise use for a down payment, he says.

The value of the average single-family home increased by 3.6% a year in the three decades through 2013, compounded annually, according to mortgage giant Freddie Mac. By contrast, the compound annual return on the S&P 500 over that period was 11.1%, according to Chicago-based investment-research firm Morningstar.

After moving to New York two years ago, Hunter Kearney, 27, looked into buying a condominium worth at least $2 million. But Mr. Kearney, an executive at a firm that sells graphite, concluded that renting a similar apartment was significantly less expensive.

“Your monthly costs end up being lower,” says Mr. Kearney, who says he saves about $2,000 a month over the cost of buying. He is investing some of the savings in the stock market.

Renters often have greater flexibility to move to a different part of the country, which can be important in a weak job market. They may feel freer to look for work in another city, and they don’t have to wait to sell their home if the right opportunity opens up.

Housing prices don’t need to decline as severely as they did during the financial crisis to cost homeowners significant sums, if they need to sell during a downturn. Modest declines in home prices are common.

Even people who want to own a home at some point can benefit from renting for a while to save up for a larger down payment. If the available inventory is thin, they can rent while they wait for a wider variety of homes to be listed for sale.

Handling a Hot Market

To calculate whether buying or renting makes more sense financially, you need to have a sense of your monthly costs in each case, including rent, mortgage payments, taxes, insurance and other related expenses that may apply to each option—as well as whether you would be more likely to spend or invest any savings from renting.

First, they should try to get a sense of how hot the local real-estate market is and whether buyers generally still have the upper hand.

If you are in a more-competitive market, be alert to the risk that you could end up in a bidding war that could drive up the purchase price.

Being patient could pay off if prices cool down. In fact, slight corrections already have occurred in some markets.

Even in a hot market, the math can be more advantageous for buyers who plan to stay put for a while, typically at least five to seven years.