Market crashes inevitably happen from time to time. Since the current bull market has already lasted eight years, and the S&P 500 trades at a multiyear high of 24 times earnings, investors should be well-prepared for a market crash. Here are 10 basic things you must do to ensure your portfolio (and peace of mind) survives a major downturn.

1. Make sure you have enough cash on hand. The amount of cash defined as "enough" varies, but you need enough cash to cover living expenses and emergency costs through a multiyear bear market without selling your stocks.

Four pink piggy banks.

Image source: Getty Images.

If you cash out during a bear market, you can lock in losses or prematurely sell winners with long-term growth potential. But if you have enough cash, you can add more shares to lower your average price -- which could pay off when the market recovers.

2. Check if your portfolio is properly diversified. There's no "right" number of stocks for proper diversification, but investors should generally own a manageable number of stocks across different sectors and global regions.

If you own too many similar stocks, consider selling some of them to buy stocks in other sectors. You should also lock up a smaller percentage of your savings in bonds for reliable interest payments.

3. Make sure you own dividend stocks. I'm a big fan of stable dividend aristocrats like AT&T (NYSE:T), which provide reliable income even as their stock price fluctuates. AT&T has notably raised its dividend annually for over three decades -- through the crashes of 1987, 2000-2001, and 2008-2009.

By signing up for a DRIP (dividend reinvestment plan), your dividends can be automatically reinvested in the stock, accumulating more shares when the stock is cheaper and fewer shares when the stock is pricier. This keeps you automatically focused on long-term growth instead of short-term gains.

4. Use precious metals to hedge against a bear market. When the market turns sour, investors usually flock to precious metals like gold and silver. Therefore, it's wise to keep a small percentage of your portfolio in precious metals to hedge against a potential downturn.

If you compare the performance of the SPDR Gold Trust ETF (NYSEMKT:GLD) against the S&P 500 during the market meltdown of 2008 and 2009, you'll see what I mean:

GLD Chart

Source: YCharts

5. Know if your stocks are trading at discounts or premiums to the market or industry. You should always be aware of the current P/E ratios of the major indices as well as the industry averages for your stocks.

If you own stocks that are trading at steep premiums to the market or industry, it might be wise to take profits. You should also sell speculative plays which haven't turned a profit yet -- because in a down market, the lack of profits means that there's no fundamental floor for the stock.

6. Remember why you bought each stock. Warren Buffett reportedly never buys a stock unless he can write down his reasons for doing so. If you did the same, you could revisit your reasons for buying each stock in your portfolio.

If your original reasons no longer apply, it might be time to sell. But if the long-term story remains intact, it's smarter to hold on, possibly add more shares, and ride out the volatility.

7. Hold on to your big winners. It might be tempting to sell a stock that has doubled or tripled over the past few years, but that's usually the wrong move for long-term investors. Simply take a look at what you would have left on the table if you sold Amazon (NASDAQ:AMZN) during the previous two bear markets:

AMZN Chart

Source: YCharts

8. Remember your investment horizon. Investors in their 30s can easily afford to ride out decades of peaks and troughs, but investors in their 70s could lose their retirement savings to a multi-year bear market.

Therefore, older investors should make sure that they're not too heavily exposed to pricier or speculative stocks, and ensure that they have the proper percentage of stocks and bonds (generally 100 minus your age in stocks, and the rest in bonds).

9. Keep an eye on the market's valuations. If the market crashes, keep a close eye on the S&P 500's P/E ratio. The 20-year average is currently at 17, so we can reasonably assume that buyers will reappear when the S&P 500 cools back down to those levels again. Investors shouldn't try to time the market based on that ratio, but it's a good indicator of when a bear market will finally end.

10. Stay invested and don't sell with the herd. Lastly, the most important thing is for investors to stay in the market, regardless of how hard the bear bites. The following 50-year chart of the S&P 500 shows why it always pays to stay invested, regardless of how steep the troughs might look.

^SPX Chart

Source: YCharts

Leo Sun owns shares of Amazon and AT&T.; The Motley Fool owns shares of and recommends Amazon. The Motley Fool has a disclosure policy.