Investing in the stock market can be as simple as buying an index fund, adding a little bit of money every month, and watching your nest egg grow. Thanks to the mathematical magic of compound returns, the early gains build a stronger platform for future returns. The payoff can be jaw-dropping if you keep this strategy up for a couple of decades.

Read on to see how a modest monthly investment can grow to half a million dollars in 30 years. You don't even have to beat the market.

How to grow a small investment over a long time

Let's keep this thought experiment very, very simple.

The S&P 500 (^GSPC 0.75%) market index tracks the performance of the 500 largest American companies. The list is rebalanced twice a year, keeping the index reasonably up-to-date. Mutual funds and exchange-traded funds (ETFs) will buy and sell stocks right after each rebalancing announcement, keeping their investment portfolios equally fresh -- with no extra effort required by the funds' shareholders.

So I'll assume that the next 30 years on Wall Street will be about as productive, lucrative, and wealth-building as the last three decades. The S&P 500 saw a compound annual growth rate (CAGR) of 8.65% over that period, which started in 1994 and included several market panics along the way. The next 30-year period will undoubtedly be different in a million ways, but the long-term averages should be comparable enough.

The investment plan is also really simple. I'll start from scratch with a zero-dollar portfolio. Every month, this hypothetical investor puts $200 into a fund tracking the S&P 500 index. It's not nothing -- perhaps comparable to a family's cellphone bill or a nice night on the town -- but a pretty painless monthly amount for many people. Imagine the $200 contribution being an automated part of your monthly paycheck.

Using a handy investment calculator with this data, I can show you the expected returns after 10, 20, and 30 years. You might be surprised by the results.

Projected returns

Number of years

Total Investment

Ending Balance

Return on Investment

10

$24,000

$38,011

58.4%

20

$48,000

$128,278

167.2%

30

$72,000

$342,640

475.9%

Data source: Investment calculator from NerdWallet.com.

Those gains start out slow but catch fire later on. You know that old adage about putting one grain of rice on the first square of a chessboard and doubling the rice pile on every square? The first few grains may not impress anyone, but the last square would hold several years' worth of global rice production.

That's the power of exponential returns, and exactly what I'm talking about in the index fund investing example. Even a modest annual return like the 8.65% long-term market average adds up to incredible returns in the long run.

Wait -- didn't the headline say something about half a million dollars?

Alright, you caught me. You might have noticed a larger price target in the headline.

I just want to show you what a difference another couple of percentage points can make when you're multiplying the returns by several decades. And you know, it's really easy to achieve that boost, too.

All you have to do is set your brokerage account to reinvest this fund's dividends into buying more shares along the way. With this dividend reinvestment plan activated, the S&P 500's total returns landed at a 10.7% CAGR in the past. So, what happens if I add this dividend-powered accelerator to this exercise?

Well, the total returns for a full three-decade calculation are miles ahead of the plain price gains:

Number of years

Total Investment

Ending Balance

Return on Investment

10

$24,000

$42,766

78.2%

20

$48,000

$167,427

348.8%

30

$72,000

$530,806

737.2%

Data source: Investment calculator from NerdWallet.com.

And there's the half-million target I was talking about in the headline. You're still not beating the market here, but matching the gains of the most popular market index with a small (but game-changing) boost from reinvested dividends.

Why Vanguard's S&P 500 ETF stands out

There are only three ETFs that track the S&P 500 index directly. Any of them should deliver results very close to the S&P 500 averages in my calculations, but I do have a favorite among them.

The Vanguard S&P 500 ETF (VOO 0.86%) is a no-frills index tracker with microscopic annual fees. It's managed by the venerable Vanguard fund family.

In the words of master investor Warren Buffett, Vanguard founder Jack Bogle "has probably done more for the American investor than any man in the country." This patient index investing genius started a movement, and his firm should stay true to that investing philosophy for the foreseeable future.

That's why I tend to prefer Vanguard's funds over other fund managers. The SPDR S&P 500 ETF Trust (SPY 0.84%) and the iShares Core S&P 500 ETF (IVV 0.85%) aren't far behind, and a couple of index-tracking mutual funds are also worth considering. But this is the S&P 500 index fund I prefer for my own portfolio, and Warren Buffett likes it, too.

There you have it. This Vanguard ETF is all you need in order to build a game-changing nest egg over a couple of decades. Just stick to your monthly investing process and watch the compound returns add up over the years. It's a pretty magnificent experience.