Amazon (AMZN 0.81%) stock soared approximately 75% in 2023, around triple the total returns of the S&P 500 index. After a rough 2022, the stock made a huge turnaround as the e-commerce and cloud-computing giant finally saw some margin expansion and generated positive free cash flow again. It now sits at a market capitalization of over $1.5 trillion and is the fifth-most valuable company in the world.

With the stock up by so much, you might be under the impression you've missed the boat with Amazon stock. But just because a stock is up a lot doesn't mean you should avoid buying shares. Is Amazon set to beat the market yet again in 2024? Let's take a closer look to find out.

Continued margin improvement in e-commerce

Amazon has its fingers in a lot of pies. For example, it is currently investing heavily in healthcare and satellite internet services. But today, two segments drive this entire operation: e-commerce and cloud computing.

People have been skeptical about Amazon's e-commerce segment for years, claiming it will always struggle to generate a profit due to the sky-high costs associated with building a vertically integrated online shopping platform. This is especially true in the United States due to how spread out the population is geographically.

In late 2023, the company showed that these concerns are misguided. Due to the scale of its logistics footprint, booming advertising revenue, and more sales coming in from high-margin, third-party seller fees, Amazon's e-commerce segment is showing margin expansion. At least, it is in North America.

Last quarter, Amazon's North American segment had a 4.9% operating margin, up from negative 0.5% a year prior. With $340 billion in trailing-12-month revenue, a 5% operating margin equals $17 billion in operating income from this segment.

There's no reason to think this margin expansion won't continue. Amazon is still working through the huge capacity build-out that occurred during the COVID-19 pandemic and is seeing strong growth from advertising and third-party sales. With how high-margin these revenue streams are, it would be unsurprising to see Amazon's North American segment reach 10% operating margins at some point in 2024. That is $34 billion in earnings just from its North American retail operations.

Online shopping is set to continue gaining market share this decade and still makes up just 20% of overall retail sales. That means Amazon -- after all these years -- still has an industry tailwind at its back that should keep revenue compounding to higher levels over the next few years.

The growth of the cloud is still underrated

Amazon's most profitable segment is Amazon Web Services (AWS), its cloud computing division. Closing in on $100 billion of revenue with greater than 25% operating margins, this would be one of the world's most profitable businesses on its own.

Investors have been worried about slowing revenue growth at AWS, with sales up just 12% year over year last quarter. This feels short-sighted. AWS has felt the slowdown in venture capital funding and the software sector, as it is the computing backbone for many of these companies. It even explicitly started working with struggling clients to reduce their cloud computing bills, which slowed revenue growth.

Despite these headwinds, the segment is still growing revenue by 12% year over year. With cloud computing continuing to take market share from legacy computing solutions, the artificial intelligence (AI) boom, and the general growth of computing needs worldwide, AWS looks poised to grow revenue at a double-digit rate for the foreseeable future.

If AWS reaches $200 billion in revenue within five to six years, which seems doable as long as it can maintain market share, the segment could be doing over $50 billion in operating income for Amazon. That would be quite the profit machine.

AMZN PE Ratio Chart

AMZN PE Ratio data by YCharts. PE Ratio = price-to-earnings ratio.

But is the stock cheap?

The short answer? Yes. At least it is if you have a multiyear time horizon. Amazon trades at a market cap of $1.56 trillion and has a trailing price-to-earnings (P/E) ratio of 78, which makes the stock seem expensive in a vacuum. However, anyone just looking at the trailing P/E is failing to appreciate the rapid margin expansion within e-commerce and the massive growth potential remaining in the cloud computing division.

If we assume its North American retail division can hit 10% margins and $34 billion in earnings, and cloud computing will hit $25 billion in earnings shortly, that is $59 billion in combined earnings for Amazon. It also assigns zero value for its international retail operations and any of its moonshot bets, such as Kuiper satellite internet or healthcare. Dividing $1.56 trillion by $59 billion equals a P/E of 26, almost exactly the market average and much more palatable than a P/E of 78.

Remember that Amazon still has plenty of runway left to grow its top line and that this also puts zero value on any other subsidiaries besides AWS and North American retail. With this in mind, I think Amazon stock remains cheap and has a good chance of beating the market again in 2024. Don't sleep on this technology giant.