iPhone: About unlocking - http://support.apple.com/kb/HT5014 - Only some carriers offer the ability to unlock iPhone for use on any carrier. Follow the instructions in this article to unlock your iPhone.
iPhone: Wireless carrier support and features - http://support.apple.com/kb/HT1937 - including a list of which ones offer unlocking.
Some carriers will not accept unlocked phones - https://discussions.apple.com/message/20359060 - "Virign Mobile, like all CDMA carriers, will only activate devices on their network that were initially sold for use on their network."
https://discussions.apple.com/thread/4535859 - topic detailing the procedure in unlocking an AT&T phone