Some game developers build cheats directly into their video games. There are several reasons for doing this. One reason is that it can simplify the quality assurance (QA) phase of game development. The QA phase is also known as game testing. Testers try the game out to make sure it's playable and that there are no glitches in the game's code.
If a game is particularly long or has many levels, items and characters, game testers may need a shortcut to test particular scenarios. For example, a fantasy role-playing game might allow characters to wield dozens of different weapons. Walking around the game's world and gathering these items might take several hours of playing. But if the developer builds in shortcuts, the game testers can get their virtual hands on these weapons without going through the effort of finding them. Sometimes these shortcuts stay in the game all the way through to publication.
Other game developers include cheats to encourage players to keep playing their games. No game developer wants a player to become so frustrated with a game that he or she abandons it. Cheat codes give players who have trouble with the game's mechanics a chance to complete the game. Codes can also increase a video game's replay value -- you've gone through the game once as a normal player, now, with the proper cheat code, you can play it as a godlike unstoppable force of nature. And some developers may include cheat codes simply because players expect to find them in modern video games.
Players may discover the secret to unlocking a shortcut by chance or by word of mouth. Some might try to scour the video game's code in search of shortcuts. Eventually word of the shortcuts spreads to sites like GameFAQs or IGN. All you have to do is search those sites for the game you're playing to see if there are cheat codes available.
Cheating with codes is usually pretty simple. Some games have a designated screen into which players can enter codes. Others require the player to pause the action and enter a sequence on a game controller. It might take a try or two to get the rhythm down, but before long you'll be able to turn your hapless character into an invincible warrior.