Finding a few great companies to hold onto for many years can seem overwhelming, but the good news is that there are plenty to choose from. I tend to gravitate toward the tech sector for investment ideas, and even in this sometimes tumultuous sector there are standout companies that have already proved their mettle.

Two that could be great stocks to hold until you retire are Apple (AAPL -0.35%) and Microsoft (MSFT 1.82%). Both of these tech giants have established businesses and impressive market share, and both are continuing to release products and services that are likely to be in demand for years to come. Let's take a closer look at each one.

A person looking at a tablet.

Image source: Getty Images.

1. Apple 

For years, naysayers have said the company lacks innovation and that its best days are behind it. And yet the company continues to slowly and steadily release iterations to its products and services that keep customers coming back year after year.

Consider the company's latest iPhone updates. Apple released its iPhone 15 lineup this month with the usual upgrades: better internal processors, improved cameras, and some software changes. Apple is typically the tortoise (and not the hare) when it comes to product changes, yet its approach continually pays off. 

Demand for Apple's iPhones is so strong in the U.S. that the company's smartphone market share has expanded from 40% in mid-2018 to 55% right now, according to Counterpoint Research.

The company has had similar success with its Apple Watch, the best-selling smartwatch worldwide, with 26% market share. Meanwhile, its closest competitor, Samsung, has just 9% of the market. 

Products aside, Apple's methodical approach to growth has also worked well for its services segment. In 2019, Apple's annual services revenue was $46.2 billion. Now, just four years later, Apple has reached $62.8 billion in services revenue in the first nine months of 2023. 

Apple has also consistently defied market expectations. While the S&P 500 has gained 54% over the past five years, Apple's stock is up a much more impressive 228%. Of course, there's no guarantee that Apple's stock will continue to outpace the market's gains -- but if you listened to people who were saying Apple can't keep growing, then you would have missed out on Apple's gains over the past few years. 

Apple is doing what it's always done: release great products that people continually want to buy, and then slowly improve those products. That formula has proven very successful for the company in years past, and I think it'll continue to serve the company well for years to come. 

2. Microsoft

Microsoft, another tech behemoth, also deserves a spot on this list -- not only because it's grown into a key cloud computing player over the past few years, but also because of the company's recent investments in artificial intelligence

Microsoft's cloud computing infrastructure Azure has grown into the second-largest cloud computing service (after Amazon's AWS) over the past years. Azure holds an impressive 26% share of the market, compared to 30% for Amazon, and easily outpaces its next-biggest competitor, Alphabet's Google, which has just 9%.

Azure has become an increasingly important service for Microsoft because the long-term opportunity is so big. According to Fortune Business Insights, the global cloud computing market is worth about $678 billion this year, and will reach an estimated $2.4 trillion by 2030. This cloud expansion will come from more companies needing robust cloud infrastructure and services as they focus on building their own AI services.

This is where Microsoft's growth in the coming years will likely come from. The tech giant has already invested an estimated $13 billion into ChatGPT creator OpenAI, giving it a reported 49% stake in the company. This results in Microsoft getting access to OpenAI technologies and a portion of its profits until Microsoft can recoup its investment. 

Microsoft is already integrating ChatGPT in many of its services, including its Edge browser, Microsoft 365 apps, and Azure cloud services. And Microsoft will continue to benefit as more companies also shift their focus to AI. Companies are ramping up their need for high-powered servers to deliver AI processing capabilities, and many of them will likely turn to Microsoft's Azure to help them get the job done. 

Microsoft proved several years ago that it could enter a new market -- cloud computing -- and quickly shift its focus to become a leading player. I think the company is doing the same thing in the AI space right now, positioning itself with its early AI investments to benefit from this market over the coming years.