When you first sign up with a wireless telephone provider, the phone that you buy from them will come at a heavy discount- up to $200 off, in most cases. To protect this subsidy, not only do most providers lock you into a service agreement with an early deactivation fee, they make it so you cannot reprogram the phone's number or its network code without the Subsidy Lock Code, which they generally keep secret.
Getting the subsidy lock code anyway
When you call into a wireless company's call center, you are going to be connected to an agent who very likely doesn't know or care that he or she is not supposed to give out the code. So you can call up, and just ask for it. The can usually look it up in a database, based on your ESN. Failing that, say that your phone isn't working, and needs to be reprogrammed. Say that when you get the phone to display its own number, it is off by one digit. Or call to get your number changed because of prank calls- anything which would require the reprogramming of your phone. They will more likely than not then just walk you through reprogramming the phone- giving you the sublock code in the process.
What use is the sublock code, if I have it?
Remember that just changing the phone number in your phone is not enough to actually change your number. It does need to be changed in your provider's networks as well- the network will generally know what ESN and what phone number go together. There is not much you can do with the sublock code apart from taking your phone and using it with another provider- of course, given that the other provider uses the same type of wireless technology (such as CDMA, TDMA, or GSM), and is willing to support your particular phone.
Note: If the sublock code doesn't work, it may just be off by one digit, due to rounding. Generally the sublock code is generated off of the ESN. The process which does this is apparantly not as accurate as it can be. Also, once you have the ESN code, it is often possible to change it.