You probably don't need me to tell you this, but 2022 has been an awful year for Wall Street. The S&P 500, which is viewed as the most encompassing of the major U.S. indexes, produced its worst first-half return since 1970. Meanwhile, the Nasdaq Composite has shed as much as a third of its value, which easily pushed it into bear market territory.

But it's not all bad news. Even though things appear dire for the stock market right now, history has shown that every bear market decline and correction throughout history is a buying opportunity. When given enough time, every notable decline has eventually been cleared away by a bull market.

Of course, owning great companies helps build wealth, too. Just ask shareholders of e-commerce giant Amazon (AMZN -1.07%).

A person holding an Amazon package under their right arm while a child holds a door open for them.

Image source: Amazon.

$10,000 invested in Amazon on its debut day is worth a staggering amount of money today

When Amazon went public on May 15, 1997, the benchmark S&P 500 closed at 841.88. Not counting dividends, the index has since gained 360%. Inclusive of dividends, the total return of the widely followed S&P 500 jumped to 636%, as of this past weekend.

That's an average annual total return of better than 8% for the past quarter of a century. But to Amazon shareholders, it's peanuts.

Since Amazon's initial public offering (IPO) at $18 per share on May 15, 1997, the company that Jeff Bezos founded has undergone four stock splits: 

This means the original IPO cost basis, if held for the past 25-plus years, would be just $0.075 today. It also means that patience would have paid off immensely for Amazon's original stakeholders.

If you had invested $10,000 in Amazon at its IPO price in 1997, you would have purchased 555 shares, not including commission expenses or fractional shares. Taking into account Amazon's four stock splits, these 555 shares would have multiplied into 133,200 shares, as of today.

With Amazon ending the previous week at $123.53, it means a $10,000 investment a little over 25 years ago would now be worth (get this...) $16,454,196. For those of you keeping score at home, we're talking about an aggregate return of 164,607%, or an average annual return of around 34% for a quarter of a century.

Here's why Amazon has been so dominant for so long

How, exactly, does a company rise from relative obscurity to become one of the largest stocks in the world by market cap? The answer is Amazon's leading online marketplace.

The evolution of Amazon's platform beyond just selling books in 1998 really set the stage for its popularity today. According to a March report from eMarketer, Amazon is on pace to bring in about $0.40 of every $1 in U.S. online retail sales this year.

For some context, that's many multiples higher than the next-closest competitor and 8 percentage points of market share more than No. 2 through No. 15 in the U.S. online retail space, combined! Amazon has effectively established itself as the go-to platform for online purchases.

Of course, Amazon's marketplace has fueled numerous other avenues of growth. As of April 2021, the popularity of the company's marketplace had helped it sign up more than 200 million Prime members worldwide. Prime members are paying $139 annually or $14.99 monthly for a variety of perks that include free/faster shipping and access to exclusive streaming content. It's worth mentioning that Amazon is the exclusive content provider of Thursday Night Football beginning this season, which could be an impetus to signing up even more Prime members.

Another factor that's made Amazon unstoppable is its willingness to reinvest in its business. While most Wall Street analysts preach the importance of profitability when analyzing publicly traded companies, Amazon has made a habit of shunning near-term profits in favor of reinvesting its operating cash flow. The company's robust cash flow has allowed it to expand its logistics network, grow its content library, and invest in high-growth initiatives.

Lastly, cloud infrastructure-service segment Amazon Web Services (AWS) has been pivotal to the company's success in recent years. AWS accounted for an estimated 31% of worldwide cloud-service spending in the second quarter, according to a recent report by Canalys. More importantly, cloud growth is still in the very early stages. If AWS was a separate entity, it would likely be the most valuable cloud-computing company in the world.

Silver dice that say buy and sell being rolled across a digital screen displaying stock charts and volume data.

Image source: Getty Images.

With economic headwinds mounting, is Amazon still worth buying?

Taking a trip down memory lane and wondering "what if?" can be fun. What hasn't been fun is Amazon's year-to-date performance -- a 26% decline.

The most obvious issue for Amazon is the weakening U.S. economy, which started 2022 with back-to-back quarterly declines in gross domestic product. Although retail sales data has remained resilient, largely due to historically high inflation, history would suggest that Amazon's leading online marketplace is poised to struggle in the coming quarters.

To add to the above, high inflation tends to have its biggest negative impact on the lowest-earning decile of consumers. This probably means reduced buying activity on Amazon's online marketplace. We're already seeing evidence of these struggles, with Amazon's non-AWS operations producing an unsightly $5.2 billion operating loss through the first six months of the year. 

But even though Amazon generates the bulk of its sales from its online marketplace, weakness in this segment will have a relatively small impact on the company's cash flow generation. That's because online retail sales often produce razor-thin margins. What really matters for Amazon is that the needle is moving higher for its three ancillary segments with higher margins: subscription services, advertising, and AWS.

Subscription services and advertising services are each generating approximately $35 billion in annual run-rate revenue, and the margins associated with both segments are considerably higher than online retail sales. As for AWS, it accounts for roughly a sixth of Amazon's net sales yet has consistently brought in over half of the company's operating income. With these three operating segments chugging along, Amazon could potentially triple its operating cash flow by the end of 2025, even if its online marketplace stagnates.

Historically, operating cash flow has been the best measure of "value" when analyzing Amazon. Throughout the 2010s, investors comfortably paid a multiple of 23 to 37 times year-end cash flow.

But if Amazon is successful in tripling its operating cash flow by mid-decade, then investors have the opportunity to buy it at just below nine times Wall Street's estimated future (2025) cash flow. In other words, even with economic headwinds mounting, Amazon remains as compelling as ever from an investment perspective.