OK
These are instructions on how to unlock the iPhone 3G and iPhone 3GS for use with any GSM cellphone carrier using UltraSn0w. This will work with the iOS 4.0 firmware.
Before you can follow these instructions you must have a iPhone and you must be on the 04.26.08, 05.11.07, 05.12.01, or 05.13.04 baseband(modem firmware).
To find your firmware and modem firmware(baseband) versions you can follow tutorial.
If you are on T-Mobile remember to turn off 3G before starting...
YouTube - How To UNLOCK iPhone 3GS & 3G - ULTRASN0W on 05.13.04 BASEBAND (How to Apply Unlock))