The stock market could help you retire as a millionaire if you pick the right companies and hold them in your portfolio for a long time, as doing so will help you gain from the power of compounding and evolving trends in various industries.

For instance, a $50,000 investment in Amazon a decade ago is worth about $500,000 now thanks to the stock's nearly 900% gains over the past decade, and that's after accounting for the steep drop in the e-commerce giant's stock price in recent months. Amazon, however, is not the only company that has generated solid returns for investors over the past decade.

Nvidia (NVDA -3.87%), Microsoft (MSFT -0.66%), and Tesla (TSLA -1.06%) have also generated massive returns in the past 10 years, and it won't be surprising to see them maintain their trajectory in the coming decade. Let's see why investors can put $50,000 in these companies and retire as millionaires after a decade.

A person raises their hands amid falling paper money.

Image source: Getty Images.

1. Nvidia

A $50,000 investment in shares of Nvidia a decade ago is now worth more than $3 million if the dividends paid out by the company were reinvested. It is worth noting that Nvidia has delivered such massive gains despite periods of volatility that have sent the stock plunging, which is why it may be a good idea to buy it right now given the relatively discounted valuation.

Nvidia stock is now trading at 43 times earnings following its 43% pullback in 2022. The stock has a five-year average earnings multiple of 58, which means investors looking to buy a potential long-term winner are getting a good point of entry. More importantly, Nvidia is in a solid position to replicate its terrific stock market performance over the next decade due to a plethora of catalysts that extend beyond its traditional video gaming business, which has been the cornerstone of its rapid growth over the years.

Data centers, for instance, have turned into a happy hunting ground for Nvidia. The growing need for graphics cards to tackle intensive workloads related to artificial intelligence and machine learning, as well as emerging tech trends such as the metaverse have given Nvidia's data center business a boost.

In fiscal 2022, Nvidia generated $10.6 billion in revenue from the data center business, an increase of 58% over the prior year. The segment accounted for almost 40% of Nvidia's sales last fiscal year, and the company is just scratching the surface of a massive opportunity in this business. According to a third-party report, the global market for data center accelerators such as graphics cards and processors could grow at an annual pace of 32.5% through 2031 and generate $179 billion in revenue.

Nvidia is currently one of the leading players in the data center GPU market with a share of over 80%. Add other catalysts and it is easy to see why analysts are upbeat about Nvidia's long-term growth. It is expected to clock 25% annual earnings growth for the next five years, which could translate into terrific long-term gains on the stock market as well.

2. Microsoft

Microsoft is another stock that has delivered solid returns over the past decade, turning a $50,000 investment into nearly $550,000 including dividend reinvestments. The tech giant has come a long way from selling just computer operating systems and is now a major player in several fast-growing areas such as video gaming software and hardware, cloud computing, and emerging tech trends such as the metaverse.

These tailwinds have been fueling impressive growth at Microsoft, with the company's fiscal 2022 third-quarter revenue (for the three months ended March 31) rising 21% year over year in constant currency terms to $49.4 billion. A closer look at the key growth hotspots indicates that Microsoft is in a nice position to keep growing at a nice pace for a long time to come and replicate its stunning stock market performance over the next decade.

The cloud business, for instance, is turning out to be a key growth driver for the company. Microsoft reported 29% year-over-year growth in its cloud business last quarter to $19.1 billion, with the segment producing 39% of its top line. The cloud business still has a lot of room for growth due to a couple of simple reasons.

First, the global cloud services market is expected to exceed $1.6 trillion in revenue by 2030, compared to $325 billion in 2019, translating into a compound annual growth rate of nearly 16%. Microsoft has steadily increased its influence over this market, with its market share reaching 22% at the end of 2021 as compared to less than 14% in 2017.

If Microsoft continues to gain more share in the cloud computing market and hits gold in other areas such as video gaming and the metaverse, it could well be on its way to clocking impressive long-term growth and boosting investors' portfolios significantly.

3. Tesla

Tesla has been a big stock market winner over the past decade, turning a $50,000 investment into roughly $6 million. However, Tesla's best years still lie ahead thanks to the growing adoption of electric vehicles (EVs) across the globe.

In the U.S., for instance, electric vehicle sales had nearly doubled to 608,000 units in 2021 as compared to 308,000 units in 2020. Globally, an estimated 6.75 million EVs were shipped in 2021, an increase of 108% over 2020. It is estimated that the global EV market could clock 29% annual growth through 2030 and hit annual sales of 31.1 million units. EV sales could continue growing at a nice pace beyond 2030 as well as they will account for a 32% share of the overall vehicle market by then.

Tesla is already capitalizing on this opportunity, with its revenue rising significantly over the past decade.

TSLA Revenue (TTM) Chart

TSLA Revenue (TTM) data by YCharts

The company posted $18.8 billion in revenue for the first quarter of 2022, an increase of 81% over the prior-year period. It is also worth noting that its margins are improving at a nice pace. Tesla's adjusted earnings before interest, taxes, depreciation and amortization (EBITDA) margin increased to 26.8% at the end of the first quarter as compared to 17.7% in the prior-year period.

This eye-popping growth was a result of a ramp-up in vehicle production and deliveries. Tesla delivered just over 310,000 vehicles last quarter, a jump of 68% over the prior year. The company's production was up 69% year over year to 305,407 units during the quarter. Tesla CEO Elon Musk aims to achieve an annual production capacity of 20 million vehicles by 2030.

For comparison, the company has produced just over 1 million vehicles in the past four quarters, indicating that it is aiming to substantially increase its capacity to capitalize on the end-market opportunity. Analysts expect Tesla's earnings to increase at an annual pace of nearly 40% for the next five years -- a pace that it could sustain beyond that, as the discussion above indicates -- and lead to a healthy upside in the stock market.