Mark Cuban and Kevin O’Leary agree that this is the best thing to do with your money

Kevin O'Leary
Scott Mlyn | CNBC

As sharks on ABC’s “Shark Tank,” investors Kevin O’Leary and Mark Cuban . But they do agree on one thing: Getting — and staying — out of debt is one of the best things you can do with your money.

Cuban in his 20s and realized that the money he lost to interest outweighed anything he could earn through investments in real estate or the stock market.

"Whatever interest rate you have — it might be a student loan with a 7 percent interest rate — if you pay off that loan, you're making 7 percent. That's your immediate return, which is a lot safer than trying to pick a stock or trying to pick real estate, or whatever it may be," he told MarketWatch.

He says that paying off all your debt in full is the anyone can make.

How Bill Gates, Serena Williams, Mark Cuban and others spent their first big paychecks

"Using a credit card is okay if you pay it off at the end of the month," Cuban told Money. "Just recognize that the 18 percent or 20 percent or 30 percent you're paying in credit card debt is going to cost you a lot more than you could ever earn anywhere else."

He’s right: The average return on long-term investments annually, so paying down debt with a 20 percent interest rate effectively earns you twice as much as you would get through an investment alone.

O’Leary agrees that eliminating debt is key to mastering your money. "If you want to find financial freedom, you need to retire all debt — and yes, that includes your mortgage," he .

O’Leary goes so far as to say that you should aim to have everything paid off, from student loans to credit card debt, by age 45.

Kevin O'Leary: Here's the age by which you should have your debt paid off

"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."

O’Leary emphasizes that, as you get older, your spending and responsibilities will only increase, from student loans in your 20s to financing a mortgage and having children. Start planning as early as possible for how to pay off that debt throughout your life, he suggests. That way, you can be financially secure by the time you retire.

However, for many, paying off debt is easier said than done. Americans now owe a record high $1.03 trillion in revolving credit card debt. If you want to work on getting out of the red, check out these tips to get started:

Don't miss: Suze Orman shares the biggest money mistake that almost everyone makes

Like this story? Subscribe to CNBC Make It on YouTube!

Kevin O'Leary: It's crazy to rely on a joint bank account — even if you're married