The stock market in 2023 can be summed up into three words: the "Magnificent Seven." A moniker for the seven biggest technology-focused companies that are capitalizing on multiple megatrends, the Magnificent Seven companies have been the primary fuel driving the S&P 500 up over 20% this year.

One of these stocks is Amazon (AMZN -1.44%), a leader in e-commerce and cloud computing. Shares have rocketed 75% higher this year after the company showed a major profit inflection compared to 2022.

Is Amazon set to beat the market yet again in 2024? Or has this stock run out of juice? 

AMZN Chart

Data by YCharts.

Retail and media margin expansion will continue

The biggest difference for Amazon in 2023 compared to 2022 was the profitability of its North American retail segment, which encompasses its e-commerce division, physical retail, and all the media services that go along with Amazon Prime.

In 2022, the segment had an operating margin of -0.9% due to rising logistics costs, overbuilding during the pandemic, and wage inflation. In 2023, with inflation getting under control and the economy normalizing from the COVID-19 pandemic, this headwind has abated. Over the last 12 months, Amazon's North American division generated a 2.4% operating margin and has climbed every quarter in 2023. Last quarter, it had a 4.9% operating margin.

If we dig even deeper into the details, it looks like there is room for Amazon's North American division to see continued margin expansion in 2024. High-margin advertising and subscription services are growing quickly and now make up a larger portion of the business compared to before the pandemic. For reference, in 2019 North America had a 4.1% operating margin.

Add in increasing operating leverage at its massive scale, and I think it's plausible for Amazon's North American division to hit 10% profit margins by this time next year. On its trailing $340 billion in revenue, that equates to $34 billion in earnings. As revenue climbs higher in 2024 and beyond, this earnings inflection should only continue.

The next leg of cloud computing growth

Retail is finally generating some profits, but the real high-margin business at Amazon is Amazon Web Services (AWS). The cloud computing division is closing in on $100 billion in annual revenue and sports healthy operating margins above 25%. As the leader in this fast-growing market, AWS has plenty of years left to grow sales at a double-digit rate. Over the last 12 months, revenue is up 15% year over year to $88 billion.

Even more good news showed up at its doorstep late last year with the explosion of artificial intelligence (AI) tools such as OpenAI's ChatGPT. While Microsoft is a primary financial backer for ChatGPT, there is plenty of AI spending, and AWS should be able to capture a decent share of the pie.

These new AI tools require massive amounts of computing, and the most efficient way to get this computing power is through cloud computing giants like AWS. For example, the company just signed a $4 billion investment with AI upstart Anthropic, most of which will go to spending at AWS.

At $100 billion in revenue and 25% profit margins, that equates to $25 billion in earnings that -- like the North American retail segment -- are poised to climb higher over the next few years and beyond.

But is the stock cheap?

Even if we assign zero value to its international operations (which have consistently lost money), Amazon stock does not look expensive. Adding up these profit estimates, the company should be generating $59 billion in earnings before taxes within a year or two. At a market cap of $1.5 trillion, the stock has a forward price-to-earnings ratio (P/E) of 25, or right around the market average, based on these estimates.

For a business that still has a long runway to grow this decade, a market average P/E suggests a bargain. As such, I think shares of Amazon can beat the market again in 2024.

More importantly, it looks like a great business to own for the long term, which is where most investors should have their attention focused. Hold on to shares of Amazon for the next decade and watch your portfolio grow in value.