RAR (Roshal Archive)
| Full name | Roshal Archive |
|---|---|
| Extensions | .rar; volumes .part1.rar, .part2.rar (RAR5 and newer RAR4) or .rar, .r00, .r01 (old naming); .rev recovery volumes; .cbr (comic book) |
| MIME type | application/vnd.rar (registered), application/x-rar-compressed (common) |
| Type | archive, lossless compression, optional encryption |
| Starts with | RAR5 52 61 72 21 1A 07 01 00 (Rar!\x1A\x07\x01\x00); RAR4 52 61 72 21 1A 07 00 (Rar!\x1A\x07\x00) |
| Specification | RAR 5.0 archive format (RARLAB technical note) |
| Maintained by | RARLAB (Alexander Roshal), the makers of WinRAR |
| License | proprietary; free UnRAR source for extraction, creating RAR files needs WinRAR or RAR |
RAR is an archive format: it packs many files and folders into one file, compresses them, and can encrypt them with a password. It’s common for software and media downloads, comic books (.cbr) and backups. Its strengths are a good compression ratio, archives split into volumes, and a recovery record that repairs damaged archives.
RAR is proprietary. Only WinRAR and the rar command line tool from RARLAB create RAR files. Extraction is open: RARLAB publishes the UnRAR source code, which can be used in any program that extracts RAR, but not to build a RAR-compatible archiver. All open-source libraries on this site only read RAR.
When to use RAR#
- Use to extract archives you received: all major platforms have free tools that open RAR.
- Use when you already own WinRAR and need volumes plus a recovery record (to survive damaged downloads or disks) in one archive.
- Avoid for archives you create for other people: ZIP opens everywhere without extra software, 7z compresses as well or better with an open format.
- Avoid in programs that must create archives: no open-source library writes RAR. Use ZIP, 7z or TAR with gzip, xz or zstd.
RAR4 vs RAR5#
RAR has 2 incompatible archive formats. Both use the .rar extension; the signature tells them apart.
| RAR4 (RAR 2.9 / 3.x / 4.x format) | RAR5 (RAR 5.0 format, default since WinRAR 5.0) | |
|---|---|---|
| Signature | 52 61 72 21 1A 07 00 (7 bytes) |
52 61 72 21 1A 07 01 00 (8 bytes) |
| Header integers | fixed size, little-endian | variable-length integers (vint) |
| Header checksum | low 16 bits of CRC-32 | full CRC-32 |
| File checksum | CRC-32 | CRC-32 or BLAKE2sp |
| Compression | LZSS + Huffman, PPMd, RarVM filters | LZSS + Huffman, fixed filters (delta, x86, ARM) |
| Dictionary | up to 4 MB | up to 1 GB; up to 64 GB with RAR 7.0 |
| Encryption | AES-128, SHA-1 based key derivation | AES-256, PBKDF2-HMAC-SHA256 |
| File names | OEM / Unicode | UTF-8 |
| Recovery | recovery record, .rev volumes |
Reed-Solomon recovery record, .rev volumes |
| Readers | every RAR tool | most current tools; very old ones fail |
Current WinRAR creates RAR5 by default and creates RAR4 only on request. Archives with a dictionary larger than 4 GB (a RAR 7.0 option) need UnRAR 7.0 or newer to extract.
File structure#
A RAR file is a signature followed by a sequence of blocks (headers). Each header may be followed by a data area, such as the compressed bytes of a file. An optional SFX module (an executable that extracts the archive) can come before the signature; readers search for the signature in the first megabyte or so.
RAR5 layout#
[SFX module] optional, self-extracting archives
signature 52 61 72 21 1A 07 01 00
[archive encryption header] only when file names are encrypted
main archive header
file header + data one per file (and per volume part)
service header + data optional: comment (CMT), NTFS streams (STM), quick open (QO)
[recovery record] service header named RR
end of archive header
Every RAR5 header starts with the same fields. Sizes and most numbers are vint: variable-length integers with 7 bits per byte, low bits first, and the high bit set on every byte except the last.
| Field | Size | Description |
|---|---|---|
| Header CRC32 | 4 bytes | CRC-32 of everything from Header size to the end of the header |
| Header size | vint | size of the header after this field (max 2 MB) |
| Header type | vint | 1 main archive, 2 file, 3 service, 4 archive encryption, 5 end of archive |
| Header flags | vint | 0x0001 extra area present, 0x0002 data area present, 0x0004 skip if unknown, 0x0008 / 0x0010 data continues from previous / in next volume |
| Extra area size | vint | if flag 0x0001 |
| Data size | vint | if flag 0x0002; for a file, the packed size |
The start of a typical RAR5 file:
52 61 72 21 1A 07 01 00 signature "Rar!\x1A\x07\x01\x00"
xx xx xx xx header CRC32
0A header size (vint): 10 bytes follow
01 header type 1: main archive header
05 header flags: extra area present, skip if unknown
06 extra area size: 6
00 archive flags: not a volume, not solid
... extra area (locator record), then file headers (type 2)
Main archive header flags: 0x0001 volume, 0x0002 volume number present (all volumes except the first), 0x0004 solid, 0x0008 recovery record present, 0x0010 locked (can’t be modified).
File header fields after the common part: file flags (directory, mtime present, CRC32 present, unknown size), unpacked size, attributes, modification time, CRC-32, compression info, host OS (0 Windows, 1 Unix), and the UTF-8 name. The compression info vint holds the method in bits 7-9 (0 = store, 1-5 = fastest to best) and the dictionary size in bits 10-14. Extra records in a file header add encryption parameters, a BLAKE2sp hash, high-precision times, symlinks and hard links, and Unix owner names.
RAR4 layout#
RAR4 uses fixed-size fields in little-endian order. Every block starts with a 7-byte header:
| Field | Size | Description |
|---|---|---|
| HEAD_CRC | 2 bytes | low 16 bits of the CRC-32 of the header |
| HEAD_TYPE | 1 byte | 0x72 marker, 0x73 archive header, 0x74 file, 0x7A service (comment, recovery record), 0x7B end of archive |
| HEAD_FLAGS | 2 bytes | block flags; 0x8000 means an ADD_SIZE field and a data area follow |
| HEAD_SIZE | 2 bytes | size of the header including these 7 bytes |
| ADD_SIZE | 4 bytes | size of the data area, if flag 0x8000 |
The 7-byte signature is itself a marker block (0x72). A file block (0x74) stores packed size, unpacked size, host OS, CRC-32, DOS date and time, the version needed to extract, the method (0x30 store to 0x35 best), name length, attributes, the name, and an 8-byte salt for encrypted files. Files over 4 GB add 32-bit high parts of the sizes.
Solid archives#
In a solid archive the files are compressed as one continuous stream, so similar files share the dictionary and compress much better. The cost: extracting one file means decompressing all files before it, and damage in one place breaks every file after it. Libraries that extract solid archives are much faster when they process entries in order.
Volumes#
A large archive can be split into volumes of a fixed size. RAR5 archives and most newer RAR4 archives name them name.part1.rar, name.part2.rar; old RAR4 archives use name.rar, name.r00, name.r01. Open the first volume to extract: tools find the next ones by name. A file that spans volumes has a file header in each volume with the “continues” flags set.
Encryption#
RAR encrypts file data, and optionally all headers too (WinRAR’s “Encrypt file names”). Without the password, an archive with encrypted headers doesn’t even show its file list. RAR5 uses AES-256 in CBC mode with a key from PBKDF2-HMAC-SHA256 (215 iterations by default), and stores a check value so a wrong password is detected before extraction. RAR4 uses AES-128.
Recovery record and recovery volumes#
A recovery record is extra redundancy data (a percentage of the archive size) stored inside the archive. WinRAR’s “Repair” command uses it to fix damaged sectors. Recovery volumes (.rev) do the same for whole missing volumes. Extraction libraries ignore both.
Specifications and documentation#
- RAR 5.0 archive format (RARLAB): the official description of RAR5 headers, without the compression algorithm
- UnRAR source code (RARLAB): the reference decompressor for RAR4 and RAR5, the only complete description of the compression
- UnRAR 7.0 implementation notes: what changed for RAR 7.0 large dictionaries
- RAR 4 format description: RAR4 block layout, from the bitjs project
- application/vnd.rar media type registration (IANA)
- RAR on Wikipedia
Software that opens RAR files#
| Software | Windows | macOS | Linux | Web | Can | Notes |
|---|---|---|---|---|---|---|
| SumatraPDF | ✓ | view | free, open source; shows images inside .rar and .cbr comic books, doesn't extract other files | |||
| WinRAR | ✓ | view, edit, create, convert | commercial (trial); the only GUI that creates RAR | |||
| RAR command line | ✓ | ✓ | ✓ | create, edit | commercial, rar for macOS, Linux and FreeBSD; unrar is free | |
| File Explorer | ✓ | view | built into Windows 11 (23H2 and newer), extract only, no encrypted archives | |||
| 7-Zip | ✓ | ✓ | ✓ | view | free, open source; extracts RAR4 and RAR5 (command line 7zz on macOS and Linux) | |
| NanaZip | ✓ | view | free, open source 7-Zip fork for Windows 11 | |||
| PeaZip | ✓ | ✓ | ✓ | view | free, open source | |
| Bandizip | ✓ | ✓ | view | free edition, extracts RAR5 | ||
| The Unarchiver | ✓ | view | free; unar command line also for Linux | |||
| Keka | ✓ | view | free (paid in the Mac App Store) | |||
| Ark | ✓ | view | free, open source, KDE; uses unrar or unar | |||
| File Roller | ✓ | view | free, open source, GNOME Archive Manager | |||
| RAR for Android | view, create | by RARLAB, free with ads. Also on Android | ||||
| ZArchiver | view | free. Also on Android | ||||
| ezyZip | ✓ | view | extracts in the browser |
Libraries#
Open-source libraries extract RAR files; none create them. See all RAR libraries for a comparison.
| C/C++ | libarchive, UnRAR library |
|---|---|
| C# | SharpCompress |
| Java | junrar |
| Go | rardecode |
| Python | rarfile |
| Ruby | ffi-libarchive |
| Rust | unrar |
| PHP | rar extension |