Basically the password system is written into the game. Each password tells the game to start from a certain point. Generally there is a password for each level, where you are 'awarded' the password for the next level after completing the previous. The reason for this was because when cartridges were used, there was no memory resident on the console to save your game, and the cartridges only contained ROM (read only memory) which stored the game. Some NES games did have actual save features (like the original Zelda), but those cartridges were more expensive to produce (because of the specialized memory and battery to keep the memory powered so the stored information is not lost on shutdown), so they were not used extensively. Eventually we started to see systems using memory expansion packs for saving (like N64 and Playstation) and the password system went away. Now consoles include hard drives or flash memory for saving, so memory expansion packs have disappeared as well (except for playing Gamecube games on the Wii).