its easy. you jailbreak then download a program in cydia called ultrasn0w. ive never used it but you just open and follow the steps its easy.check here for detailed instructions on how to..
iClarified - iPhone - How to Unlock the iPhone 4, 3GS, 3G Using UltraSn0w
good luck
So the question is....Why would you want to unlock your phone to use with Tmobile? I dont see the point if youre gonna get slapped with cancellation fees and such through ATT and itd be a real hassle to have both networks and be switching between the 2 by swapping sim cards.