For a traditional IRA, you’re usually all clear if you’re 59 ½ or older.
Roth IRAs offer a bit more flexibility. Generally, you may withdraw your contributions to a Roth penalty-free at any time for any reason, as long as you don’t withdraw any earnings on your investments (as opposed to the amount you put in) or dollars converted from a traditional IRA before age 59 ½. Not sure which money is considered a contribution and which is considered earnings? The IRS views withdrawals from a Roth IRA in the following order: your contributions, money converted from traditional IRAs and then earnings. So if you take out more than you’ve contributed in total, then you’re starting to dip into conversion dollars or earnings, and will be penalized and taxed accordingly.
To withdraw earnings from a Roth IRA penalty-free, you must be at least 59½ and it must be at least five years since you first began contributing. If you converted a regular IRA to a Roth IRA, you can’t take qualified distributions until at least five years after the conversion.