Buying a new home is a big decision that involves a whole lot of smaller ones. Many people focus on the number of bedrooms or the quality of the kitchen appliances as they contemplate where they want to live.

But new homebuyers shouldn't let considerations like those persuade them to buy a home that's more expensive than they can comfortably afford.

With home prices on the rise in many parts of the U.S., keeping things affordable is getting harder to do. In May the median listing price for a home rose 6 percent from the previous year, to $315,000, a record high, according to a report by Realtor.com. Meanwhile, the number of homes priced above $750,000 rose 11 percent from a year ago.

Buyers say that those high prices are forcing them to spend more than they planned. One-third of buyers report that they spent more than they expected to on their home, and nearly one-third put down a higher down payment than they anticipated, according to a June survey by CoreLogic, a real estate data analytics firm.

More on Home Ownership

Financial planners recommend limiting the amount you spend on housing to 25 percent of your monthly budget. Yet the average married couple with children between the ages of 6 and 17 spends 32 percent of their budget on housing, and single people spend almost 36 percent, according to data from the Bureau of Labor Statistics. 

And when people take on mortgages that are larger than they planned for, it becomes more difficult for them to reach other financial goals, such as saving for a child's college education or their own retirement.

To make sure you don't spend more than you should, here's some advice on getting a mortgage you can afford.

Follow the 25 Percent Rule

There's a straightforward way to make sure you can afford your mortgage while managing your other goals, according to Eve Kaplan, a certified financial planner in New Jersey. "Housing—including maintenance—ideally shouldn't consume more than 25 percent of a household budget. This goes for folks who rent, too," Kaplan says.

Mortgage bankers would disagree. They use various calculations to figure out how much you can afford, and the amount is often much higher than financial planners recommend. A common measure that brokers use is the debt-to-income ratio (DTI), which, for a qualified mortgage, limits your total debt payments, including your mortgage, student loans, credit cards, and auto loans, to 43 percent.

Let's say you and your spouse make a combined annual income of $90,000, or about $5,600 per month after taxes. Based on your DTI and depending on your other debts, you could be approved for a mortgage of $600,000. That might sound exciting at first, but with a monthly payment of about $3,225, it would eat up more than half your take-home pay. 

Following Kaplan's 25 percent rule, a more reasonable housing budget would be $1,400 per month. So taking into account homeowners insurance and property taxes, you'd be better off sticking to a mortgage of $240,000 or less. If you have enough for a 20 percent down payment, the maximum house you can afford is $300,000.  

"People think, ‘I'm making really good money. I should be able to afford this,'" says Mary Beth Neeley, a certified financial planner and financial advisor at Wealth Enhancement Group, a financial planning firm in Jacksonville, Fla. "But most people don't consider saving for the future. You have to put your priorities in place and look at all your goals. You don't want to have a house that adds stress to your financial situation." 

Neeley asks clients an important question when trying to help them determine what they're willing and able to spend on housing: "Do you really want to change your lifestyle to have a more expensive home?" 

Aim to Put 20 Percent Down

The amount of mortgage you can afford also depends on the down payment you make when buying a home. "In a perfect world, we recommend a 20 percent down payment to avoid paying mortgage insurance," Neeley says.

When your down payment is less than 20 percent, your costs rise. You typically have to pay private mortgage insurance, which can cost up to 1 percent of the entire loan amount each year until you build up 20 percent equity in your home. On a $240,000 mortgage, that's $200 per month.

Keep in mind that you will have other ongoing costs related to homeownership as well, including taxes, insurance, and utilities. All of these expenses need to be estimated before you settle on a monthly mortgage payment.

Don't Be Fooled by the 5-Year Rule

Kaplan says homeowners usually need to stay put for at least five years to make the closing costs of buying a home worthwhile. That's a useful rule of thumb, but if you're thinking of staying that long, you may be tempted to opt for a mortgage that's higher than you can comfortably afford now. Be careful. Predicting future income isn't as easy as it may seem. Kaplan cautions that stretching your budget can backfire if you become unemployed for an extended period.

When they're planning for the long term, many homebuyers may also see their home as an investment for the future, which can be an excuse for spending more today than they can easily afford. But real estate can be volatile, as we saw in the 2008 housing crash. Having too much of your net worth tied up in your home can be risky. 

Realize That Other Expenses May Come Up

Even if your mortgage doesn't stretch your budget, an unexpected job loss or other event could cause you to struggle to make your mortgage payments. The more affordable a home is in the first place, the better chance you'll have of recovering.

Building up an emergency fund is easier if you limit your mortgage payment to 25 percent of your take-home pay. The more cash you have on hand, and the lower your monthly obligations, the better chance you'll have of staying afloat if difficult times strike.