When planning for retirement, you've probably thought about how much you'll need to cover your bills and sustain your spending habits, but if you haven't factored in how much you'll owe in taxes, an unpleasant surprise is lurking.

Of recent retirees surveyed by Nationwide, 46% say they wish they were better prepared for taxes in retirement. Twenty-four percent of those surveyed reported that they've paid several thousand dollars more in taxes than they had anticipated. Fortunately, with a little planning, you can reduce the amount you'll pay in taxes and keep more of your money for yourself.

Senior couple sitting in front of a computer with papers on the desk and in their hands and looking worried.

Image source: Getty Images.

Taxes on retirement savings

Most 401(k)s and traditional IRAs are tax-deferred. The amount you contribute reduces your taxable income in the year that you make the contribution, but then when you withdraw the money, you have to give the government its share. Money that you contribute to Roth accounts, on the other hand, doesn't reduce your taxable income up front, but is allowed to grow and be withdrawed tax-free. 

The key to minimizing your taxes in retirement is first contributing to the right accounts while you're still working and then sequencing your withdrawals appropriately. If you believe you're in a higher income tax bracket today than you will be in retirement, it makes sense to contribute to tax-deferred retirement accounts. But if you're just starting out in your career and think there's a chance you could end up in a higher income tax bracket in retirement, a Roth account is a better fit.

When withdrawing money from your retirement accounts, be mindful of the income tax brackets. You may want to withdraw money from your tax-deferred accounts until you reach the upper limit of one income tax bracket and then rely on your tax-free Roth savings for the rest of your money. Or you could withdraw an equal proportion of money from each type of account. 

For example, say you have $500,000 in tax-deferred retirement savings and $500,000 in Roth savings. Because you have an equal amount of both, you could draw 50% of your expenses from tax-deferred accounts and 50% from Roth accounts. This will help to minimize your taxes in the current year, though it may inhibit the growth of your Roth savings.

Also keep in mind your required minimum distributions (RMDs). The government requires that you begin taking RMDs from all of your retirement accounts except Roth IRAs by age 70 1/2, unless you're still working. Your RMD amount is based on your age and the value of your retirement savings. You can calculate it using this worksheet

Taking your RMDs can push you into a higher income tax bracket if you're not careful, so focus on withdrawing money from your tax-deferred accounts before the RMDs kick in at 70 1/2. But again, you have to be mindful of how much a larger tax-deferred account withdrawal will affect your taxes for this year. Another option is to rollover your tax-deferred retirement savings to a Roth IRA, but then you must pay taxes on the money in the year of the rollover. 

Capital gains tax

If you've been saving for retirement in a non-tax-advantaged investment account like a brokerage account, the taxes on this money work differently. If you sell an investment after holding it for less than one year, any profit will be subject to standard income tax rates. But if you've held onto that stock for more than one year, it becomes subject to capital gains tax, instead.

These gains may be taxed at 0%, 15%, or 20%, depending on your tax-filing status and your income for the year. Here's a table showing the 2018 long-term capital gains tax rates:

Filing Status

0%

15%

20%

Single

$0 to $38,600

$38,601 to $425,800

$425,801 or more

Married, filing jointly

$0 to $77,200

$77,201 to $479,000

$479,001 or more

Married, filing separately

$0 to $38,600

$38,601 to $239,500

$239,501 or more

Head of household

$0 to $51,700

$51,701 to $452,400

$452,401 or more

Data source: Tax Cuts and Jobs Act

If you're able to keep your annual taxable income low, you may be able to avoid any capital gains tax altogether. But if you exceed the above thresholds by even a small amount, you could end up owing a lot more in taxes than you'd planned.

Say you're a single adult and your income is $38,500 for the year. You sell some of your investments and have a $1,000 long-term capital gain. Because you're below the 15% long-term capital gains taxation threshold, you won't pay any taxes on your $1,000 capital gain. But if your annual income was just $101 higher, you would now only get $850 of your $1,000 gain because you'd lose 15% to capital gains taxes.

Social Security benefit taxes

You can also be taxed on your Social Security benefits if your income exceeds certain limits, though these are different from the capital gains tax limits listed above. Social Security benefit taxes are based on your combined income -- that is, your adjusted gross income, plus any nontaxable interest and half of your Social Security benefits.

Single adults with a combined income exceeding $25,000 and married couples filing jointly with a combined income over $32,000 could be taxed on up to 50% of their Social Security benefits. Single adults with a combined income over $34,000 and married couples with a combined income over $44,000 could be taxed on up to 85% of their benefits.

You may be able to avoid this by limiting your withdrawals from your tax-deferred retirement accounts, but depending on how much your living expenses are, you may have to settle for paying some taxes on Social Security benefits.

Planning for taxes in retirement can be challenging, especially because you don't know how the tax brackets will change or exactly how much your living expenses will be. But if you keep abreast of any changes to the taxes listed above, you should be able to make smart choices that minimize how much you owe the government during your golden years.

The Motley Fool has a disclosure policy.