As previously discussed in Why use an unlocked phone?, there is no locking mechanism available in CDMA phones. The subscriber identity information of the CDMA phones is controlled by the carrier, so the phones themselves do not have locking mechanism. So, the unlocking mechanism only applies to GSM phones. To give you a simple answer before you read this entire article, you’ll have to ask your carrier to unlock your GSM phone.

Why is it illegal to unlock a phone yourself?

In 2006, the Librarian of Congress decided to exempt phone unlocking from the DMCA (Digital Millennium Copyright Act). However, the Librarian reversed the decision in 9/2012 and “phone unlocking” is no longer exempted under the DMCA. Every three years, the Librarian reviews the specific rules of the DMCA, and makes the decision. Unless president overrules the decision, unlocking is illegal until the decision may reverse again by the Librarian in the future reviews. The primary reason for the reversal in 2012 is that increasing number of phones sold in the USA is unlocked, and the users no longer need to unlock the phone themselves.

Due to reversed decision, any phone purchased after 10/27/2012 cannot be unlocked by a user (or 3rd-party). The phones purchased prior to 10/28/2012 can be unlocked by anyone. With 90 days of grace period, it is illegal to unlock your GSM phone for those phones purchased after 10/28/2012 beginning 1/26/2013.

How do you unlock a smartphone?

Before you unlock your phone, you’ll have to understand unlocking your GSM phone does not necessarily make it completely portable. You’ll have to do some homework and make sure your “unlocked” phone will be compatible with the carrier you plan to use.

Phones are locked by wireless carriers to restrict use of the phone on other carriers’ network. The best way to unlock your phone is by asking the carrier to unlock it for you. As long as your account is in good standing, and you have a legitimate reason such as traveling outside of USA or traveling to a poor coverage area will likely get your carrier to unlock your phone temporarily. AT&T and T-Mobile will unlock any phone at the end of service contract if you ask. So there is no real reason for you to unlock your phone yourself especially when it is illegal to do it yourself.

References:
AT&T Unlock Policy
T-Mobile Unlock Policy