Instructions
Look for a code menu on the main screen of the game. Some games intentionally program codes into their games to give you invincibility or to unlock characters and they have a specific code screen for you to enter it. On older games, this is also how you used to be able to keep track of your game progress.
Read the exact instructions for the code in question. Codes must be entered on a very specific screen in a specific way for the exploit to work. For example, a code may require you to pause the game on the third level and enter in a button sequence before the code becomes effective. In some instances, even the timing of the code is important. If you miss a detail of how and where to enter the code from the instructions, the code will not work.
Enter the code as instructed when the appropriate time in the game arises. Some games allow you to mix-and-match codes, giving you multiple attributes at once. For example, you may be able to enter one code to exploit unlimited health and then enter another to gain unlimited ammunition. Other games will restrict you to one code at a time.