When investors encounter tough days in the stock market, they need a game plan for how to respond, Jim Cramer told his Mad Money viewers Friday. That means knowing what type of selloff you're dealing with and how best to navigate it. Fortunately, history can be your guide in identifying those inevitable moments of weakness and keep you from panicking.

On Wall Street Friday, the Dow Jones Industrial Average fell 298 points, or 1.2%, to 24,686. At its low for the day, the index was down 539 points. The S&P slid 1.74%, and the Nasdaq dropped 2.06%.

Cramer told his viewers that the U.S. stock markets have only seen two truly horrendous selloffs since he began trading in 1979. Those were the Black Monday crash in October 1987 and the rolling crash of the financial crisis from 2007 through 2009. But while both of these declines saw huge losses, they were in fact very different.

Many investors don't remember Black Monday, where the Dow Jones Industrial Average lost 22% in a single day. Even fewer remember that the market lost 10% during the week prior, and continued its losses on the Tuesday after. While it wasn't known at the time, this crash was mechanical in nature, caused by a futures market that overwhelmed the ability to process the flood of transactions. In the confusion, buyers stepped aside and prices plunged.

The carnage wasn't stemmed until the Federal Reserve stepped in with promises of extra liquidity. But in the end, the economy was strong. There was nothing wrong with the underlying companies, the market just stopped working. That's why it only took 16 months to recover to their pre-crash levels.

Investors witnessed similar mechanical meltdowns in the so-called "flash crash" of 2010 and its twin in 2015. On May 6, 2010 at precisely 2:32 p.m. Eastern, the futures markets again overwhelmed the markets, only this time machines were doing most of the trading. The crash lasted for a total of 36 minutes, during which time the Dow plunged 1,000 points from near the 10,000 level.

In August of 2015, another flash crash occurred at the open, with the Dow again falling 1,000 points in the blink of an eye. In the confusion, traders couldn't tell which prices were real and which ones were pure fantasy. Only those with strong stomachs risked trading at the heart of the decline, but those traders were rewarded handsomely.

In all of these cases, Cramer said, the machinery of the markets was broken. Even the circuit breakers put in place after 1987 were not able to stem the declines and in fact, did very little to even slow them down. But for those investors who were able to recognize what was actually happening, these declines were a once- (well, twice-) in-a-lifetime gift.

Cramer and the AAP team are buying more Palo Alto Networks (PANW) . Find out what they're telling their investment club members and get in on the conversation with a free trial subscription to Action Alerts PLUS.

The Great Recession 

The Great Recession was a totally different animal. The market began falling in October 2007, but didn't bottom until March 2009, almost two years later. Afterwards, it took until March of 2013, four years later, for the markets to get back to even. Cramer said this kind of decline is the most dangerous, but fortunately, it's truly a once-in-a-lifetime event, only occurring every 80 years or so.

The Great Recession was caused by the Fed raising interest rates 17 times in lock step, trying to cool an already cooling economy. The recession could have been avoided had the Fed done their homework and actually talked to CEOs, as Cramer did at the time.

Cramer recalled talking to the CEOs of banks, all of whom told him that defaults on mortgages were on the rise in a fashion none of them had seen before. Cramer's famous "They know nothing" rant on CNBC stemmed from those conversations, as the Fed did nothing until the first banks began to collapse. The market fell 40% before finally finding its footing.

How can investors identify this type of devastating decline? Cramer said investors can ask whether the economy is on a solid footing. Is business declining? Is employment falling? Are interest rates still rising even as cracks are appearing? If big companies are unable to pay their bills, the problem could be a lot deeper than you think.

Today's Market

Today's market is not like 2007, however, Cramer said. Business is stronger, our banking system is stronger and there's still time for the Fed to take their foot off the brakes and wait for more data before proceeding.

So you've just spotted a mechanical breakdown in the market, what should you buy? Cramer said he's always been a fan of accidental high-yielders, companies whose dividend yield is spiking because their share prices are falling with the broader averages.

He said that these stocks are always among the first to rebound, as their dividends help protect them. He advised always buying in wide scales as the market declines. That way, if the rebound is swift, you'll still make a little money, but if it's a larger, multiday sell off, you'll make even more.

Cramer reminded viewers that when the Fed is cutting interest rates, almost every market dip is a buying opportunity. But when it's raising rates, things get tricky. Not every rate hike causes a crash, however, only ones that push rates high enough to break the economy.

During these times, it's important to remember that stocks aren't the only investment class out there. You can also invest in gold, bonds or real estate to stay diversified.

Over on Real Money, Cramer says the Fed is more in control than he's seen it since 2006-2007. Find out what that means and get more of his insights with a free trial subscription to Real Money.

It's Not Just the Fed 

The Fed isn't the only reason why the market declines, and Cramer ended the show with a list of the other common culprits.

The first sell-off culprit are margin calls. Too often, money managers borrow more money than they can afford and when their bets turn south, they are forced to sell positions to raise money. We saw this happen in early 2018 when traders were betting against market volatility by shorting the VIX. When volatility returned, these traders lost a fortune and the whole market suffered.

There are also international reasons for the market to sell off, including crises in Greece, Cyprus, Turkey and Mexico, among others. Cramer said in these cases, it's important to ask whether your portfolio will actually be impacted by these events. Usually, the answer is no.

Then there's the IPO market. Stocks play by the laws of supply and demand after all, so when tons of new IPOs are hitting the markets, money managers often have to sell something in order to buy them. Declines can also stem form multiple earnings shortfalls as well as, yes, political rhetoric coming from Washington.

Cramer said many of these declines happen over multiple days. The key is to watch if the selling ends by 2:45 p.m. Eastern. If so, it may be safe to buy. But if not, there will likely be more selling the following day and it will pay to be patient.

Search Jim Cramer's "Mad Money" trading recommendations using our exclusive "Mad Money" Stock Screener.

To watch replays of Cramer's video segments, visit the Mad Money page on CNBC.

To sign up for Jim Cramer's free Booyah! newsletter with all of his latest articles and videos please click here.

At the time of publication, Cramer's Action Alerts PLUS had a position in PANW.

More from Jim Cramer

Visa, Wynn Resorts, Target: 'Mad Money' Lightning Round

Visa, Wynn Resorts, Target: 'Mad Money' Lightning Round

Trade and Interest Rates: Cramer's 'Mad Money' Recap (Friday 11/16/18)

Trade and Interest Rates: Cramer's 'Mad Money' Recap (Friday 11/16/18)

Flashback Friday: Nvidia Is the Ultimate Chip and Dip

Flashback Friday: Nvidia Is the Ultimate Chip and Dip

Don't Let a Short-Term Headwind Cloud Your Focus, Jim Cramer Says

Don't Let a Short-Term Headwind Cloud Your Focus, Jim Cramer Says

Jim Cramer: Nvidia Is a Great Company and They Will Get It Right

Jim Cramer: Nvidia Is a Great Company and They Will Get It Right