Retirees who saved diligently over the years may be in for a shock when they discover how little they can safely spend in retirement.

Many financial advisers recommend you spend 4% of your portfolio in the first year of retirement and adjust that amount in subsequent years for inflation. For example, if you’ve saved $1 million, you should only spend $40,000 in your first year.

Some retirees may wonder why they can’t spend more if the stock market delivers double-digit annual returns. After all, they’ve worked hard and saved for decades to enjoy their golden years.

But people are living 20 to 30 years or more in retirement, and running out of savings is now a real possibility for many of them. If you’re caring for someone who is retired or planning for your own retirement, it might be helpful to analyze potential spending scenarios.

According to data compiled by the Social Security Administration, a man reaching age 65 today can expect to live on average until 84. A woman will live on average past 86. (Try Social Security’s life expectancy calculator here.)

What’s more, you have to account for the uncertain future returns of your portfolio. If you retire at the start of a stock-market downturn, your conservative spending in the early years will help you weather the storm and your portfolio will benefit from the subsequent recovery. “You’re going into retirement, you have no idea what’s going to be happening,” says Judith Ward, senior financial planner with T. Rowe Price in Baltimore.

That’s why financial experts like Ward say it’s important to focus on spending, the one area where you have the greatest control, especially if you have a well-balanced portfolio of stocks and bonds. “It guards against bad things happening at the beginning of retirement,” Ward says.

Retire Lucky

Don’t be misled by average annual returns for stocks. For example, U.S. stocks have delivered about 10% average annual return before inflation over long periods of time.

So why limit your spending to just 4%? That’s because those stock returns didn’t come smoothly. Some years they delivered stronger returns, and other years they suffered losses.

Conservative spending, especially during the first years of retirement, will pay off as you age. If you retire at the start of a bull market, you’ll be able to adjust your spending higher in your later years.

If a bear market mauls your portfolio, this conservative approach will help you weather the storm. That’s because if you sell fewer stocks when they’re down, your portfolio has a better chance of recuperating when the markets rebound.

It’s important to remain invested in stocks—40% to 60%—because they offer greater appreciation than bonds over the decades you may live without working. If you have a well-diversified portfolio of stocks and bonds, your spending rate matters more than tinkering with asset allocation, planners say.

Flexibility is Key

The early years of retirement are critical because if you spend too much in a down market, your investments won’t recover.

But you don’t have to be a slave to the 4% rule. “I look at it more as giving people a starting point for their spending,” says Ward. “It’s not necessarily a spending plan.”

Life is unpredictable and you may need to draw on assets for family emergencies, health care or other needs. But the point is you can adjust your spending accordingly, especially if you experience a bull market in the first few years. “If the next five years are fantastic, you can spend more,” Ward says.

In addition, you might continue working in your later years and you may not have to draw as much as 4% from your savings. If you take required minimum distributions from your IRA, you might consider reinvesting the proceeds instead of spending them.

Fund companies can help you manage your variable spending rate in retirement. For example, Vanguard Group’s hybrid strategy will let you set a ceiling and a floor to each year’s spending amount, calculated annually.

Browse Our Free Senior Care Guides

Using Vanguard’s program, called Dynamic Spending, each year you might consider a range of withdrawals, from a drop of 2.5% to an increase of 5% from the previous year. When the markets perform well, you can withdraw up to the ceiling amount, giving you more money to spend. If the markets perform poorly, you can reduce your spending and still feel like you won’t risk depleting your portfolio prematurely.

In an analysis published in September 2016, Vanguard found that the more flexibility retirees have in reducing their spending when markets are performing poorly, the more likely their portfolios will last.

Market Simulation

With so much future uncertainty, how do financial planners know the odds that your spending and asset allocation can last 30 years?

Many financial planners use a Monte Carlo simulation to determine whether your spending rate and asset allocation can withstand market swings decades in retirement. Monte Carlo simulation is a computer tool that models future uncertainty by running thousands of scenarios and producing outcomes based on probability.

For example, T. Rowe Price uses such simulations in determining the percentage of success a portfolio might have given a spending rate. Any positive result above 80% is a good range, says Ward.

But if you score an 80% probability of success, don’t worry that there’s a 20% chance you’ll run out of money. Instead, you might consider reducing your spending, especially in early years. “There’s a 20% probability you might have to make adjustments,” says Ward. “Some of these adjustments might be easy to make.”

Also, you shouldn’t have to run the analysis more than every few years except in the event of a significant drop in the value of your assets. “One of the problems [with] running it every year [is that it] will jerk you around a little bit,” Ward says. “Keep an eye on your balances.”