Before switching from AT&T to T-Mobile, check the technical specifications of the phone to make sure it supports the data options you want to use. While both AT&T and T-Mobile use Global System for Mobile Communications technology, they use different channels for 3G and Long-Term Evolution, and not all phones support all of these frequencies.
Make sure the phone doesn't have a subscriber identity module lock. GSM phone providers can lock phones to a certain provider's SIM cards, making it impossible to use the phone on other carriers. Buying an unlocked phone lets you avoid these locks, but providers often offer significant discounts on locked phones. However, AT&T and other providers generally allow users to unlock the phone after fulfilling contract obligations, and AT&T offers an online interface to allow users to request an unlock code. To use this code, insert a non-AT&T SIM card, and enter it when prompted.
If the phone supports the right channels and is unlocked, insert the T-Mobile SIM card, and follow the online instructions or call customer support to activate the phone. Phone activation varies by the type of plan, but activation typically entails inputting the number on the SIM card and the phone's International Mobile Station Equipment Identity number, which you can find by dialing *#06#. If the phone doesn't work after you've activated your plan, check the Access Point Name settings; most phones update these settings automatically, but some might require you to input T-Mobile's servers.