There's no denying that investing in the stock market is one of the best ways to build wealth. The S&P 500 has produced a respectable return over the long run. But individual businesses have fared significantly better. Just look at Home Depot (HD -1.65%).

This top-retail stock has generated a total return, including dividends, of 2,786,000% since its initial public offering (IPO) in September of 1981. If you invested $1,000 at that time, you'd have nearly $28 million today. That's a spectacular gain.

Let's take a closer look at Home Depot's monster success. Then, investors can look at the company today with a fresh perspective before deciding if the stock is a smart buying opportunity.

Following a proven playbook

Home Depot sells a wide range of tools and supplies to do-it-yourself (DIY) and professional customers to help them tackle renovation projects. This was the case 40 years ago, and it's still true today. The only notable difference is the scale of this business.

Today, Home Depot is one of the world's largest enterprises, valued at $338 billion. And it has come to dominate the industry, generating $153 billion in fiscal 2023 revenue. That's nearly double the amount that its smaller rival, Lowe's, reported last fiscal year.

The key part of Home Depot's strategy has been to open new stores across the country. Bernie Marcus and Arthur Blank, the co-founders of the retail giant, figured out early on that the best plan was to expand the store base. In 1993, the business had just 264 locations. As of Feb. 20, there were 2,335 stores, with some in Canada and Mexico. It's wild to think that there's a Home Depot location within 10 miles of 90% of the U.S. population.

This broad reach has resulted in a company that generates enough revenue to put it 20th on the Fortune 500 list. Plus, Home Depot produces consistent net income and free cash flow.

That financial success has certainly been the main ingredient that has rewarded investors over the long term. What's more, Home Depot hasn't shied away from returning copious amounts of cash to shareholders. In fiscal 2023, $8.4 billion was paid in dividends, and $8 billion was used to buy back stock. This capital allocation policy is something that investors can bank on.

Should you buy Home Depot stock?

It's inspiring to look at a company and its remarkable historical success. What Home Depot has done to get to a point of dominating the industry is noteworthy. But prospective investors need to view things with a fresh perspective before deciding what to do with the stock.

To be clear, Home Depot has hit a bit of a rough patch. The blame can rest on the current macroenvironment. Higher interest rates and inflationary pressures discourage people from wanting to take on expensive renovation projects. This helps explain why same-store sales fell 3.2% in last year, with management expecting a 1% drop in fiscal 2024.

But there are reasons to be bullish. The average age of homes in the U.S., now at about 40 years, helps support demand for renovation projects. And with a long-running housing shortage, consumers are incentivized to stay in their current homes, focusing on ways to spruce them up.

The other reason to want to buy shares is that the stock is down 14% in the past few weeks (as of May 3). This dip presents investors with a more compelling buying opportunity. Shares trade at a forward price-to-earnings ratio of 22.2.

Home Depot shares aren't going to put up the same type of return that they did in the past few decades. But based on the facts today, the stock still looks like a smart addition to your portfolio.