T-Mobile and A T&T Wireless both uses GSM network. Both cell phone companies uses a sim card on the back of their phones. A sim card is a small card (about the size of your finger tip) that stores your phone address book as well as identifies your phone number to the network when you make or receive calls. Without a sim card, your cell phone won't work at all.
If you want to buy the iphone then you would have to use it with A T&T Wireless. However you can buy a iphone that is unlock, meaning that the software has change on the phone so that you can use it with another cell phone company.
Once the iphone is unlocked you can now use that cell phone with T-Mobile since T-Mobile also uses sim cards and works on GSM network. All you need is a T-Mobile sim card and put in into a unlock iphone and that will work.