For example, say you accidentally contributed $8,000 to your Roth IRA, although you were eligible to contribute only $7,000 this year. So your excess contribution is $1,000.
Your AOB was $10,000, and your ACB is $12,000. You'd subtract your AOB ($10,000) from your ACB ($12,000), leaving you with $2,000. Then you'd divide this by your AOB, leaving you with 0.2.
Finally, you'd multiply this by the amount of your excess contribution ($1,000), giving you your net attributable income, $200.
So if you want to avoid the 6% penalty on your excess contribution, you have to remove the $1,000 contribution itself and the $200 you earned because of that contribution.
If you go through the preceding calculations and find you've taken a loss instead of earning money on your excess contribution, you subtract this loss from the amount you must withdraw.
For example, if you follow the formula and find out you've lost $200, you only have to withdraw $800 to satisfy the government.
Successfully removing the excess contribution before the tax deadline will help you avoid the 6% excise penalty, but you'll still have to pay income tax on this money. If you're younger than 59 1/2, the government will also charge you a 10% early withdrawal penalty on any earnings you withdraw. So in our example, you'd owe $20 of your $200 in earnings to the government, plus income tax.
If you don't remove your excess contribution before the tax deadline, you can file an amended tax return after you've removed the funds, but you must do this by the October tax extension deadline. The government will review this and refund you any penalties it's taken out if necessary.