Unlocking a cellphone is a quick and relatively simple operation but might result on the loss of your mobile's warranty. The difficulty in unlocking phones varies between manufacturers and even by phone type, some are easier why some are harder.
Unless you're into electronics and computers it is best to leave the unlocking to a professional. These exist all around the world for various prices. In Canada, it costs around 30-50 dollars to unlock a GSM phone whereas in Eastern Europe it can be done with 5 dollars. You can generally find these places on internet forums, walking around the street, or in the classifieds in the newspaper.
There are also sites that offer to unlock your phone for a fee. They then give you some software to download and run yourself. It is suggested you avoid these as these can be scams, are overprices, and can result in a broken phone.
Why was your cellphone locked when you bought it? It is because mobile carriers generally lock their phones to their network when you buy the phone subsidized (on a contract). This way the phone can not be used on a competitors network by switching the service but will only work on the original carrier's network. If you unlock your phone, when travelling, you can purchase a SIM card from a provider of that country and avoid roaming fees. It is perfectly legal to unlock your GSM cellphone and it is a safe operation if done by professionals.