How to Unlock Your Iphone 3g or 3gs - use you iPhone on T-Mobile

Most iPhones are acquired on a monthly contract, and are locked to the network operator you take your contract out with. When your contract ends, you may want to continue using your iPhone on a different network, or as a prepaid phone with a different SIM card. Before you can switch to a new operator, the iPhone must be unlocked, allowing it to work with any SIM card and on any cellphone network.

...
Unlocking an iPhone is not illegal.

Step

Call the network operator that originally supplied your iPhone and request an unlocking code for the handset. The operator will ask for certain details, such as your cell phone number and email address, so they can send you the unlocking code and instructions.

Step

Follow the instructions given by the network operator for unlocking your iPhone using the supplied code. This will differ depending on the network operator. The instructions and code will usually be supplied by email, and can take up to two weeks to arrive.

Step

Hold down the power button on top of the iPhone and slide the red switch to the right when it appears on the screen. The iPhone will shut down.

Step

Insert the SIM removal tool into the small hole next to the SIM card tray on the side of the iPhone. The SIM card tray will eject, allowing you to fully remove it from the device.

Step

Replace the existing SIM with your T-Mobile SIM card, and reinsert the tray into the iPhone. Push the tray in fully, until it is flush with the handset's casing.

Step

Press the power button to turn the iPhone back on. When the iPhone reboots, it will connect to the T-Mobile network.