Knowledge Base

What Is Bit Flag?

bit-flag

Bit Flag, also known as a bit field, is metadata you can find in several kinds of files. Find out what it means, where it comes from and what it says about your file.

A bit flag packs several yes-or-no answers into a single number. Each binary digit in that number is a separate switch: on or off, set or not set. It is a compact way for a program to record a handful of small facts in the space of one value.

Where the value comes from

Bit flags, also called bit fields, come from programming. In languages such as C and C++ they let a developer store many boolean values inside a single byte or a set of bytes, with each bit or group of bits addressed on its own. File formats borrow the same idea to record options about their contents.

In a metadata report you are most likely to meet a bit flag on a ZIP archive, and on the many everyday formats that are ZIP containers underneath: DOCX, XLSX and PPTX documents, ODT files and EPUB e-books. The ZIP format gives every item inside the archive a general purpose bit flag, and the program that created the archive sets it. Nobody types this value in.

Reading the value

The flag is usually shown in hexadecimal, a number system that counts in sixteens and is written with a leading 0x. A value of 0x0 means no switches are set, which is the ordinary case. Values such as 0x2 or 0x808 mean one or more bits are on, and you read them by converting the number to binary and looking at each position.

Three of the ZIP switches are worth knowing:

  • the first bit marks the item as encrypted, meaning it needs a password
  • the fourth bit says the item's size and checksum were written after the data rather than before it, which is what happens when an archive is produced on the fly
  • the twelfth bit says the item's name is stored as UTF-8, the character encoding that can represent accents, non-Latin scripts and emoji

Why it matters for your file

The flag explains behavior you would otherwise find mysterious. It is where a password-protected document announces that it is locked, before any program asks you for the password. It is why some tools cannot tell you how large an item inside an archive is until they have unpacked it. And it is why file names with accents or Chinese characters come out perfectly in one unpacking program and as nonsense in another: one of them respects that UTF-8 switch and the other assumes an older encoding.

What the field does not do is describe quality, and it holds no personal information. It is a technical note about how the file was written, useful when something will not open and you want to know why.