The market for artificial intelligence (AI) technology is a massive growth opportunity. Spending on AI software and systems is expected to grow to over $1 trillion, according to some estimates. But it's important to invest in companies that are actually going to make money from AI. This is how investors will know they are investing in a long-term winner.

Nvidia (NVDA -4.69%) and Microsoft (MSFT -0.10%) are no-brainers. These top AI stocks delivered stellar returns to investors in recent years, and are already outperforming the market again in 2023 thanks to the growing demand for AI hardware and software. Here's why these two stocks are still great buys.

1. Nvidia

Nvidia has dominated the market for graphics processing units (GPUs) for many years. These chips power everything from video games to massive data centers. The company has regularly controlled around 75% or more of the GPU market for many years, and it is translating that lead to the AI market.

The opportunity for Nvidia's business is massive. Nearly all data centers are using central processing units (CPUs), which are not powerful enough to handle AI workloads. This is opening a wave of new orders for GPUs. Nvidia expects revenue to nearly double year over year in the fiscal second quarter.  

In fact, Nvidia CEO Jensen Huang sees this demand curve as the beginning of a 10-year transition to retool data centers with powerful GPU systems. Generative AI-powered chatbots have been the catalyst to kick off this investment cycle, but there's more coming.

For example, Apple is reportedly interested in creating a generative-AI text generator to compete with OpenAI's ChatGPT (which is backed by Microsoft) and Alphabet's Bard.

Competition will inevitably heat up -- Nvidia's top GPU competitor Advanced Micro Devices recently announced the MI300X chip, designed for AI workloads, which will start shipping later this year. But investors should expect Nvidia to hold its lead. Nvidia has a long history of maintaining a steady pace of innovation as the pioneer of graphics processing technology.

The stock trades at a high forward price-to-earnings ratio of 58. However, analysts are still raising their long-term earnings forecasts based on the accelerating demand for AI chips, so the stock might be cheaper than its valuation suggests. It's not a bargain, but Nvidia's growth opportunity is large enough that the stock can likely still outperform from here.

2. Microsoft

Microsoft has an inherent advantage in AI software because of the familiarity millions of users already have with Windows and Office.

AI is transforming how whole industries do business, and many businesses rely on Microsoft software. This positions Microsoft to become the face of AI for most consumers and businesses. 

Evercore ISI analysts estimated that Microsoft should see $100 billion in incremental revenue over the next four years from AI. That would match the same increase in Microsoft's revenue over the last five years. 

There will surely be healthy demand for the Microsoft 365 suite of apps, especially as AI-powered text features are integrated into Word. Microsoft recently announced Copilot that will bring large language models to Microsoft 365 apps. Microsoft has found that 70% of employees want to use AI as much as possible for work, so the company should see robust demand as it rolls out these new tools.

Investors should note that bringing new AI features to market is not cheap, but Microsoft is not planning to offer AI capabilities in its software for free. Microsoft said it will charge $30 per user, per month, to business customers for Microsoft 365 Copilot, which adds large language models to its software suite. The company is clearly preparing to monetize its technology to its fullest potential. 

Microsoft will also see more growth in enterprise cloud services, which offers AI services and solutions to companies looking to do more with their data. Cloud revenue is Microsoft's largest revenue generator, and grew 25% year over year last quarter on a constant-currency basis. 

The stock trades at a premium to the market average P/E, but it's worth it given the long runway of growth and recurring revenue that Microsoft generates from subscriptions.