When one looks at the NES specs and wonders how the games achieve what they do using that hardware, the answer is, they don't. It's quite important to notice that most NES games rely heavily on HW extensions, or extra "hardware acceleration", as it might be called today, on the cartridges. Only the early, or very simple-looking games were simple ROMs. The games most people think about when they wonder how they achieved it, however, utilize the external addon chips, misleadingly termed as MMCs or "memory management controllers", even though they do a lot more than what is meant by "memory management" today, even things totally unrelated to memory handling (such as providing extra audio channels, etc.)
Supporting all, or even most of these chips is/has been an issue when writing emulators.
This made the lifespan of cartridge-based consoles longer, as they could always "upgrade" your console by supplying some new HW; think about how the latest NES games (utilizing the latest addon chips, and doing it well) looked nearly as good (or even better) as the first or cheapest SNES games (utilizing none).