First of all, ESN stands for "Electronic Serial Number". Similar to the IMEI (International Mobile Equipment Identity) number, this is a number that uniquely identifies a phone.
The difference is that an IMEI number is attached to a phone that takes a SIM card using GSM (Global System for Mobile communication) technology. An ESN is a numeric identifier attached to a CDMA (Code Division Multiple Access) phone.
If the phone is under contract, either one of these numbers may be linked to the subscriber's account.
A CDMA phone typically does not use a SIM card. We say typically because there are some phones that use both GSM and CDMA technologies.
There are certain iPhones being used on Sprint and Verizon, for example, that are both GSM and CDMA capable. That means that they can be used on GSM networks, under certain conditions.
Usually, after officially unlocking the GSM side of those iPhones, they can be used on GSM networks. However those GSM networks must be outside of the United States. The CDMA side will continue to work on the original carrier's network.
So, what is this clean/bad ESN all about? Since the ESN number is linked to the subscriber's account, if that phone is ever lost or stolen and reported as such, the provider of that phone can block its ESN, better known as "blacklisting" it.
The phone may be blacklisted as well if the former subscriber didn't pay their bills. Putting an ESN on a blacklist means that it cannot be used on the issuing provider's network. It is no longer "clean".
In the past, someone could just take a phone with a bad ESN to another CDMA carrier and use it with no problem. More recently, USA carriers have begun to share their blacklists, making it more difficult for a phone with a bad ESN to be used.
Verifying whether an ESN is clean or not involves contacting the original provider directly. You would take the same route for cleaning an ESN, basically presenting proof that you purchased the phone.
This can be a real hassle when decisions need to be made about purchasing the phone in question.
On a side note, ESN numbers are running out. So what is being done about that? Here's where the MEID (Mobile Equipment Identifier) number comes in. The MEID is more compatible with the IMEI system, as described above, but the MEID is still associated with a CDMA phone.