If you're invested in stocks, you've probably endured quite a ride over the past couple of years. If you're already retired, you might well have been on the verge of panic as you watched your life savings dropping in value during 2008 and early 2009.

Falling markets are tough for any investor to endure. When you're just starting out, it's painful to watch any of your hard-earned savings disappear. But when you're depending on your savings to provide you with income for the rest of your life, you can't afford to take the same risks younger investors can. That makes any losses you suffer even harder to bear.

No matter how much you've managed to save, the universal fear among retirees is running out of money. But by anticipating the ups and downs in various markets, you can keep the odds in your favor.

Can you trust the 4% rule?
Those who've read the Fool's Rule Your Retirement newsletter service know about the 4% rule. In simple terms, based on past historical market returns, a portfolio of stocks and bonds has always been able to support annual withdrawals of 4% of the initial portfolio value for 30 years or more. So if you have $1 million when you retire, you could take withdrawals of $40,000 each year, adjusting upward for inflation every year, and expect to have money left 30 years later.

That makes plenty of sense during good times. With stocks returning roughly 9%-10% per year on average, a 4% withdrawal seems quite conservative when the market is rising.

But when stocks fall, it's hard to believe you can sustain withdrawals based on a nest egg whose value is dropping. If you're unlucky enough to retire at exactly the wrong time, it can take some fortitude to count on having history repeat itself.

The worst-case scenario?
Consider, for example, someone who retired at the top of the market in 2000. A Rule Your Retirement article from the newsletter's archives showed that depending on exactly what investments you made, following the 4% rule could have left you looking at big losses. When the S&P was down just about 50% from its March 2000 highs, a portfolio with 75% invested in an S&P 500 index fund and 25% in a short-term bond fund had lost around a third of its value even before taking withdrawals into account. Even after the rebound, those annual 4% withdrawals -- based on the original balance -- still represent a much larger percentage of your remaining assets.

That's not too surprising, given how most companies saw their stocks perform badly during the bear market. In 2008, Pfizer (NYSE: PFE) fell 17%, IBM (NYSE: IBM) 20%, and Procter & Gamble (NYSE: PG) 14% -- and those were good results compared to the overall market.

The 4% rule was designed with these sorts of historical drops in mind. After all, the market has gone through long stretches of so-so performance before -- only to see big rebounds like the one we saw last year. Even so, counting on history to repeat itself isn't necessarily reassuring after you've seen a big chunk of your net worth go up in smoke.

Spreading out the risk
There are things you can do, though, to avoid that worst-case scenario. A more diversified portfolio that the RYR article discussed included more than just the large-cap domestic stocks you'll find in the S&P 500 -- and it performed much better over the same time period with less risk. By including small-cap stocks such as Ceragon Networks (Nasdaq: CRNT) and Ebix (Nasdaq: EBIX), REITs such as Simon Property Group (NYSE: SPG), and international stocks such as China Green Agriculture (NYSE: CGA), retirees in 2000 have captured some of the relative outperformance in those assets.

Unfortunately, they've still been hit hard by the recent bear market, which hasn't provided many safe havens for investors. But over time, owning different types of stocks should help smooth out returns.

You shouldn't keep all of your eggs in one basket, especially during retirement. By building a diversified retirement portfolio that includes assets that will do well when others are performing poorly, you can avoid the anxiety that comes from down markets that come soon after you retire.

To get more details on structuring your portfolio to get maximum benefit from diversifying, sign up for a 30-day free trial of Rule Your Retirement. You'll get access to back issues, including the June 2007 newsletter that discussed withdrawal rates during tough markets. Try it out today, and start sleeping better at night.

Attention, Fools! Looking for a trustworthy financial planner? The Garrett Planning Network is offering a limited-time 10% discount for new Motley Fool clients. Just click this link, search your state, and look for the Motley Fool icon to identify participating advisors.