Cheat codes help change the original game to add additional content to the gameplay. Unlocking different art work, different clothing, different endings, or accessing hidden levels left by the developers, all in an effort to boost it's replay value. Other cheat codes make it so the character is invincible or has unlimited ammo/energy.
Cheat codes were originally put into games for testers to effectively test certain circumstances in games that would not normally happen. Eventually they were accidentally and then later on, purposefully left in as hidden gems for the player to discover. The Konami Code ( up, up, down, down, left, right, left, right, B, A), arguably one of the best-known 'classic' cheat codes was first used in the game Gradius, because one of the top people working on the game, Kazuhisa Hashimoto, thought the game was too hard during testing.