Enthusiasm about artificial intelligence (AI) has driven substantial gains in the stock market this year, and it certainly has investors' attention. The technology is still in the early stages of its development, but Wall Street's estimates about its long-term potential are staggering.

Goldman Sachs predicts AI could add $7 trillion to global economic output over the next decade, thanks to its ability to increase productivity. The bank has analyzed the prior productivity booms that were driven by electricity and information technology, and it says they have been preceded by massive investment cycles.

Based on its analysis, Goldman Sachs thinks businesses will spend $200 billion on hardware and software per year by 2025 to lay the groundwork for AI. That's more than double what they spent on AI in 2022! Many companies will be on the receiving end of that spending, but Nvidia (NVDA 1.27%) and Microsoft (MSFT 0.59%) might be the biggest winners. Here's why investors should buy shares in both of them. 

Nvidia's hardware is essential to AI development

Prior to the early 2000s, businesses stored their valuable data on  servers that they maintained on their own premises. But since the widespread adoption of cloud computing, massive shared data centers now host much of that information offsite at a fraction of the cost. Since AI models need data to learn, the modern data center is also where developers are now building, training, and deploying those models.

But training AI cost-effectively requires a new generation of semiconductor hardware, and Nvidia has amassed an estimated 90% market share in that space. In fact, there is clear proof in Nvidia's financial results that Goldman Sachs' predictions are coming true. In its fiscal 2024 second quarter, which ended July 30, the chipmaker generated $10.3 billion in data center revenue, a whopping 171% increase compared to the year-ago period.

That gain was driven almost entirely by demand for its graphics chips (GPUs) designed for AI workloads, like the popular H100. But despite Nvidia's powerful growth, it's still in the early innings of what could be a multiyear upgrade cycle for data center operators like Microsoft Azure and Amazon Web Services. Nvidia CEO Jensen Huang says there is $1 trillion worth of existing data center infrastructure that will need to be replaced to support accelerated computing and AI. 

Nvidia's dominance in the AI space will be very difficult to disrupt, despite the valiant efforts of competitors like Advanced Micro Devices, which will begin shipping its impressive MI300 AI data center chips later this year. That's because developers are already familiar with Nvidia's CUDA (Compute Unified Device Architecture) software, which is used to build AI applications on top of its GPU chips.

CUDA can accelerate AI training and deployment, but it can't be used with other companies' chip hardware. Therefore, if a company abandons Nvidia's GPUs, developers in its entire ecosystem would also have to abandon the software they've been using for years. As a result, beating Nvidia will require more than just building a better chip.

Nvidia stock has surged 204% in 2023 so far, giving the company a market cap of more than $1 trillion. It's quite expensively valued by most traditional metrics -- except when you look to the future. Wall Street expects Nvidia to deliver $16.71 in earnings per share in fiscal 2025, which gives it a forward price-to-earnings (P/E) ratio of 26.2.

Considering that the Nasdaq-100 technology index trades today at a trailing P/E ratio of 30.5 and a forward P/E of 27.3, buying Nvidia stock at its current price wouldn't be such a bad move as long as you can hold onto it for at least the next couple of years. Besides, for the reasons mentioned above, it's likely Nvidia will capture quite a large share of Goldman Sachs' projected corporate spending on AI by 2025.

Microsoft is betting big on cloud-based AI services for businesses

Microsoft is the world's second-largest provider of cloud infrastructure services, behind only Amazon. Its Azure platform delivers hundreds of products and solutions to business customers, from simple data storage to advanced AI tools -- and the latter is becoming a growing part of its offering. In fact, one Wall Street analyst at Bernstein believes Microsoft's focus on AI could help Azure to overtake Amazon in the cloud industry.

In 2019, Microsoft made a $1 billion investment in OpenAI, the developer of the ChatGPT online chatbot. Earlier this year, it invested another $10 billion in the start-up, which shocked the technology industry. Microsoft immediately began integrating OpenAI's technology into its product portfolio, including Azure, its 365 productivity suite, and its internet search engine, Bing. 

The company's new cloud segment, called Azure OpenAI Service, has been a raging success so far. Businesses can access OpenAI's latest GPT-4 technology through Azure to build their own AI applications and dramatically increase their productivity. In Microsoft's fiscal 2023 third quarter, which ended March 31, Azure OpenAI Service had 2,500 business customers, a tenfold increase from the three months prior. By June 30, the end of its fiscal 2023 fourth quarter, that number had grown to 11,000.

As I mentioned, Microsoft has also embedded OpenAI's technology into its 365 document suite (which includes such ubiquitous programs as Word, Excel, and PowerPoint). Those applications are now capable of generating content for the user, in addition to answering queries, which saves people a visit to a traditional search engine like Alphabet's Google. The company just released an enterprise version called Copilot designed specifically for use in a commercial environment. Unlike the consumer versions, Copilot won't use a business's sensitive data to further train its AI models, making it much safer in the workplace.

But Microsoft isn't betting all of its marbles on OpenAI. It also invested earlier this year in Builder.ai, another notable AI start-up. It helps entrepreneurs develop software with AI by using prompts, even if they have no programming experience. This could be a key addition to Azure in the future, because it would be a highly attractive tool for small businesses and start-ups.

In short, Microsoft is becoming a one-stop shop for businesses in need of AI products and services. It's building an incredible distribution network for some of the best AI technologies through Azure, which will help the company capture substantial amounts of business investment over the long term.

Azure generated over $55 billion in revenue during Microsoft's fiscal 2023, and if Goldman Sachs' estimates are correct, that number could grow significantly over the next few years.