Format:Bethesda archive (BSA and BA2)
| Versions | Morrowind; BSA 0x67, 0x68, 0x69; BA2 1, 2, 3, 7, 8 |
|---|---|
| Magic | 42 53 41 00 (BSA), 42 54 44 58 (BTDX), 00 01 00 00 (Morrowind) |
| Extensions | .bsa, .ba2 |
| Endianness | little |
| On this wiki | Facts · Code · Notes · Topics |
Archive formats of Bethesda's Gamebryo and Creation Engine games: .bsa (magic BSA\0, versions 0x67/0x68/0x69 for Oblivion, Fallout 3/New Vegas/Skyrim, Skyrim SE; Morrowind uses a different header) and .ba2 (magic BTDX with GNRL or DX10 type, versions 1, 2, 3, 7, 8 for Fallout 4 and Starfield). Files are looked up by name hash; names are optional.
Identification
First u32: 42 53 41 00 ("BSA\0") for Oblivion, Fallout 3, New Vegas, Skyrim LE/SE; 42 54 44 58 ("BTDX") for Fallout 4 and Starfield .ba2; 00 01 00 00 for Morrowind .bsa. All integers little-endian. Source for everything below: TES5Edit/xEdit Core/wbBSArchive.pas (MPL-2.0), written for its BSArch tool.
Morrowind
Header 12 bytes: magic 00 01 00 00, HashOffset u32, FileCount u32. Then FileCount records of (size u32, offset u32), name offsets (u32 each), NUL-terminated names, FileCount 64-bit name hashes. File offsets are relative to the end of the hash table.
BSA, Oblivion to Skyrim SE (magic BSA, version u32)
Version 0x67 = Oblivion, 0x68 = Fallout 3, New Vegas and Skyrim LE, 0x69 = Skyrim SE/AE. Header is 36 bytes: magic, version, FoldersOffset, ArchiveFlags, FolderCount, FileCount, FolderNamesLength, FileNamesLength, FileFlags (all u32). FoldersOffset is 36.
Folder records: hash u64, file count u32, offset u32 (16 bytes; Skyrim SE has a u32 padding after the count and another after the offset: 24 bytes). Then for every folder, in order: a length-prefixed folder name (1 length byte, name with NUL), followed by its file records: name hash u64, size u32, offset u32 (16 bytes). After all folders come the NUL-terminated file names in the same order.
Archive flags: 0x1 directory names present, 0x2 file names present, 0x4 compressed by default, 0x8 retain directory names, 0x10 retain file names, 0x20 retain file name offsets, 0x40 Xbox 360 archive, 0x80 retain strings during startup, 0x100 embedded file names (file data starts with the full path), 0x200 XMem codec. File flags (content types): 0x1 meshes, 0x2 textures, 0x4 menus, 0x8 sounds, 0x10 voices, 0x20 shaders, 0x40 trees, 0x80 fonts, 0x100 misc.
A file is compressed when ArchiveFlags bit 0x4 XOR bit 30 (0x40000000) of the file record's size field is set; the real size is the field without bit 30. Compression: zlib for versions 0x67 and 0x68, LZ4 frame format for 0x69 (Format:LZ4). A compressed file's data starts with a u32 uncompressed size, then the compressed stream (Ryan-rsm-McKenzie/bsa src/bsa/tes4.cpp writes it at line 1240). With the embedded-file-names flag (0x100, honoured only for versions above 103, so not Oblivion) the data starts with a length-prefixed (1 byte) full path dir\name, which comes before the size prefix and is counted in the record's size (tes4.cpp lines 1039-1055). When a file name table exists its name wins over the embedded name.
BA2 (magic BTDX)
Header: magic BTDX, version u32, type u32 (GNRL general files or DX10 textures), FileCount u32, NameTableOffset u64 (24 bytes). Version 2 and 3 (Starfield) add a u64 that is always 1; version 3 adds CompressionMethod u32 (0 = zlib, 3 = LZ4 block); versions 1 (Fallout 4), 7 and 8 (Fallout 4 next-gen update) otherwise share the layout. Files are zlib-compressed in Fallout 4 (Library:Zlib).
GNRL file record (36 bytes): name hash u32, extension (4 ASCII chars), directory hash u32, a byte that is always 0, chunk count byte (always 1), chunk header size u16 (16), data offset u64, packed size u32 (0 when stored), unpacked size u32, then the filler 0xBAADF00D.
DX10 file record: name hash, extension ("dds"), directory hash, a zero byte, chunk count (up to 4, hardcoded in the engine), header size u16 (24), then Height u16, Width u16, mip count byte, DXGI format byte, flags byte (bit 0 = cube map), tile mode byte, followed by chunk records of 24 bytes: offset u64, packed size u32, size u32, StartMip u16, EndMip u16, BAADF00D. The file data is the texture's pixel data without a DDS header; the loader rebuilds the DDS header from these fields.
Name table at NameTableOffset: for every file in order a u16 length followed by that many ASCII bytes, no terminator (Bethesda's Archive2 writes forward slashes). The table may be missing; tools then name files <dirhash>\<namehash>.<ext>.
Notes
- Names are looked up by hash, so a modded archive without names still works in game; tools that need names read them from the name table.
- Mods can load loose files before archives; see the plugin format Format:Bethesda plugin (ESP, ESM, ESL).
- Game executables identify archive generation by the version u32; an unknown value is an error in xEdit ('Unknown archive version').
Name hashes
Files and folders are found by hash, so a tool that writes archives must reproduce them. Paths are first normalized (lowercase, / to \, leading and trailing backslashes removed; an empty or 260+ character path becomes .; detail::normalize_path in src/bsa/detail/common.cpp, the lowercase mapping itself not read here: Unverified). All from Ryan-rsm-McKenzie/bsa (MIT).
Oblivion to Skyrim SE (tes4). The 64-bit hash is stored little-endian with byte fields in this order: last char, second-to-last char, length, first char, then a u32 crc. For a folder path: first/last/last2 characters and length (u8) are taken from the whole path, crc = CRC of characters 1 to length-3 (only if length > 3). The CRC is not CRC-32: crc = byte + crc * 0x1003F over the bytes, starting from 0. For a file: the stem (name without extension) is hashed like a folder; then the same multiply-by-0x1003F hash of the extension (with dot) is added to the crc, and for the extensions in the list "", .nif, .kf, .dds, .wav, .adp (index i) the fields are adjusted: first += 32*(i & 0xFC), last += (i & 0xFE) << 6, last2 += i << 7. A file with an empty stem, a stem of 260+ chars or an extension of 16+ chars gets hash 0 (src/bsa/tes4.cpp lines 398-530).
Fallout 4 / Starfield BA2 (fo4). Three u32 values: directory = CRC-32 (the standard reflected 0xEDB88320 table, start 0 without the usual final inversion as written in the source) of the directory path, file = CRC-32 of the stem, extension = up to the first 4 characters of the extension packed little-endian (src/bsa/fo4.cpp lines 245-368).
Morrowind (tes3). Two u32 values lo/hi over the whole normalized path: the first half of the characters is XORed into lo, each byte shifted by (i mod 4) * 8; the second half is folded into hi with hi = rotr(hi ^ rot, rot) where rot is the byte shifted by ((i - midpoint) mod 4) * 8 (src/bsa/tes3.cpp lines 133-154).
Code & repositories
- https://github.com/TES5Edit/TES5Edit @
9fb016884bec138ea6c7b872cec831537d464c3e· license: MPL-2.0
xEdit: plugin editor and BSArch archive tool for Bethesda games; record, group, BSA and BA2 structures in Core/
Tested on: source read, not run: source read, not run · checked 2026-10-18; last activity 2026-10-18; Note: the latest release ships binaries; the wiki links only the source, never the binaries - https://github.com/Ryan-rsm-McKenzie/bsa @
2c7280d5c9199f90b7338d70425181029c9bb2f2· license: MIT
C++ library to read and write Morrowind (tes3), Oblivion to Skyrim SE (tes4) BSA and Fallout 4/Starfield (fo4) BA2 archives, including the name hash functions
Tested on: source read, not run · checked 2026-10-19; last activity 2025-02-08
Open questions
- Verify the hash functions against a real archive: the algorithms above come from reading source only.