Buying a house is expensive. Everybody knows that, but even people who work very hard to prepare for the cost of owning a home are often surprised by how much they end up paying. 

That's particularly true among consumers whose loans require private mortgage insurance (PMI). A study released last week by TD Bank showed 65% of homeowners with PMI caused them to pay a higher-than-expected monthly mortgage payment. 

A borrower is required to get PMI if the loan exceeds 80% of the property's value (meaning the borrower provided a down payment less than 20% of the value), according to the U.S. Department of Housing and Urban Development. The purpose of the insurance is to protect the lender against losses in the event of loan delinquency, and it also allows consumers to purchase a home with a smaller down payment. It's not a permanent expense: Once the homeowner builds up sufficient equity in the home, PMI is canceled (the homeowner can request cancellation at 20% equity, or the lender cancels it automatically at 22%, as dictated by the Homeowners Protection Act of 1998). 

Among people who purchased a home in the past two years, 35% said PMI impacted their decision of which house to buy. It's also pretty common for people to make down payments of less than 20%: 45% of those ages 18 to 34, 37% of homebuyers ages 35 to 54 and 23% of people older than 55 required mortgage insurance on their loans over the past decade, the TD Bank study showed. 

PMI costs an average of $100 a month, according to the report, and FHA loans now require mortgage insurance for the life of the loan. (The Federal Housing Administration insures these loans, which can require as little as 3.5% down.)

It's easy to see how PMI can add up and cost consumers more than they anticipated. Getting a mortgage can be a complicated process, and it can be especially difficult for first-time homebuyers to understand all the costs associated with homeownership.

Read More from Credit.com

Why You Should Check Your Credit Before Buying a Home         

How to Search for Your Next Home

How to Get Pre-Approved for a Mortgage