To unlock your iPhone, contact the new carrier you wish to use and request that they unlock your phone for you. Only a new carrier can unlock an iPhone.
After you contact your carrier, it can take several days for the unlocking process to complete. You also have to meet certain requirements depending on the carrier that you have chosen. Once the carrier confirms that your iPhone is unlocked, you have to reset your iPhone.
If your iPhone has a SIM card, simply replace the old SIM card with a new one provided by your current carrier. A setup process begins and upon completing the setup, the phone is usable again. If you do not have an iPhone with a SIM card, you must back up your iPhone, erase it and then restore it to its previous settings in order to be able to use it with a new SIM card.
If you run into complications, restore your iPhone to its factory settings or restore a backup of the device. Also, contact your carrier and inform them that there was a problem with the unlocking process. Once an iPhone has been unlocked, it remains that way even when updating the iOS.