In a recent interview with MarketWatch, billionaire Mark Cuban shared the best investment anyone can make: "Paying off your credit cards. Paying off whatever debt you have."

Cuban, who struggled to keep himself on the right side of his credit card debt in his 20s, learned the hard way that the money saved on interest by not having debt is better than any return you could get by investing your money, whether in the stock market or in real estate or elsewhere.

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

If you have credit card debt, the interest rate may be much higher than that: The typical credit card charges about 15 percent, which can end up costing you a fortune if you continually miss payments or only pay the minimum on your balance each month. Many people fall into that trap and, today, the average household with revolving credit card debt pays nearly $1,000 in interest annually.

To avoid losing out on interest payments, Cuban recommends ditching your plastic altogether, though he also notes, in an interview with Money, that "using a credit card is okay if you pay it off at the end of the month. 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."

If you've paid off your high-interest debts, the next best way to invest your money is to put it in a cheap S&P 500 SPX fund, Cuban says. A Standard & Poor's 500 index fund will hold 500 of the largest U.S. companies in the United States. It offers diversity at a low cost and generally delivers good long-term returns.

Chairman and CEO of Berkshire Hathaway Warren Buffett agrees. "Consistently buy an S&P 500 low-cost index fund," the legendary investor tells CNBC. "I think it's the thing that makes the most sense practically all of the time."

And stay the course, even through periods of no returns or losses, Buffett says: "Keep buying it through thick and thin, and especially through thin."

Like this story? Like CNBC Make It on Facebook!

Don't miss: Most Americans are breaking Mark Cuban's No. 1 wealth-building rule

