If I had a time machine and could go back 40 years, The Home Depot (HD -0.58%) stock would be on my list of stocks to buy. The company reimagined what a home-improvement store could be with its sprawling spaces stocking more products than traditional shops. This allowed for rapid expansion to over 2,300 locations today.

A $10,000 investment in The Home Depot stock 40 years ago would be worth nearly $15 million today. And reinvesting dividends would have resulted in an investment worth over $25 million.

HD Chart

Data by YCharts.

Shares of The Home Depot trade near their all-time high at over $415 as of this writing. But as spectacular as its returns have been long term, they've cooled in recent years. The Home Depot stock has delivered a total return of 112% in the last five years.

That's still a solid result, but there's a new stock to watch in the home-improvement space. Shares of flooring specialist Floor & Decor (FND -1.16%) are up 147% over the last five years, and this little-known stock could outperform The Home Depot over the next five years too. Here's why.

Why Floor & Decor was and is the better buy

An investment thesis is the core explanation for why a stock will go up (or down). For Home Depot, it's only opened 55 net new stores over the last five years, growth of just about 2%. This isn't surprising considering how large it already is, but it does limit the company's opportunity for top-line growth.

The investment thesis for Home Depot stock, therefore, largely revolves around its profit margins and its returns to shareholders. Regarding profit margins, the company is already among the best in the business with a net margin between 9% and 10%. That also leaves little room for improvement -- margins can only be so high in this competitive category of retail.

One of the main ways Home Depot stock creates value is by returning cash to shareholders through dividends and share repurchases. This can be powerful over the long term, and don't misunderstand: Home Depot is a great business and many investors rightly plan to keep holding shares. But Floor & Decor has greater room for improvement, and that's why I believe the stock offers higher upside.

It's not just a theory: Floor & Decor stock outperformed Home Depot stock over the last five years because it grew revenue and operating profits faster, as the chart below shows.

HD Revenue (TTM) Chart

Data by YCharts.

Floor & Decor's ongoing path to top-line growth is simple. It has 241 locations today and should end the year with about 250. Next year, it plans to open 25 more -- that's good for 10% unit growth. And long term, it intends to have 500 stores across the country.

Same-stores sales have dropped recently for Floor & Decor -- management expects them to be down about 8% for the full year. But that's unusual and likely driven by a weak housing market more than anything. In 2022, the company capped off its 14th consecutive year of gains.

Lower same-store sales have also depressed Floor & Decor's profit margin. Right now it's below 5% whereas it was previously in the 7% to 8% range.

FND Profit Margin Chart

Data by YCharts.

Home sales in September fell to their lowest levels since 2010, according to the National Association of Realtors. It's reasonable to assume this is the culprit for Floor & Decor's sluggish sales. The problem should correct within the next five years. And when it does, same-store sales should perk back up, boosting the company's margins as well.

Between the new store openings, same-store-sales growth, and profit margin expansion, I believe Floor & Decor will not only outperform Home Depot over the next five years but the S&P 500 as well.