NEW YORK (CNNMoney.com) -- Leave no nest egg unscathed. That seemed to be the mission statement of the market meltdown that began in 2008.

On March 9 of this year, stocks hit a bottom, with both the S&P and the Dow closing at 12-year lows.

The market has since had better days, but halfway through the year, the S&P was still down 37% from where it was 18 months earlier.

Yet, there is some good news. The balances of 401(k) investors fared much better, according to calculations made for CNNMoney.com by Jack VanDerhei, research director of the Employee Benefit Research Institute.

Among all 401(k) accounts, the average balance fell 8.75% in the 18 months that ended June 30.

EBRI, working with the Investment Company Institute, has the country's most extensive information on 401(k) performance and investor behavior -- a database covering more than 21 million participants.

The numbers offer some measure of hope for 401(k) participants looking to get back to where they were. They also provide snapshots of how different groups were affected. Factors playing the biggest role were a participant's age, tenure at a company and whether or not she started 2008 with a small balance or a large one.

For example, young workers with no more than 4 years' tenure at a company fared the best. That's primarily because they had low balances to begin with and the power of their contributions easily trumped the downward pressure of the equity returns in their portfolios. The average balance for this group was actually up 47% over the past 18 months.

Hardest hit were those 401(k) participants between the ages of 45 and 64 who had worked 20 years at a company. Their balances were down an average of 17.5%.

Balances of 401(k) plans tended to outperform stocks as a whole in part because most 401(k) participants were invested in a mix of stocks and bonds or stable value funds.

And some participants did grow more conservative in how they invested.

"Over the last 18 months, the allocation [of new contributions] to equities fell 12.7%" at large companies, said Byron Beebe, a U.S. retirement market leader at Hewitt Associates, which keeps records for 500 retirement plans at the largest U.S. companies.

But the biggest factor bolstering 401(k) balances against the riptides of the market was the fact that participants kept contributing to their accounts much as they had before the meltdown last fall.

"Almost everyone has stayed the course," said Michael Doshier, vice president of workplace investing at Fidelity Investments, which tracks 17,500 defined contribution plans representing over 11 million participants.

Participants kept investing even though nearly 8% of companies have suspended their matching contributions to employees since last August, according to Fidelity. Hewitt estimates that between 6% and 7% of Fortune 500 companies were among them.

While the market meltdown challenged everyone's investing assumptions, it did reaffirm one principle -- that when it comes to having enough for retirement, how much you save counts even more than how your investments do.

Recovering what's been lost

Of course, knowing that your 401(k) balance hasn't fallen as far as the S&P doesn't erase the cold fact of the downturn: A big part of your nest egg is still in the red and it will take some time to recover what's been lost.

Just how long it takes will depend on two main factors:

how much you and your employer contribute to your account as a percent of your current balance;

how much of a return your portfolio will generate going forward.

In the two tables below, VanDerhei calculated roughly how long it would take for 401(k) participants to restore their balances to their Jan. 1, 2008, levels. One table assumes the participant's portfolio generates annual returns of 4% going forward; the other assumes an 8% return.

Say your 401(k) was worth $100,000 at the start of last year and has fallen 20%, leaving you with an $80,000 balance. If your portfolio is generating an 8% annual return and you and your employer combined contribute $8,000 to your account every year (that is, 10% of your current balance), VanDerhei estimates it will take you roughly 1 year and 4 months to restore your balance to $100,000.

If your portfolio only generates 4%, then it would take 1 year and 9 months.

If, however, you bumped up contributions to $12,000 (or 15% of your current balance), you could do it even sooner.

Once you've gotten back to even you might be tempted to ratchet back your contributions. But consider that even before the market meltdown, many workers -- both current 401(k) participants and those who don't participate -- weren't saving enough to begin with.

"A very large percentage were not saving anything close to what would be required to replace a significant percentage of their pre-retirement income by age 67," VanDerhei said. "The recent market crisis has only exacerbated their dilemma to the extent they were invested in equities."