File Signatures & Magic Bytes Guide
When you double-click a file, your operating system usually looks at the letters after the final dot—such as .pdf, .jpg or .docx—to decide which app should open it. That extension is only part of the filename. The actual format is recorded inside the file’s bytes.
Many formats begin with a fixed sequence of bytes called a file signature or magic bytes. Inspecting those bytes is the fastest way to find out what an unfamiliar or mislabelled file really is.
You can inspect a file’s signature and first 64 bytes locally in your browser with the free File Sniff file type checker.
How file signatures work
A file signature is a short marker placed at a predictable position near the beginning of a file so software can recognise the format immediately:
- Fixed start-of-file signatures appear at byte offset
0. For example, every standard PNG image starts with the eight bytes89 50 4E 47 0D 0A 1A 0A, where50 4E 47spellsPNGin ASCII. - Offset signatures appear after a length field or outer header. ISO Base Media files (such as MP4 videos, QuickTime
.movmovies, M4A audio, HEIC photos and AVIF images) begin with a 4-byte box size followed by66 74 79 70(ftyp) at byte offset4, and then a brand code such asisom,qt,heicoravif. - RIFF containers start with
52 49 46 46(RIFF), a 4-byte file size, and then a 4-byte format tag at byte offset8:WEBPfor WebP images,WAVEfor WAV audio, orAVIfor AVI video.
Common file signatures at a glance
| Format | Hex signature | ASCII / marker | Offset |
|---|---|---|---|
PNG image (.png) | 89 50 4E 47 0D 0A 1A 0A | .PNG.... | 0 |
JPEG image (.jpg, .jpeg) | FF D8 FF | (binary) | 0 |
GIF image (.gif) | 47 49 46 38 37 61 / 47 49 46 38 39 61 | GIF87a / GIF89a | 0 |
WebP image (.webp) | 52 49 46 46 … 57 45 42 50 | RIFF…WEBP | 0 & 8 |
PDF document (.pdf) | 25 50 44 46 2D | %PDF- | 0 |
ZIP / OOXML container (.zip, .docx, .xlsx, .pptx) | 50 4B 03 04 | PK.. | 0 |
HEIC / MP4 / MOV (ftyp box) | … 66 74 79 70 | …ftyp + brand | 4 |
Legacy Office / Outlook (.doc, .xls, .ppt, .msg) | D0 CF 11 E0 A1 B1 1A E1 | (OLE Compound Document) | 0 |
Outlook TNEF (winmail.dat, .dat) | 78 9F 3E 22 | x.>" | 0 |
7-Zip archive (.7z) | 37 7A BC AF 27 1C | 7z.... | 0 |
RAR archive (.rar) | 52 61 72 21 1A 07 | Rar!.. | 0 |
Gzip archive (.gz, .tgz) | 1F 8B 08 | (binary) | 0 |
SQLite database (.sqlite, .db) | 53 51 4C 69 74 65 20 66 6F 72 6D 61 74 20 33 00 | SQLite format 3\0 | 0 |
Windows PE executable (.exe, .dll) | 4D 5A … 50 45 00 00 | MZ … PE\0\0 | 0 & e_lfanew |
| Mach-O executable (macOS / iOS) | CF FA ED FE / FE ED FA CF | (binary) | 0 |
WebAssembly binary (.wasm) | 00 61 73 6D 01 00 00 00 | \0asm.... | 0 |
When the signature only shows a container
Some magic bytes identify an outer packaging format rather than the specific document type inside:
- ZIP-based document formats: Microsoft Word (
.docx), Excel (.xlsx), PowerPoint (.pptx), EPUB books (.epub), Android packages (.apk) and OpenDocument files all start with50 4B 03 04(PK\x03\x04). To tell a Word document apart from an ordinary ZIP archive without decompressing the file, a checker inspects the ZIP central directory at the end of the file for entries such as[Content_Types].xmlandword/document.xml,xl/workbook.xmlorppt/presentation.xml. - OLE Compound Documents: Older Office files (
.doc,.xls,.ppt) and Outlook.msgemails share the same eight-byte OLE header (D0 CF 11 E0 A1 B1 1A E1). Distinguishing them requires reading the internal OLE directory streams. - Plain text formats: Files such as
.txt,.csv,.json,.mdor scripts do not have a mandatory binary header. A careful checker validates UTF-8 text and syntax (such as complete JSON or a#!shebang) rather than guessing from a filename.
What magic bytes cannot prove
File signatures are designed for format recognition, not security verification:
- A valid header does not prove the rest of the file is intact. A truncated download can still have a valid header at the start while missing its final bytes.
- Signatures can be forged or combined. Because some parsers scan from the start of a file and others scan from the end (like ZIP), a crafted file can contain more than one marker.
- Identification is not a malware scan. Knowing that an attachment is a Windows executable (
MZ/PE\0\0) or a mismatched video helps you avoid opening the wrong thing, but a matching extension never proves a file is safe.
Try inspecting a file with the free file type checker, learn how to identify an unknown file, or read what a file extension mismatch means.