A fundamental of good personal finance is to have a backup plan—or a stash of money that will buffer you against the bigger knocks in life, such as an unexpected health care expense or a loss of your primary source of income.

Your safety net fund should be a somewhat liquid account that you can access on a few days’ notice.

But how much do you actually need to set aside in your safety net fund? Much of that depends on your monthly essential expenditures. There is no perfect answer, but here’s a guide that you can personalize to get an answer that’s right for you.

What Are Your Essential Costs?

Ideally, you should have an estimate for the smallest amount of money that you’d be able to live on month-to-month. That includes your total bills and expenses on the following: housing, utilities, loan payments, food, clothing, transportation, health insurance, and other essentials. You’ll want to add those up to get the sum of your total monthly expenditure.

In case you lose your primary source(s) of income or, you also need an idea of how long you might be without that income.

A good way to estimate how much you might need is to multiply your monthly minimum expenses by your re-employment period (the number of months it might take you to find a new job). According to September 2016 data from the Bureau of Labor Statistics, the average duration for unemployment in the United States was 27 weeks. You can customize that timeframe based on your industry and skills.

In general, it is a good idea to have a minimum of three to six months of monthly expenses covered in your safety net fund.

A Quick Estimate

If you can quickly estimate your monthly expenditures, then you can also approximate the amount you’ll need for your safety net fund by using your monthly gross income (before taxes) and your residential zip code.

We can also calculate this for you by using the same methodology used in RetireGuide, Betterment’s retirement planning tool. We use your monthly gross income, zip code, and then adjust for taxes as well as propensity to save or spend multiplied by three months of anticipated unemployment.

First, your gross income can help us estimate your after-tax income. While your pre-tax savings in Individual Retirement Accounts (IRAs), 401(k) plans, and other personal deductions might impact our estimate, we don’t anticipate that it will be material. We use these variables because there is a strong relationship between your pre-tax income and how much you’ll be spending each month.

Next, we consider how much it generally costs to live where you live.

We use your income and zip code to estimate how much we think you spend each month. This allows us to estimate what a three-month baseline safety net fund would be, or enough money to cover your expenses for three months.

Betterment encourages people who earn more to save more. course, the number derived from an estimate is just that, an estimate. If you can calculate your monthly spending needs using the more personalized method, you’ll likely reach a more precise amount. For any given income level, we calculate tax, and then estimate how much we think you should be saving.

Calculate Your Safety Net Fund Amount

Here’s a simple formula to get you started:

Monthly expenditures x Re-employment period = Baseline safety net amount

If you can fully fund your baseline safety net, you might consider creating a safety net fund that is even larger than this amount and investing that money.

For those who have not yet saved for a safety net fund, Betterment’s advice can tell you exactly how much you need to save every month to meet your target over the next three to five years. For example, if your goal is to save $20,000 in three years for a safety net, Betterment suggests a monthly deposit of $521.86 to get you there.¹

Of course, you should always keep a small reserve of cash on hand for immediate emergencies.

But if you plan to keep a safety net fund in place over the long term, investing that money might be a smarter choice as cash will likely lose its value due to inflation.

1Suggested monthly deposit based on Betterment’s default safety net advice with zero initial deposit, which recommends an asset allocation of 40 percent stocks. Returns are subject to the disclosure found here.

More from Betterment: