Region file format

The Region file format is the binary file format for storing Java Edition chunks from Beta 1.3 to release 1.2. Each file stores a group of 32×32 chunks called a region. The format took the place of the Alpha level format, which had been in use since the Infdev development phase, where chunks were stored in individual files on the file system. The file does not begin with a magic number, unlike other file formats, and begins directly with the header. The format has been superseded by the Anvil file format; however, the Anvil file format made changes only to the chunk format and changed the region file extensions from ".mcr" to ".mca".

The system is based on McRegion, a mod by Scaevolus, also known for his development of the Optimine project. The McRegion format was adopted nearly unchanged, except for the addition of a table of chunk update timestamps. JahKob has claimed that this format is up to 7 times faster than the previous system. The difference in a world's total file size between the Region file format and the Alpha level format is negligible.

Location
Region files are located in a subfolder of the world directory, "region", and have names in the form, where x and z are the region's coordinates.

The coordinates for the region a chunk belongs to can be found by taking the floor of dividing the chunk coordinates by 32, or by bit shifting 5 bits to the right. For example, a chunk at (30, -3) would be in the region (0, -1), and one at (1500, -600) would be at (46, -19).

Header
Region files begin with an 8KiB header, split into two 4KiB tables. The first containing the offsets of chunks in the region file itself, the second providing timestamps for the last updates of those chunks.

The offset of a chunk [x, z] (in chunk coordinates) in the first table can be found by using this formula: 4 * ((x mod 32) + (z mod 32) * 32). When using certain languages (such as Java/C/C++), the values of x mod 32 and z mod 32 can be negative. To prevent this, use the AND operator (&) instead of modulo: 4 * ((x & 31) + (z & 31) * 32). Its timestamp can be found 4096 bytes later in the file.

Chunk location
Location information for a chunk consists of four bytes split into two fields: the first three bytes are a (big-endian) offset in 4KiB sectors from the start of the file, and a remaining byte that gives the length of the chunk (also in 4KiB sectors, rounded up). Chunks are always less than 1MiB in size. If a chunk isn't present in the region file (e.g. because it hasn't been generated or migrated yet), both fields are zero.

A chunk with an offset of 2 begins right after the timestamps table.

Chunk timestamps
The entries in the timestamp table are individual four-byte big-endian integers, representing the last modification time of a chunk in epoch seconds.

Payload
Chunk data begins with a (big-endian) four-byte length field that indicates the exact length of the remaining chunk data in bytes. The following byte indicates the compression scheme used for chunk data, and the remaining (length-1) bytes are the compressed chunk data.

Minecraft always pads the last chunk's data to be a multiple-of-4096B in length (so that the entire file has a size that is a multiple of 4KiB). Minecraft does not accept files in which the last chunk is not padded. Note that this padding is not included in the length field.

There are currently three defined compression schemes:

The uncompressed data is in NBT format and follows the information detailed on the chunk format article; if compressed with compression scheme 1, the compressed data would be the same as the on-disk content of an Alpha chunk file. Note that chunks are always saved using compression scheme 2 by the official client.

If the value of compression scheme increases by 128, the compressed data is saved in a file called, where x and z are the chunk's coordinates, instead of the usual position.

Migration and level.dat
Beta 1.3 converts any "old" chunks into region files before loading the world, rather than incrementally as they are loaded during play. As part of the conversion,  is updated with TAG_Int("version") (note case) set to 19132. Beta 1.3 also introduces a new level name field, TAG_String("LevelName"). There's also introduced new TAG_Byte("Sleeping") in player TAG_Compounds - level.dat in singleplayer, [player name].dat in multiplayer that indicates whether is player in the bed. It has value 1(true) or 0(false). For the beta 1.8, TAG_Int("GameType") was added. In beta 1.9, TAG_byte("hardcore") was added.

The format of level.dat is otherwise unchanged.

Software
The community has developed programs to work with region files:

Spielstand-Speicherung/Region Format Format de fichier Région Regionファイルフォーマット Regio bestandsformaat 区域文件格式