It's been a rough year so far for the stock market, and the past few weeks have been especially shaky.

After a brief bear market rally, the S&P 500 has fallen more than 7% since mid-August. The tech-heavy Nasdaq is also down more than 10% in that time frame, and many investors are concerned that this could be the beginning of a market crash.

There is a chance that stock prices could continue falling, and we may be headed toward a more significant downturn. But the good news is that it doesn't necessarily matter whether the market crashes. Here's why.

Person looking at charts on a computer.

Image source: Getty Images.

What history shows about market crashes

Nobody can predict exactly how the market will perform in the short term. Stock prices can be erratic, and even the experts can't say for certain what will happen in the coming weeks or months.

What we do know, though, is that over the long term, the market is incredibly consistent. And if history shows us anything, it's that there is good reason to be optimistic about the market's future.

Since 1980 alone, the S&P 500 has fallen by at least 10% on 20 separate occasions. Some of those crashes were severe, too. During the Great Recession, for instance, the S&P 500 lost nearly 57% of its value at its lowest point. In the dot-com bubble burst in the early 2000s, it fell by close to 50%.

However, the S&P 500 has also earned returns of nearly 3,600% in that same time frame. Despite all this volatility, the stock market has an incredible track record of recovering from even the worst crashes.

^SPX Chart

^SPX data by YCharts

This isn't to say that market crashes aren't nerve-wracking. Nobody wants to see their portfolio plummet in value, and these downturns can be difficult to stomach even for the most experienced investors.

Over time, though, the market is much safer than it may seem. Even if a crash is looming, by sticking it out and staying invested, you can take advantage of those long-term gains.

The secret to making money in the stock market

While it can be intimidating, one of the best ways to maximize your earnings is to continue investing during downturns.

Again, stock market crashes aren't easy. But they are one of the best opportunities to buy. Stock prices are significantly lower during a downturn, which means you can load up on solid investments at a fraction of the cost.

Then, when the market inevitably rebounds, you'll reap the rewards. Case in point: Between 2009 and 2010 during the recovery phase of the Great Recession, the S&P 500 saw returns of close to 70%. If you had invested during the lowest point of that downturn, you likely would have seen substantial gains in a relatively short time.

It's uncertain whether a market crash is looming, but the future isn't as grim as it may seem. By continuing to invest and keeping a long-term outlook, it's possible to make a lot of money in the stock market.