Apple (AAPL -0.35%) stock rose 48% in 2023 and helped the S&P 500 index surge back to its 2021 highs in December. The iPhone maker has one of the most loyal customer bases -- and an incredibly strong brand because of it -- but the stock's climb last year is somewhat puzzling, considering the company's recent sales decline.

Why are investors bidding the shares higher? Is it safe to buy at these highs? Here's what you need to know.

iPhone returns to growth

Slowing sales growth wouldn't seem to support a stock hitting new highs and trading at a high valuation of 30 times next year's earnings estimates. However, iPhone sales, which make up almost half of Apple's business, hit a new record in the fiscal fourth quarter ending in September, returning to growth after sales declined for the full fiscal year.

Apple posted a 2.7% year-over-year increase in iPhone sales in fiscal Q4 despite being supply-constrained. The iPhone 15 has lifted the global smartphone market out of a recent sales slump and could be a catalyst for stronger top-line growth over the next year.

A chart showing iPhone making up nearly half of Apple's total sales.

Investors have banked on the growth in the services business to make the case to buy Apple stock. Services include app sales, subscriptions, and AppleCare warranty plans and the segment generates higher margins than the iPhone and other devices. While services sales were up 16% year over year in the fiscal fourth quarter ending in September, it wasn't enough to drive growth for the entire company, as total sales fell slightly in fiscal 2023.

Nonetheless, there is a reason Warren Buffett continues to make Apple Berkshire Hathaway's largest stock holding, a stake worth over $156 billion as of Sept. 30.

Apple's installed base of devices is over 2 billion and growing

Despite other smartphones that beat Apple with innovative features, Apple continues to grow its base of active devices and generate loads of cash to fund investments in artificial intelligence and other features to maintain high customer satisfaction scores.

Apple's iOS mobile operating system trails Alphabet's Android in market share. Android consistently commands over 80% share of the mobile market, according to Counterpoint Research. But Apple commanded half of the smartphone market's total sales. Most impressive is that Apple generates a high percentage of the smartphone market's operating profit.

Apple's brand helps the company price its products to earn higher profits than its competitors -- a key competitive advantage and why the stock deserves to trade at a high valuation. Apple generated $99 billion in free cash flow on $383 billion of total sales in fiscal 2023.

The Oracle of Omaha loves to make big bets on companies with strong brands, especially if those brands can produce high margins and keep growing over the long term. Apple possesses these qualities in spades.

Apple is a solid investment to round out a retirement portfolio

Apple stock isn't going to appreciate by 48% every year, but the blue chip stock can deliver solid returns over many years. "Our installed base of over 2 billion active devices continues to grow at a nice pace and establishes a solid foundation for the future expansion of the ecosystem," CFO Luca Maestri said on the fiscal Q4 earnings call.

Because Apple has such a low share of unit sales in the smartphone market, the company has ample opportunity to grow iPhone sales over the long term.