A locked phone is one that is specially set-up to only work with a particular network (such as O2, Vodafone, etc.)
Why would a phone be locked?
The most common reason is to force -- or at least attempt to force -- a phone owner to use the handset with that network, thus giving it revenue. This isn't just profiteering though: in many cases the network pays money to phone manufacturers or retailers so that the sale price is lower, making it more likely people will get phones in the first place. With smartphones this subsidy can be more than £100. Locking is designed to increase the chances of making this money back.
Will unlocking get me out of a contract?
No, unlocking a practical rather than legal issue. If you have signed a deal for a minimum contract period, which is common with new phone purchases, then you are committed to this, subject to any early cancellation policy. The fact that you have unlocked a phone and are not using the network's services doesn't remove the obligation to pay the monthly fee.
So what's the point of unlocking?
The main reason is to switch your phone to a different network once your minimum contract is up. Theoretically it could be good value to unlock it while an existing contract is still up, for example if you use a lot of data and make few voice calls, and your contract has high data charges or a low monthly data limit, but this is likely to be rare.
How does unlocking work?
There are two main ways, depending on the phone. One is to use a special code which will be generated from your International Mobile Equipment Identity (IMEI) number. The other is to use a data cable connected to a piece of software on a computer.
What are my options?
There are usually four sources of unlocking. The first is from the network itself, which may give you a code in return for a fee, though this is very variable. The second is at a specialist phone unlocking shop, which may use either a code or a data cable. The third is via a mail order service where you post the phone off. Finally, you can get hold of codes or software online, both for a fee and free of charge.
What are the pros and cons?
Using the network is the most reliable, but also likely the most expensive. Using a shop should be safe enough but may be costly. A mail order service has the drawback that you will be without your phone, plus must pay to have the phone delivered securely. Getting a code or software online can be the cheapest option, but you need to be very wary it isn't a scam of some sort.
With all methods (except sometimes via the network) you will be acting legally but may technically breach the warranty, which could be costly if the phone later becomes faulty.
I've heard about services to unblock a phone. Is this the same as unlocking?
Not at all. A blocked phone is one that's been reported lost or stolen and where the relevant network has remotely blocked it to stop anyone else making calls. While there are illicit services claiming to overcome this, doing so would be illegal. This also means that if you were ripped off by such a service, you'd struggle to get a refund.