Many tech stocks have enjoyed a surge in 2023, as markets like artificial intelligence (AI), cloud computing, and virtual/augmented reality (VR/AR) have made investors bullish. As some of the biggest names in the sector, Apple (AAPL 0.50%) and Microsoft (MSFT -0.11%) shares have climbed 49% and 44%, respectively, since Jan. 1.

Apple's dominance in consumer tech has produced one of the most reliable growth stocks available. Meanwhile, Microsoft has proven itself as the king of software, with growing positions in AI. However, before adding both stocks to your list of holdings, it's a good idea to get the most out of your investment by understanding which is the better buy: Apple's or Microsoft's stock.

Apple: Consistent demand for the iPhone

It has been over 16 years since the first iPhone launched, yet the business continues to provide reliable revenue growth, reporting a 7% year-over-year increase in Apple's fiscal 2022. The massive success of the smartphone has led it to become the highest-earning part of the company's business, making up over 50% of its revenue. The immense popularity of the iPhone has allowed Apple to charge a premium for the device, which bolstered the business last year despite an economic downturn.

According to a recent study by Counterpoint, macroeconomic headwinds caused smartphone shipments to decline 17% in the first quarter of 2023. Consumer pullback led many industry leaders to experience declining or stagnating market share. However, consistent iPhone sales saw Apple grow its position in smartphones, with its market share rising from 49% to 53%.

Meanwhile, Samsung's market share stayed the same at 27%, and Motorola's share fell from 10% to 8%. The potency of Apple's smartphones allowed it to capitalize on market challenges, proving the resiliency of its business.

Apple's dominant role in smartphones is a powerful tool when touting its other products. The iPhone has often been described as a gateway to other Apple devices, proven by its leading position in many product categories. Alongside stock growth of roughly 300% in the last five years, the company's shares are an attractive option for investors.

Microsoft: Massive potential in AI

While Apple is leading the consumer tech market, Microsoft has similar dominance in software. The tech giant is home to powerful brands such as Windows, Office, Azure, Xbox, and LinkedIn, which have granted reliable revenue gains. Since 2019, Microsoft's annual revenue has climbed 58% year over year, with operating income rising 94%. 

The company's financial success has given it the resources to expand to other sectors, like AI. For instance, in 2019, Microsoft invested $1 billion in ChatGPT developer OpenAI. The partnership looks likely to be one of the company's smartest moves, allowing Microsoft to procure exclusive licenses on some of the start-up's most advanced AI models.

The Windows company has so far brought AI upgrades to several of its widely used services, such as its Office productivity suite, cloud service Azure, and search engine Bing. As a result, Microsoft has quickly become one of the biggest names in AI, a promising position considering the market is projected to expand at a compound annual growth rate of 37% through 2030.

Like Apple, Microsoft has a history of providing investors with consistent gains. Its stock has soared 225% since 2018. Paired with its prospects in AI, Microsoft's stock is another great option.

Is Apple or Microsoft the better buy?

Apple and Microsoft are pretty evenly matched as the world's first- and second-most valuable companies by market cap. However, the below chart uses two metrics to show how Apple's stock trades at a better value. The iPhone company's price-to-earnings ratio (P/E) and price-to-free cash flow (P/FCF) are quite a few points below the same figures for Microsoft, suggesting it is the cheaper option.

MSFT PE Ratio Chart

Data by YCharts

P/E is calculated by dividing a company's share price by its earnings per share. Meanwhile, P/FCF compares a company's share price to its free cash flow. With both metrics, the lower the figure, the better the value. These valuation metrics can be useful to determine whether a stock is trading at a bargain or is overvalued. An optimal P/E and P/FCF would customarily be under 20 to be considered undervalued. As a result, Apple stock may not be a bargain buy, but it is a chapter option when compared to Microsoft.

Furthermore, it is still early days for the AI market, with Microsoft likely to continue facing steep competition for years to come. Meanwhile, Apple has already proven its products are the preferred choice in its industry. The iPhone company's immense brand loyalty from consumers makes it seem like the more reliable choice.

So if you can only buy one, Apple is the better buy. However, keeping Microsoft on your radar for future investment is not a bad idea.