If you can imagine buying a stock and holding it for 30 years, you're ahead of the game. By following that kind of investing philosophy, you give yourself a good chance of beating the market and perhaps becoming a millionaire. At the very least, you're likely to retire much richer than you are today.

There's no way to know for sure what will happen to any specific investment, but if you do your due diligence and choose a diversified collection of great stocks, the chances are good that you'll have a hefty nest egg. Home Depot (HD 1.15%) is one such stock, and if you had identified its potential 30 years ago, your nest egg would be well padded now.

Simple premise, excellent stock

Investors often get excited about the latest trends and hyped-up stocks. Just look at what's going on with artificial intelligence. However, the danger with focusing your investments on hyped-up trends is that they can fade away and take your portfolio's value with them. And because nobody can reliably and consistently "time the market," you won't necessarily know when the right time is to pull your cash out of those trendy stocks.

So if you do want to benefit from the rise of new ideas and technologies, invest in the companies that are pursuing them -- but balance those investments with some safe and secure stocks, too. That strategy doesn't have to mean resigning yourself to underperformance -- many fairly safe stocks can still deliver market-beating gains. Home Depot has seriously outperformed the market over the long term, and it also pays an above-average dividend. If you had invested $1,000 in Home Depot stock 30 years ago, held on, and reinvested your dividends along the way, you'd have a position worth nearly $60,000 today -- nearly 3 times as much as you'd have if you'd invested that same $1,000 in the S&P 500.

HD Total Return Level Chart

HD Total Return Level data by YCharts.

To take that a step further, if you could go back 10 years earlier to 1994 and invest that same $1,000, your position today would have compounded exponentially to a remarkable $2 million. And if you had invested $1,000 in Home Depot stock when it went public, just three years before that, you'd have a $29 million stake today.

That's the power of starting your stock investing journey early and holding onto your positions for the long term.