We all know we need to save for retirement, but it can be hard to figure out which of all the different accounts with tax benefits to prioritize with our limited savings. Making the wrong decision can cost us higher taxes, less flexibility, or even lost free money. Here are some factors to consider when prioritizing your retirement savings:

1) Have you taken out a Roth IRA max?

The main advantage of a Roth IRA is that any earnings are tax deductible as long as you have had an account open for at least 5 years and are over the age of 59 1/2. However, you can also withdraw the sum of your contributions for any reason without taxes or penalty in the meantime. Any earnings you withdraw before 5 years and age 59 may be subject to taxes and a penalty of 10%, but contributions come first. (Exceptions to the 10% penalty include education expenses and up to $10,000 for a first-time home purchase.)

Since you can always access contributions, they can double as part of your emergency fund. If you already have emergency savings, you can simply contribute it to a Roth IRA up to the annual limit. Just be sure to keep your Roth IRA in a safe and accessible place such as a savings account or money market fund until you create a suitable emergency fund (enough to cover at least 3-6 months of necessary expenses) elsewhere. At this point, you can invest your Roth IRA more aggressively for tax-free retirement.

If you don’t have an emergency fund, having at least a few thousand dollars in cash reserves should be your top priority. Otherwise, you may find yourself raiding another retirement account (and possibly paying early withdrawal penalties) or defaulting on your rent, mortgage, or emergency car payments. Having to complete a withdrawal form to take advantage of a Roth IRA may discourage you from exploiting it for trivial things.

If your income is too high to contribute to a Roth IRA, you can contribute to a traditional IRA and then convert it to a Roth IRA. As long as you don’t have any other IRA money before taxes, you only pay taxes on the earnings you transfer. If you have other money from a pre-tax IRA, see if you can include it in your employer’s retirement plan by the end of the year to avoid some tax complications.

2) Does the employer match retirement plan contributions?

If so, then the maximum of that match should be the next priority. Where else will you get a guaranteed return on your money? Don’t leave that free money on the table! Of course, you’ll also get all of the other benefits of your retirement account like pre-tax contributions or tax-free growth, potentially low cost or unique investment options, the ability to borrow against it and pay interest to yourself, and creditor protection.

3) Are you eligible to contribute to a Health Savings Account (HSA)?

If you’re enrolled in a qualifying high-deductible health insurance plan, you can make pre-tax contributions to a health savings account and use the money (and any earnings) tax-free for eligible health care expenses. Whatever you don’t spend on healthcare now can be invested and used for any purpose without penalty after age 65 as part of your retirement savings. The money can also be used tax-free to pay for future qualifying medical expenses, including some Medicare and long-term care insurance premiums. When you consider that you will likely have medical expenses in retirement, you may want to try paying for health care from other savings. This allows HSA’s money to grow for as long as possible to be used tax-free for healthcare costs in retirement.

4) Are you eligible to contribute to a 457 plan?

This retirement account is available to many public sector employees and has the same tax benefits and contribution limits as 401(k) and 403(b). However, there is no penalty for early withdrawal. This extra flexibility gives priority over others if you are under 55.

5) Have you reached your employer retirement plan cap?

If not, this should be the next priority for all of the reasons for nonconformance under #2. Keep in mind that even if you reach your pre-tax/Roth limits, your plan may allow you to contribute after-tax. You can then transfer the after-tax dollars into a Roth account so they can then grow to be tax-deductible eventually. Some plans allow you to perform a Roth conversion while you're working there. Otherwise, you can transfer the money to a Roth IRA.

6) Are you investing tax efficiently outside of tax accounts?

If you reach the limit on all of your eligible tax accounts, you can still save and invest for retirement in a regular investment account. Since your interests, profits, and capital gains will be taxed each year, you'll want to use this account for investments that generate the least taxes. This means individual stocks and ETFs, low turnover mutual funds, and municipal bonds. Taxable bonds, high-turnover mutual funds, and REITs should be kept in tax-protected accounts as much as possible. If you are not sure how to do this, this may be a good reason to hire a financial advisor or use an automated tax advisor.

As you can see, figuring out which accounts to contribute to first is not always easy. If you would like additional assistance in making this decision, consider consulting a qualified and unbiased financial professional. Don't let this paralyze the analysis though. Contributing to a less than ideal account is still much better than not contributing at all.