Format:iNES and NES 2.0 ROM image
Appearance
| Platforms | Platform:Nintendo Entertainment System |
|---|---|
| Magic | 4E 45 53 1A ("NES" + 0x1A) at offset 0 |
| Extensions | .nes |
| Endianness | little |
| On this wiki | Facts · Code · Notes · Topics |
Cartridge image of the Nintendo Entertainment System / Famicom (.nes): a 16-byte header starting with "NES" 1A (iNES, extended by NES 2.0) giving PRG and CHR sizes, mapper number, mirroring, battery and trainer flags, followed by an optional 512-byte trainer, PRG ROM and CHR ROM.
Layout
Header (16 bytes), optional trainer (512 bytes, if flags6 bit 2), PRG ROM (units of 16 KiB), CHR ROM (units of 8 KiB), then optional extra data (PlayChoice INST-ROM and PROM, or miscellaneous ROM in NES 2.0). Dumps carry no checksum; identification of a game is by hashing PRG+CHR (a database such as the one Mesen ships does this).
Header bytes
| Byte | iNES | NES 2.0 |
|---|---|---|
| 0-3 | 4E 45 53 1A |
same |
| 4 | PRG ROM size in 16 KiB (0 = 256 units in Mesen) | low 8 bits of PRG size |
| 5 | CHR ROM size in 8 KiB (0 = CHR RAM) | low 8 bits of CHR size |
| 6 | bit 0 vertical mirroring, bit 1 battery, bit 2 trainer, bit 3 four-screen, bits 4-7 mapper low nibble | same |
| 7 | bit 0 VS System, bit 1 PlayChoice-10, bits 2-3 = 00 for iNES, bits 4-7 mapper bits 4-7 | bits 2-3 = 10 marks NES 2.0; bits 0-1 console type |
| 8 | PRG RAM size in 8 KiB (rarely used) | bits 0-3 mapper bits 8-11, bits 4-7 submapper |
| 9 | bit 0 PAL | bits 0-3 PRG size high nibble, bits 4-7 CHR size high nibble |
| 10 | unofficial | PRG RAM (bits 0-3) and PRG NVRAM (4-7) as shift counts |
| 11 | unused | CHR RAM (0-3) and CHR NVRAM (4-7) as shift counts |
| 12 | unused | bits 0-1 timing: 0 NTSC, 1 PAL, 2 multi-region, 3 Dendy |
| 13 | unused | VS PPU type (low nibble) and VS hardware (high nibble), or extended console type |
| 14 | unused | miscellaneous ROM count |
| 15 | unused | default expansion device |
Identification
- Version:
(byte7 & 0x0C) == 0x08is NES 2.0,== 0is iNES, anything else is treated as an old iNES whose bytes 7-15 are junk (old tools wrote "DiskDude!" there), so only the low mapper nibble is trusted. - Mapper number: iNES
(b7 & 0xF0) | (b6 >> 4); NES 2.0 adds(b8 & 0x0F) << 8(12 bits, 0-4095). The mapper selects the bank-switching hardware, see the emulator's mapper list for behaviour. - NES 2.0 sizes: RAM fields (byte 10 and 11 nibbles) are shift counts, size =
64 << nbytes (0 = none); Mesen writes it as128 * 2^(n-1), the same. An exponent-multiplier form is used for a PRG or CHR size when the high nibble is 0xF: size =2^(value >> 2) * ((value & 3) * 2 + 1). - Related containers: FDS disks start with
FDS\x1A(headerless images exist), NSF music files withNESM\x1A, UNIF withUNIF. - Sizes in Mesen2 NesHeader.cpp (lines 111-139): NES 2.0 PRG size is
((byte9 & 0x0F) << 8 | byte4) * 16 KiBand CHR is((byte9 & 0xF0) << 4 | byte5) * 8 KiB; when the high nibble is 0xF the byte is insteadexponent << 2 | multiplierand the size is(multiplier * 2 + 1) << exponentbytes (exponent capped at 60). In iNES a PRG count of 0 means 256 units; a CHR count of 0 means CHR RAM. - Mapper in an old iNES header (byte 7 bits 2-3 neither 00 nor 10) uses only
byte6 >> 4(NesHeader.cpp lines 6-17). - NES 2.0 console type is
byte7 & 3: 0 NES/Famicom, 1 VS System, 2 PlayChoice-10, 3 extended console type inbyte13 & 0x0F(1 VS, 2 PlayChoice, 4 EPSM expansion audio, 0xC Famicom Network System). Timing isbyte12 & 3(0 NTSC, 1 PAL, 2 multi-region, which Mesen2 runs as NTSC, 3 Dendy). In plain iNES only byte 9 bit 0 (PAL) is read. - The submapper is
byte8 >> 4. VS PPU model isbyte13 & 0x0F(0 2C03, 2-5 2C04A-D, 8-12 2C05A-E) and VS hardware typebyte13 >> 4. The default input device is byte 15. - Trainer: if byte6 bit 2 is set, 512 bytes follow the header and are read before PRG data (Mesen2 iNesLoader.cpp lines 47-58, commented as loaded at $7000-$71FF); a file too short for it is rejected. Then PRG, then CHR; a file shorter than PRG+CHR is rejected, a longer one only warns.
- A file whose first bytes match no known magic is accepted as a headerless iNES dump only if its CRC32 is in the game database (RomLoader.cpp lines 63-70).
- Other formats recognised by the same loader: Format:FDS disk image, Format:UNIF ROM image, NSF (
NESM1A), NSFE, and Study Box (STBX).
Code & repositories
- https://github.com/SourMesen/Mesen2 @
b9fa69ddc6d0a331fb103fdb5eef6904305703c2· license: GPL-3.0-only (declared by the contributor for the files used; GitHub reports GPL-3.0 for the repository)
Multi-system emulator with a debugger: iNES/NES 2.0 header parsing (Core/NES/NesHeader.cpp), SNES header detection (Core/SNES/BaseCartridge.cpp), Game Boy, GBA, PC Engine, SMS, WonderSwan
Tested on: source read, not run: source read, not run · checked 2026-10-18; archived; last activity 2026-06-04; Note: the latest release ships binaries; the wiki links only the source, never the binaries
Pitfalls
- A header with the mapper high nibble polluted by trailing garbage is the usual cause of a wrong mapper: check bytes 12-15 are zero.
- The mirroring bit is ignored by mappers that control mirroring themselves.
- Unverified: the exact PlayChoice trailing-data layout is not covered here.
Evidence and references
Read from Mesen2 (GPL-3.0) Core/NES/NesHeader.cpp and NesHeader.h; see Platform:Nintendo Entertainment System.