Can you unlock T mobiles iphone 5 and use it for AT&T?

Tmobile sucks, so I want to change carriers

It depends how long you have been with tmobile if it has beens somewhat long they will give you the unlock code and directions to unlock it but if you just joined them they won't give you the unlock code

You can for sure go the other way… AT&T to T-Mobile… So i'm sure you can unlock T-mobile iphone (soon, if not already) http://gsmunlocklabs.com/unlock-iphone/

If contract is up most carriers will unlock it if you call them as the phone is yours at that point.