Kevin O'Leary: This is the age when you should have your mortgage paid off

Americans hold $8.88 trillion of mortgage debt, according to a February report from the Federal Reserve Bank of New York. It's the largest type of household debt in the country, and it increased "substantially" during the fourth quarter of 2017 — up $139 billion, according to the report.

If you're one of those millions of people with a mortgage, your top priority should be paying it off before retirement, according to Kevin O'Leary.

"If you want to find financial freedom, you need to retire all debt — and yes that includes your mortgage," the personal finance author and co-host of ABC's "Shark Tank" tells CNBC Make It.

"The reason I say 45 is the turning point, or in your 40s, is because think about a career: Most careers start in early 20s and end in the mid-60s," O'Leary says. "So, when you're 45 years old, the game is more than half over, and you better be out of debt, because you're going to use the rest of the innings in that game to accrue capital."

But unlike other types of debt (like big credit card bills), taking out a mortgage on a home that appreciates in value can be a smart decision. In 2017, homeowners with a mortgage saw the equity in their home increase in value by an average of $15,000 according to CoreLogic.

"Mortgages are more of a gray area than credit card debt, because real estate can be an investment," O'Leary explains. Still, he advises you to think long and hard before taking on a mortgage at all.

"It's not always a good investment, and in my opinion, most people in their 20s, or even 30s, have no reason to be taking on that kind of debt," he says. "Homes don't always gain as much value as you expect — at least not anymore, and at least not quickly."

If you do decide to take on debt to buy a home, O'Leary's advice is simple: Get it paid off as soon as you can. If you already hold a mortgage on your home, O'Leary argues paying it off should take a higher financial priority than using extra cash to invest in things like stocks or bonds.

"There's never an incentive to stay in debt," O'Leary says. "Life is unpredictable. What happens if you're laid off or incur unexpected expenses elsewhere? Your once-manageable mortgage is suddenly going to seem not-so-manageable."

Personal finance expert Suze Orman agrees. If you plan to stay in your home through your golden years, you should get your mortgage paid off before you retire.

"You should be grabbing every opportunity you can to eliminate the known risks in your retirement plan," Orman writes in Money. "If you know you want to stay in your home, paying off the mortgage is a great way to build security."

Self-made millionaire and wealth management expert David Bach even says paying off your mortgage as quickly as possible is a step toward retiring early.

"I can tell you, having been a financial advisor at Morgan Stanley, my clients who retired at 50 years old, the secret was: They had paid their mortgage off early," Bach tells CNBC Make It. With a 30-year mortgage, make a plan to pay it off in 20, or preferably 15 years, he says. To do that, contribute an extra 20 percent to your monthly mortgage payment by scrimping and saving elsewhere.

So before you decide to pay off your mortgage early, consider a few questions to pinpoint your financial goals: Where will your money earn the greatest return? What level of risk are you willing to take? How much access to your money do you need? Then, make the best decision for you.