Will restoring my Iphone 4 unlock it?

I just bought a locked iphone 4 from a friend, and it's locked by AT&T, and my carrier is T Mobile. If I restored my Iphone 4, what it unlock it? What does Restore mean? What does Back up mean? And what's the difference? I'd appreciate it if you answered all of my questions.

Restore means it will restore to manufacturing settings i.e. Everything will be erased.
If your new phone is using GSM, you are screwed and you will have to pay a lot for a company like that to change your phone to another carrier. They make changing carriers expensive and tedious so that you'd rather buy a new phone (Don't you love capitalism?)
Back up means that you used another iphone previously and you would like to transfer all of your files from your old phone to your new one. I recommend you restore it to avoid having to use your friend's account whenever you want to update or install a new app.
If it is by SD card, just get card out and put your T-mobile one in. You should go to your carrier.

About Backup and restore
When you restore your phone you basically change the full operating system, and either replace it with the same or an upgrade version of it. Is important to have a backup of your important data like contacts, picture etc because when restoring the system the phone will be reverted to its original state, with no data on it just it's operating system (like new). For iPhones is very easy to make a backup with their free program iTunes, and after you do the phone restore (that is done also with iTunes) can get back all your information and data you previously had using your backup.
About unlock
For iPhones the unlock status is managed by the apple servers, so each time you want to use a new sim card the iPhone will need to activate it with the apple server and will verify if your iPhone is allowed to work with that carrier or not. If is unlocked you will be able to activate any sim you want, if not only the sim card from the network is locked to. To unlock an iPhone you need to change the status from the apple database from "Locked to AT&T" to unlocked. That can be done trough your carrier, for example for at&t, if you have an account with them in most situations should be able to get the phone unlocked for free. If not have to use an independent unlock method, that now for at&t starts from 45$:
http://www.onlineunlocks.com/at-t-iphone-unlock