Skip to content
Buy me a coffee

Magic numbers

tag: file-typestag: beginners

The extension (.pdf, .jpg) is just part of the file name, and anyone can change it. Windows also hides known extensions by default, so invoice.pdf.exe shows up as invoice.pdf.

The bytes are in hex (see Reading hex). The text column shows the same bytes as characters, where they’re readable.

Format First bytes As text
Windows program (PE: .exe, .dll) 4D 5A MZ
Linux program (ELF) 7F 45 4C 46 .ELF
macOS program (Mach-O, 64-bit) CF FA ED FE
PDF 25 50 44 46 2D %PDF-
ZIP, and everything built on it (.docx, .xlsx, .pptx, .jar, .apk) 50 4B 03 04 PK..
Older Office files (.doc, .xls, .msi) D0 CF 11 E0 A1 B1 1A E1
RTF 7B 5C 72 74 66 {\rtf
PNG 89 50 4E 47 0D 0A 1A 0A .PNG....
JPEG FF D8 FF
GIF 47 49 46 38 GIF8
RAR 52 61 72 21 1A 07 Rar!..
7-Zip 37 7A BC AF 27 1C 7z....
gzip 1F 8B
Windows shortcut (.lnk) 4C 00 00 00 L...
ISO disk image 43 44 30 30 31 at offset 0x8001 CD001

Plain-text formats have no signature: scripts (.js, .vbs, .ps1, .bat, .hta), HTML, CSV. They’re identified by what’s inside them, so a script can be called anything. Read it in a text editor (never by double-clicking it) and look at the first lines.

  1. Copy a PNG picture of your own and rename the copy to picture.txt.
  2. Look at its first bytes: xxd picture.txt | head -1 (macOS, Linux) or Format-Hex picture.txt | Select-Object -First 1 (PowerShell).
  3. It still starts with 89 50 4E 47. The name changed; the file didn’t.

Confirming a file type: the tools that read these signatures for you.

One Reverse Look

"A little learning is a dangerous thing." ~ A. Pope

One Reverse Look · Made with ❤ · Your friendly knowledge seeker