Many of us will find ourselves unemployed at some point in our lives. We might be lucky and land a new job quickly, or the process could take a while. In early 2015, for example, unemployed workers had been out of a job for an average of 32 weeks, according to the U.S. Bureau of Labor Statistics.

Unemployment can be difficult both psychologically and financially. But there are ways to make it less of a strain, especially by planning ahead.

Before it happens

Even if your job seems totally secure at the moment, it’s smart to have a contingency plan just in case. Never stop networking so that if you do lose your job, the next one will be easier to come by. Update your resume and keep it at the ready.

You can prepare financially, too, for being laid off one day. Start by building an emergency fund. If you don’t already have some cash set aside, the time to start saving is before unemployment, or any other emergency, comes along. Here are tips on creating a rainy-day fund.

Related: Protecting Your Job When You're 50-Plus

If you own a home, consider applying for a home equity line of credit (HELOC). It will allow you to borrow against your equity if you ever need to. No matter how much equity you’ve built up, a HELOC can be difficult or impossible to obtain if you can’t prove you have income to repay it, so the time to apply is while you’re still working.

HELOCs generally have much lower interest rates than credit cards, notes Jane Rose, a CPA and vice president emerita of RTD Financial Advisors in Philadelphia, so they can be handy in a crunch. But they also carry their own risks, such as a chance of losing your home if you’re unable to repay.

When it happens

Losing a job can come as a shock. You may need some time to regroup, but the sooner you can attend to some basic money matters, the better.

Calculate your new income. If your salary is suddenly shut off, consider what other sources of income you might have available. If you have a working spouse, for example, could your household make do on just one income for a while? Are you able to take on some part-time work while you’re job hunting? Will you be getting severance pay?

You may also be eligible for unemployment benefits for a period of time, currently up to 26 weeks in most states. You can find out how to apply on your state’s unemployment insurance website. Because there may be a lag between applying and receiving your first payment, try to get your application in as early as possible.

Compare it to your expenses. Many of us have surprisingly little idea of where all our money goes each month. We know that it goes — we just aren’t sure where. One way to get a close estimate is to consult your bank and credit card statements for the past year and compile a list of expenses. Include any cash you withdrew for everyday miscellaneous expenses.

Related: 7 Costly Money Mistakes and How to Avoid Them

If you’re fortunate, your new income will be enough to cover your typical money needs. More likely, it will fall short, and you’ll have to draw on your emergency fund or other resources to make up the difference.

Identify the non-essentials. You may not be able to boost your income right away, but you can stretch the money you have by starting to pare expenses. Now that you have a list, divide them into must-haves (a place to live, food to eat, utilities) and nonessentials (vacations, dining out, premium cable, etc.).

The average American family today spends about 40 percent of its food budget in restaurants; prepare more meals at home and you’ll not only save money but possibly enjoy a healthier diet. Note, too, that some expenses, like that sky-high cable bill, can be more negotiable than you might think. It’s well worth a phone call to ask.

If you’ve never made a budget before, now’s a good time to learn how.

In fact, taking a close look at how you spend your money is a worthwhile exercise whatever your employment status. “Even people who are employed should usually spend less and save more,” Rose says.

Related: 5 Annoying Fees You Should Stop Paying Now 

Consider your health costs. The loss of a job usually means the end of employer-paid health insurance, so you’ll need to replace it or risk facing a costly illness that could put you in an even worse financial bind. There are many things you can probably do without while you’re unemployed, but health insurance really isn’t one of them.

Under the federal law known as COBRA, you may be eligible to stay on your ex-employer’s plan for a period of time, though you’ll have to pay the full cost, which can be expensive. If your spouse works, find out how much it would cost for you to join his or her plan and compare that against COBRA. If neither of those is a viable option, you’ll need to go insurance shopping.

Under the Affordable Care Act, if you lose your employer health insurance, you have a special 60-day window to purchase new coverage through the Health Insurance Marketplace for your state. The price will be based on your income and household size. By applying, you can also find out whether you’re eligible for coverage under Medicaid or the Children’s Health Insurance program (CHIP).

Shop around for life insurance. If your employer provided life insurance, you may have an opportunity to continue that coverage by paying for it yourself, but you could find less expensive policies by shopping around. If you don’t have any dependents, life insurance isn’t critical, but if you have young children or others who count on your income, it’s important.

Think twice before tapping your retirement fund. If unemployment lasts long enough, you may need to dip into your savings to pay the bills. As a general rule, you should reserve your retirement accounts for last, to preserve their tax-deferred compounding and avoid a potential financial crisis later in life. But there are exceptions, Rose notes.

For tax purposes, she says, it may be shrewd to make some withdrawals from your retirement accounts and take advantage of the lower tax bracket you’re likely to be in because of your reduced income. Bear in mind that generally you can’t make withdrawals without penalty before age 59 ½, and you’ll still owe taxes in most cases. This can be complicated, so it’s wise to get professional advice.

Related: Quiz: Test Your Retirement Savings Savvy 

Stay out of tax trouble. Severance pay and unemployment benefits are taxable, according to the IRS. Even if you can’t afford to pay all the taxes you owe, you should still file a tax return, the agency says. The IRS website has advice on what to do in that situation.

Don’t give up. Unemployment usually doesn’t last forever, though it can seem like it at the time. Once you’re back at work, try to rebuild your emergency fund and replenish any savings you spent. It may never happen again, but if it does, you’ll know how to handle it.

Greg Daugherty is a longtime personal-finance writer and a former senior editor of Money magazine.