The past few years have been a wild ride in the stock market. The S&P 500 (^GSPC -0.22%) -- which is often used to gauge the overall stock market's performance -- declined over 30% at the beginning of the COVID-19 pandemic, went on a bull run that doubled its value from March 2020 to December 2021, and then snapped back to reality, declining just over 19% in 2022.

Many other major companies and indexes have followed the same trend in the past few years. For new investors, this wild ride may be hard to grasp, but for investors who've been around a while, it reinforces one point about the stock market: Bear markets are inevitable.

So knowing this, the one lesson investors should never forget is that bear markets are a chance for opportunity, not panic.

History tends to repeat itself

Here is a look at the stock market's three major indexes' -- the S&P 500, tech-heavy Nasdaq Composite, and blue chip-filled Dow Jones Industrial Average -- down years since 2000:

S&P 500

Year Yearly Return
2000 (10.14%)
2001 (13.04%)
2002 (23.37%)
2008 (38.49%)
2015 (0.73%)
2018 (6.24%)
2022 (19.44%)

Data source: S&P 500.

Nasdaq Composite

Year Yearly Return
2000 (39.29%)
2001 (21.05%)
2002 (31.53%)
2008 (40.54%)
2011 (1.80%)
2018 (3.88%)
2022 (33.10%)

Data source: Nasdaq Composite.

Dow Jones Industrial Average

Year Yearly Return
2000 (6.17%)
2001 (7.10%)
2002 (16.76%)
2005 (0.61%)
2008 (33.84%)
2015 (2.23%)
2018 (5.63%)
2022 (8.78%)

Data source: Dow Jones Industrial Average.

Investors love bull markets, but at some point, they must come to an end. This doesn't mean the market will go right into a bear market like this past year, but at some point, the party stops, and concerns about the future begin to take over.

In fact, I would argue that bear markets are a necessary evil. If we never experienced bear markets and stock prices only increased, there would essentially be no risk in investing. The less perceived risk, the more investors will pay for shares because they feel like they won't lose money regardless.

This sets off a chain reaction: Stock prices keep rising because investors are willing to pay more, price-to-earnings ratios keep rising, and potential long-term future returns fall as a result. It's not an ideal cycle.

Look for the beauty within the chaos

During bear markets, when stock prices are dropping across the board, many great companies begin trading at discounted prices through no fault of their own -- just as a by-product of broader stock market conditions. That overcorrection is an opportunity for investors to set themselves up for the long term.

If you liked a stock at one price, why not like it more when its price is down 20% and nothing has fundamentally changed with the business? One of Warren Buffett's most famous quotes sums up this situation perfectly: "Be fearful when others are greedy, and greedy when others are fearful."

Stock prices reflect investors' feelings and reactions to those feelings. Stock prices fall when more people are selling than buying, which is generally a sign of fear. Instead of falling suit and doing the same, it can be the time to get greedy.

Take investors in Alphabet (GOOGL 0.35%) (GOOG 0.37%) as an example. Alphabet's shares are the lowest they've been since January 2021. If you believe in the company long term and were investing during the bull market, there's no reason to let a bear market deter you from continuing.

Alphabet's price-to-earnings ratio -- which can tell you how "expensive" it is -- is 13% lower now than one year ago.

GOOGL Chart

DATA BY YCharts

If your favorite clothing brand were 13% cheaper than last year, you'd likely embrace it, not shy away from it. Treat investing the same way.

Panic-selling can be counterproductive

One thing you want to avoid during bear markets is panic-selling. It can be tempting to sell shares to lock in profits or stop further losses, but this could be counterproductive.

On one end, panic-selling can result in a tax bill if you're selling shares for a profit. Most people are in the 15% capital gains tax rate bracket, but higher earners could pay up to 20%.

Perhaps more important than the tax bill is that panic-selling could cause you to miss out on future gains from those shares. Let's take Berkshire Hathaway (BRK.A 0.64%) (BRK.B 0.54%), for example, which saw its value cut by roughly a quarter from February to May 2020. Had investors panicked during that time and sold shares, they would have missed out on the close to 80% gains since.

There's no guarantee that every stock that falls during a bear market will bounce back and provide similar returns. But if you're investing in great businesses, you should trust its ability to weather down periods and provide good long-term returns.