One million dollars. This amount seems like a lot, but it has lost a bit of its weight due to inflation. Still, it's a goal nearly every investor has. To achieve this goal through the stock market, investors can purchase index funds, individual stocks, or a combination of the two. Because index funds track indexes like the S&P 500 or Nasdaq-100, they are widely diversified and move in smaller increments. On the other hand, individual stocks have more significant potential but also more risk. Using a combination of these two methods can help investors meet their goal of becoming a millionaire by retirement.

If the right stocks are chosen, a $300 a month contribution split among three stocks can be the ticket to becoming a millionaire by retirement. Of course, $300 is entirely arbitrary, and investors can find the future value of constant cash flows with the following formula:

Future value of continuous cash flows formula.

Image source: Author. F is the future value of an investment, A is an equal cash flow, i is the interest rate, and N is the number of interest periods.

Using this formula, one can deduce that a $300 per month cash flow, 12% annual interest rate, and 30 years will yield more than $1 million compounded monthly.

I'm sure that's enough math for many readers, so let's move on to what stocks can make this projection happen.

Stock 1: An S&P 500 Index Fund

I know this is boring, but an S&P 500 index fund like SPY (SPY 1.19%) is a great portfolio foundation. It gives investors instant diversification in 500 of the largest companies in the U.S. and has returned 10.5% annually since its inception in 1957 through 2021.

Two people looking at paperwork.

Image source: Getty Images.

Because this return rate is lower than our required 12% return, the other two stocks will need to produce a higher average return -- about 12.6% per year. 12.6% over 30 years is an impressive run for a company; however, many companies have accomplished this.

Microsoft and Apple had a compounded annual growth rate of 16.8% and 20.3% over the past 30 years. Admittedly, these are pretty extreme examples, but even Home Depot would meet this criterion, as it has returned 13.4% annually over the past 30 years.

Individual stocks can meet this benchmark, so which ones can grow for 30 years?

Stock 2: Nvidia

The premier GPU (graphics processing unit) producer Nvidia (NVDA 3.65%) is one stock I believe can grow for 30 years. Even though Nvidia already has a $400 billion market cap, this company can easily maintain a 12% stock growth rate for 30 years.

Its bread and butter product, GPUs, are being used in many products like gaming computers, data centers, and self-driving cars. With every consumer and company pursuing better performance, Nvidia's products will always be in demand as long as they stay at the industry's top.

The business is growing rapidly, with earnings per share rising 103% YoY (year over year) on quarterly revenue growth of 53%. With the company developing more software applications like Nvidia AI, the omniverse (Nvidia's version of the metaverse), and Nvidia DRIVE (Nvidia's autonomous vehicle solution), its margins will continue to rise.

Autonomous vehicles driving on the highway.

Image source: Getty Images.

Nvidia may be a large company now, but its innovation and relevance in future technologies will make it a stock that can deliver massive shareholder returns over the next 30 years.

Stock 3: The Trade Desk

Advertising has been around since ancient times, so there's little chance it will fade away within the next 30 years. However, the medium in which it's delivered likely will. Linear TV has dominated since its invention, but with the rising of streaming, advertisers can now choose a targeted audience instead of the broad public.

The Trade Desk (TTD 4.15%) is one of the companies leading this charge, and it also has a strong presence in other forms of online advertising. In 2019, the IDC (International Data Corporation) projected around $750 billion in global advertising spending, and The Trade Desk believes it can capture a large portion of that. By using third-party, first-party, and proprietary in-house data, The Trade Desk believes its data management platform can target customers accurately while maintaining customer privacy.

The Trade Desk is already a successful company, with an adjusted Q1 EBITDA margin of 38% on revenue of $315 million (which grew 43% YoY). Its massive market opportunity and profitability will allow The Trade Desk to maintain its leadership status in a significant and growing digital advertising industry.

Along with an S&P 500 index fund, these two companies can make an investor a millionaire in 30 years with a mere $300 a month. However, investors cannot get spooked and sell during difficult market conditions like those we are experiencing now. As long as the company's thesis is still on track, investors need to be committed to the $300 per month in good times and bad. The key is consistency and patience, two traits that are easier said than done. However, if an investor can master these traits, the rewards will be fantastic.