Insert SIM card from another network provider.
Check the "attempts remaining" status. The counter have to be at minimum 1, otherwise your phone is blocked and you can't unlock it by unlock code.
The unlock code is unique for every phone. You have to provide the IMEI number from your phone to get your unique unlock code.
You have to provide the IMEI number. You can find it from Settings ► About ► More information or by dialing a code - *#06#
If your contract has ended, you can request the code from your provider. Another way is to buy an unlock code.