In determining how much of an unqualified distribution is taxable, distributions are considered to have been made in a certain order, as follows:
Regular contributions are considered to have been distributed first.
Conversion contributions are next, on a first-in-first-out basis (the earliest conversions are considered as distributed first). The taxable part of the conversions (the amounts that had to be included in income at the time of conversion) is considered first, followed by the non-taxable portion.
Earnings on contributions are considered as distributed last.
Calculating Taxable Part of an Unqualified Distribution
There is a worksheet in Publication 590 that guides you through the calculation to determine the taxable part of any unqualified distribution. For purposes of this calculation, contributions and distributions are grouped together. This calculation is summarized as follows:
Total of all distributions from your Roth IRAs during the year
Minus qualified distributions during the year
Minus distributions made during the year to correct excess contributions during the year
Minus distributions that were contributed to another Roth IRA in a qualified rollover
This result is them compared to the result of the following calculation:
Total of all prior distributions from your Roth IRAs, whether or not they were qualified
Plus distributions from your Roth IRAs during the year
Minus distributions that were previously included in your taxable income
Minus the total of all your contributions to all your Roth IRAs, less total distributions made to correct excess contributions (this year and in prior years)
This result is then compared with the first, and the smaller of the two is the taxable part of your distribution.