Last year was particularly challenging for many investors. Recession fears sent the S&P 500 (^GSPC 1.20%) and the Nasdaq Composite (^IXIC 1.59%) tumbling into a bear market. Both indexes suffered their sharpest declines since the global financial crisis in 2008. But there's a silver lining to the downturn.

At some point, the economy will rebound and the next bull market will send the S&P 500 and the Nasdaq Composite soaring to new highs. That means the current situation is actually a buying opportunity, and purchasing index funds that track the S&P 500 and the Nasdaq Composite is a perfect way to capitalize.

Index funds offer the benefit of diversification across hundreds or thousands of different stocks and require far less research than individual stocks. Better yet, the S&P 500 and the Nasdaq Composite have produced double-digit returns on an annualized basis over the long term, so patient investors who regularly add money to relevant index funds could build a multimillion-dollar portfolio over three or four decades.

Here are the important details.

An index fund that tracks the S&P 500

The Vanguard S&P 500 ETF (VOO 1.26%) tracks the performance of the S&P 500, a broadly diversified market index comprised of 500 of the largest U.S. companies. The Vanguard ETF represents a blend of value stocks and growth stocks that span all 11 market sectors, though the following top-three sectors account for about half of its weight:

  • Information technology: 25.8%
  • Healthcare: 15.8%
  • Financials: 11.6%

The S&P 500 is currently 16% off its high, but the index has still produced a total return of 224% over the last decade, which is equivalent to 12.4% on an annualized basis. At that pace, $150 invested on a weekly basis would be worth $1.8 million after three decades and $6.3 million after four decades.

As a caveat, the annualized total return of the S&P 500 has been closer to 10% over longer periods of time. But at that pace, $150 invested weekly in the Vanguard ETF would still be worth $1 million after three decades and $3.1 million after four decades.

An index fund that tracks the Nasdaq Composite

The Fidelity Nasdaq Composite ETF (ONEQ 1.58%) tracks the performance of the Nasdaq Composite, an index comprised of more than 3,600 companies, most of which are based in the U.S. The Fidelity ETF is heavily skewed toward growth stocks. While its constituents span all 11 market sectors, the top three sectors account for more than 70% of its weight:

  • Information technology: 44.2%
  • Communications services: 13.6%
  • Consumer discretionary: 13.2%

The Nasdaq Composite is currently 31% off its high, but the index has still produced a total return of 290% over the past decade, which is equivalent to 14.5% on an annualized basis. At that pace, $150 invested weekly would be worth $2.8 million in three decades and $11.7 million in four decades.

As a caveat, the odds of achieving an annualized return of 14.5% over three or four decades are slim. But the Nasdaq Composite has outperformed the S&P 500 over the long term, so investors can reasonably assume an annualized return of 10.5%. At that pace, $150 invested weekly in the Fidelity ETF would be worth $1.2 million in three decades and $3.6 million in four decades.

Which index fund is better?

There are pros and cons to both index funds. Both bear below-average expense ratios, but the Vanguard S&P 500 ETF is the cheaper option. Its expense ratio of 0.03% means investors will pay just $3 per year on a $10,000 portfolio. Meanwhile, the Fidelity Nasdaq Composite ETF has an expense ratio of 0.21%, so investors will pay $21 per year on a $10,000 portfolio.

Additionally, while the Vanguard ETF includes fewer companies than the Fidelity ETF, it's still the more diversified option because its constituents are more evenly weighted across the 11 market sectors. That makes the Vanguard ETF less risky than the Fidelity ETF. However, the technology-heavy nature of the Fidelity ETF is the reason it has outperformed the Vanguard ETF over the long term.

With that in mind, the Vanguard ETF is a great option for almost any investor looking for exposure to the stock market. The Fidelity ETF is a good option for growth-focused investors who are comfortable with more volatility and risk.

That said, patient investors can buy either index fund with confidence because both indexes (i.e., the S&P 500 and the Nasdaq Composite) have recovered from every past downturn. That means both index funds will almost certainly produce a positive return, given a long-enough holding period.