The S&P 500 is at its all-time high as I'm writing this, and it might seem like a bad time to put your money in index funds that track the popular benchmark. One of the most popular index funds in the world is the Vanguard S&P 500 ETF (VOO 0.76%), as it tracks the long-term performance of the S&P with a bare minimum of expense.
Obviously, the Vanguard S&P 500 ETF isn't as attractive as it was a year or two ago when it was trading for a much lower price. But it also isn't necessarily a bad time to invest in it, if you measure your investment returns in decades. Here's why.

Image source: Getty Images.
Investing in the S&P 500 at all-time highs
Arguably, the worst possible time to have invested in the S&P 500 over the past decade was at the market's all-time high shortly before the COVID-19 pandemic hit and sent the stock market plunging. As the following chart shows, the Vanguard S&P 500 ETF reached an all-time high in February 2020 and proceeded to plunge by more than 30% in less than a month.
VOO Total Return Level data by YCharts
So the February high would have been a pretty bad time to buy shares of the index fund, right?
Not necessarily. If we zoom out, we can see that even if you had bought at the worst time before the COVID-19 crash, your investment would have more than doubled in just over five years.
VOO Total Return Price data by YCharts
Let's take it a step further and look at the worst possible time to have invested over the past 20 years -- the market's all-time high on Oct. 9, 2007, shortly before the financial crisis almost destroyed the U.S. economy and the S&P 500 lost more than half of its value.
In this case, of course it would have been scary to see more than half of your investment's value wiped out over the following year and a half. But if you simply held on through all of the turbulence, you would be sitting on a 470% total return in the nearly 18 years since.
To be clear, I'm not saying that we're about to see a market crash or anything like that. For all we know, the S&P 500 could hit a new all-time high tomorrow, and another next month, and so on. But the point is that regardless of what happens next, the long-term returns of the Vanguard S&P 500 index fund are likely to be quite strong, even if you buy at an all-time high.
Averaging could be the way to go
As a final thought, it's worth mentioning that just because it isn't a bad idea to invest in the Vanguard S&P 500 ETF right now doesn't mean you should invest all of your money at the same time. Using the concept of dollar-cost averaging can be a smart way to go, especially when the market is looking a little frothy.
In a nutshell, dollar-cost averaging means investing equal dollar amounts at set intervals. For example, instead of investing $5,000 now, you might invest $500 per month for the next 10 months, regardless of the ETF's share price.
Think of it this way. If you invest $500 in the Vanguard S&P 500 ETF today, and the market falls by 20%, your next $500 investment will buy 20% more shares. Over time, you'll buy fewer shares when the ETF is expensive, and more shares when it's cheaper, giving you a mathematically favorable average price.
The bottom line is that just because the S&P 500 is at an all-time high doesn't mean you should stay on the sidelines. Letting the mathematics of dollar-cost averaging and long-term compounding work for you can still produce an excellent result over time.