Soon after you retire, you'll probably have to start withdrawing the money you assiduously deposited month after month, year after year.

That's more complicated than it sounds.

Remember all those decisions you made about money going in? Stocks or bonds? Tax-deferred or after-tax? IRA or 401(k)?

Now you have to make all those same choices in reverse. You'll have to decide how to manage the money coming out if you want to make your money last as long as possible. For example, should you withdraw from taxable accounts first, or after-tax accounts? Sell stocks or bonds?

There's some help on that front from a new study published in the April issue of the Journal of Financial Planning. Authors John Spitzer, an economics professor at the State University of New York at Brockport, and Sandeep Singh, a finance professor there, looked at various combinations of retirement portfolios to see which harvesting strategies made the most sense.

Here's what they found:

-- If you take out less than what your investments earn on an after-tax basis every year, it doesn't matter how you withdraw your funds. To be sure of doing that, you'd have to stick with a safe withdrawal rate of 4 percent a year. So if you had a $500,000 well-diversified nest egg, you could probably withdraw $20,000 in the first year and 4 percent of what's left each year without running out of money. If you need more than that, say 7.5 percent of your savings in the first year, you'll have to do some juggling to make your money last as long as possible.

-- If your portfolio is split between stocks and bonds, deplete the bonds first. The study found that if you spend the first seven years of your retirement pulling money out of bonds and letting your stocks ride, your money will last three years longer.

There is a bit of a risk here: Most experts say that as you age, it's safer to keep a higher percentage of your portfolio in bonds to guard against stock market losses.

These findings run directly counter to that and suggest that bigger withdrawals require the greater risks of stock investing. In any portfolio that's divided between two assets, it is clearly better to first take distributions from assets that have a lower expected return rather than a higher one, the authors say.

Of course, the challenge lies in determining which has the lower expected return. In general, bonds have lower returns than stocks. But if you're starting your retirement after a huge stock run-up -- say you retired in 2000, for example -- you might have projected that bonds would have a higher expected return than stocks and done exactly the opposite of what the authors suggest here.

-- If you have a tax-deferred IRA and a Roth IRA, from which withdrawals are tax-free, and both are growing at the same pretax rate, it doesn't matter which you take out first. They will run out at exactly the same time. That's surprising and counter-intuitive, but mathematically true, the authors say.

-- If your portfolio is split between a tax-deferred account like an IRA and a regular taxable account, the calculations get really complicated.

Conventional wisdom holds that you should use the regular account first and only withdraw money from the tax-deferred account when you have to later. But that's not always true. If the after-tax returns of the regular account are larger than those of the tax-deferred account, you should use the tax-deferred account first.

The authors don't specifically address this, but harvesting tax losses in a regular taxable account might be the most efficient way to make money last. You could lower your tax burden, and thus, the total amount of money that you need to spend in a year. And you could leave your winning investments to accumulate longer.

-- You can space out those withdrawals even further if you watch your tax bracket. If you have both Roth and traditional IRAs, you can stretch your income by taking enough out of the Roth every year to keep the taxable withdrawals from the traditional account down to a lower tax level. If your taxable withdrawals are going to be high enough to push you into a higher tax bracket, consider supplementing with Roth withdrawals.

Of course, there are other issues to consider, such as the size of your nest egg, the likelihood that you want to leave some of it to your heirs, your tax bracket at various stages of retirement and the size of the mandatory IRA withdrawals you'll be required to start making after age 70 1/2.

The bottom line? You could easily use up all your free time in retirement with spreadsheets like the ones the study's authors created. But the math matters. Do it right and you'll have extra cash for a longer retirement.