Network Lock makes the phone function only with cards from one single network.
Service Provider Lock is only used in countries with so called Service Providers, which means companies reselling the services of one or more net operators. They have no net of their own. The SP-lock makes the phone function only with cards issued by that specific Service Provider.
SIM Card Lock makes the phone function only with one single card. If your SIM card malfunctions, you'll have to return both the card and phone.
The most used lock is the SP-lock (Service Provider Lock).
Locks of these kinds vary considerably from country to country. One extreme is Finland where providers are not allowed to lock the phone at all (it is considered hindering real competition). Many other countries prohibit locking; others allow locking only for the duration of a service contract. The United States is more restrictive, though not by law. U.S. GSM providers lock their phones as part of a business strategy to lock customers into their service contracts; some providers (notably AT&T Wireless) will not unlock their phones even when a customer has fulfilled his contract. The other extreme is exhibited by Hungary, where nearly all phones are locked for life.
The code you need to unlock the phone is not generated with the help of any mathematical formula. It is randomly generated and kept in a database in the computers of the operators. So it is no use, like thousands of other users, to try to find "the right code" on the internet. It is ONLY the issuer, NO ONE else, who can supply you with the code. There are some scams, where they promise to give you the code. Forget it! What you actually can find are so called "phone clips" which you to the contact of the phone and reprogram the software so that the lock disappears. These clips are often very expensive.
The software of the phone is made in such way that it asks for the unlock code if you place "wrong" SIM card in the phone. This code is ONLY obtainable from the issuer. (AT&T Wireless phones will not even ask for an unlock code; they simply display a message indicating that the SIM card is not compatible.)