Retirement tax questions

Can you explain more about not having to withdraw excess earnings? My understanding is that to avoid the 6% penalty, you have to withdraw both the original contribution plus the earnings as calculated per IRS NIA formula of that excess portion?