The scary thing about getting laid off is that it can happen out of the blue. And it doesn't matter whether you're new to your job or a seasoned employee. If your company decides it's time to make cuts, your job could end up on the chopping block, no matter how good at it you are.

Getting laid off can be a huge blow at any age. But it can especially hurt in your 50s.

At that age, you may not be so eager to start over at a new company. And also, you might struggle to get hired due to age discrimination -- a practice that's definitely illegal, but also very hard to prove.

A person with a serious expression at a laptop.

Image source: Getty Images.

If you're laid off at age 55, there may be one silver lining. Technically, you may be eligible to cash out your 401(k) plan balance without incurring a penalty.

It's a move that might seem tempting, especially if you're looking at going without a paycheck for a period of time. But before you cash out your 401(k), consider the financial drawbacks involved.

How to get your 401(k) funds penalty-free at 55

The IRS offers some pretty nice tax breaks for people who save in a 401(k). So, in exchange, it wants savers to keep their money in their accounts until retirement arrives.

Normally, if you take a 401(k) withdrawal or cash out your plan prior to age 59 1/2, you'll incur a 10% early withdrawal penalty. For a $400,000 balance, you're looking at losing $40,000 in penalty form. Ouch.

However, there's an exception for 401(k) savers who are at least 55 years old. If you leave your job in the calendar year in which you'll turn 55 or later, you're allowed to cash out your 401(k) penalty-free.

To be clear, though, this option only applies to the 401(k) offered by the employer you're separating from at 55 or later. If you worked for a different employer between the ages of 22 and 30, and you have funds in their 401(k), you can't cash out that account penalty-free at 55.

You may be tempted to take the money in your 401(k) and run if you're laid off at 55. That could allow you to bide your time in finding another job.

But just because you can take that money penalty-free doesn't mean it's a good idea. As it is, retiring in your mid-60s could mean needing your 401(k) to last 20 years or more. If you start tapping your 401(k) in your mid-50s, you could run the risk of depleting your savings in your lifetime.

Also, once you start taking money out of your 401(k), you lose the opportunity to keep that money invested in a tax-advantaged manner. That, too, could lead to a serious retirement income shortfall.

Don't be so quick to cash out your 401(k)

It's one thing to lose your job at age 55 and take a small withdrawal from your 401(k) to tide yourself over until you're working again. But it's another thing to cash out your savings completely.

The latter is a decision that could really come back to haunt you. So it's best to leave your 401(k) funds largely intact in that situation.

That doesn't mean you should leave your money in a former employer's plan, though. A good bet in that scenario is to open an IRA and roll your 401(k) into it.

As far as finding a new job in your mid-50s goes, that might be a challenge. But one thing you can always look to do is venture out on your own. If you have worked for an accounting firm for the past 30 years, consider starting your own business. If you worked in marketing, become an independent consultant.

You may find that working for yourself is a more desirable arrangement when you're in the latter stage of your career. That way, you don't have to worry about your boss deciding that your job is no longer needed, since your boss will be you.