Base64 file signatures.
Most file formats begin with a fixed sequence of “magic bytes”. Encode those bytes and you get a fixed Base64 prefix, so you can tell a PDF from a PNG from a Windows executable without decoding anything. The table below covers more than 60 formats.
Updated 9 November 2026
Look at the first few characters. JVBERi0 is a PDF, iVBORw0KGgo a PNG, /9j/ a JPEG, R0lGOD a GIF, UklGR a RIFF file (WebP, WAV, AVI), UEsDB a zip (including .docx, .xlsx, .jar, .apk), H4sI gzip, TVqQ a Windows .exe, and eyJ JSON (every JWT starts with it). Find any other format in the table below.
How it works
Base64 turns every 3 bytes into 4 characters, always starting from the first byte. So the first 3 bytes of a file always decide the first 4 characters, the next 3 decide the next 4, and so on. A PNG file always begins with the 8 bytes 89 50 4E 47 0D 0A 1A 0A, so its Base64 always begins with iVBORw0KGgo, whatever the image shows.
Because 8 bytes don't divide evenly into 6-bit characters, only the characters built entirely from signature bytes are fixed. The table shows exactly those. (PNG's 8 bytes fix 10 characters; the 11th mixes in the next byte, which in a PNG is always 0, so iVBORw0KGgo is reliable in practice.)
Signatures at an offset
Some formats put their signature a few bytes in. RIFF files (WebP, WAV, AVI) start with RIFF, then a 4-byte file size, then the real type. ISO media files (MP4, MOV, HEIC, AVIF) start with a 4-byte box size and then ftyp. The size bytes change from file to file, so the characters covering them change too. For these, the table gives the fixed characters and the position where they appear, counting from 1. For example, a WebP file has UklGR at the start and RUJQ at character 13.
The table
Base64 prefixes are computed from the magic bytes shown and checked against sample files. Text formats (SVG, HTML, JSON, scripts) have no true magic number, so their prefixes only hold when the file starts exactly as shown.
| Format | Extensions | Magic bytes (hex) | Base64 starts with | Notes |
|---|---|---|---|---|
25 50 44 46 2D | JVBERi0 | Followed by the version, e.g. %PDF-1.7 or %PDF-2.0. Both give JVBERi0. | ||
| Zip and zip-based formats | .zip .docx .xlsx .pptx .odt .epub .jar .apk | 50 4B 03 04 | UEsDB | Office Open XML, OpenDocument, EPUB, Java and Android packages are all zip files. |
| Zip (empty archive) | .zip | 50 4B 05 06 | UEsFB | |
| Legacy Microsoft Office (OLE2) | .doc .xls .ppt .msg .msi | D0 CF 11 E0 A1 B1 1A E1 | 0M8R4KGxGu | Compound File Binary format. |
| Rich Text Format | .rtf | 7B 5C 72 74 66 | e1xydG | |
| PostScript | .ps .eps | 25 21 50 53 | JSFQU | |
| PNG | .png | 89 50 4E 47 0D 0A 1A 0A | iVBORw0KGgo | Full 8-byte signature; the next byte is always 00. |
| JPEG | .jpg .jpeg | FF D8 FF | /9j/ | URL-safe encoding turns this into _9j_. |
| GIF (89a) | .gif | 47 49 46 38 39 61 | R0lGODlh | |
| GIF (87a) | .gif | 47 49 46 38 37 61 | R0lGODdh | |
| WebP | .webp | 52 49 46 4657 45 42 50 @ byte 8 | UklGRRUJQ at char 13 | RIFF container; bytes 4 to 7 are the file size. |
| BMP | .bmp | 42 4D | Qk | Only two bytes, so short text strings can also start with Qk. |
| ICO | .ico | 00 00 01 00 | AAABA | |
| CUR (cursor) | .cur | 00 00 02 00 | AAACA | |
| TIFF (little-endian) | .tif .tiff | 49 49 2A 00 | SUkqA | Also the start of many camera RAW files (.cr2, .nef, .dng). |
| TIFF (big-endian) | .tif .tiff | 4D 4D 00 2A | TU0AK | |
| Photoshop | .psd | 38 42 50 53 | OEJQU | |
| SVG (no XML declaration) | .svg | 3C 73 76 67 | PHN2Z | Text format: leading whitespace or a comment changes the prefix. |
| XML / SVG with declaration | .xml .svg | 3C 3F 78 6D 6C | PD94bW | Text format. |
| AVIF | .avif | 66 74 79 70 61 76 69 66 @ byte 4 | eXBhdmlm at char 9 | ISO media box: bytes 0 to 3 are the box size, which varies. |
| HEIC | .heic | 66 74 79 70 68 65 69 63 @ byte 4 | eXBoZWlj at char 9 | Same box structure as AVIF and MP4. |
| JPEG 2000 | .jp2 | 00 00 00 0C 6A 50 20 20 0D 0A 87 0A | AAAADGpQICANCocK | |
| JPEG XL (codestream) | .jxl | FF 0A | /w | |
| QOI | .qoi | 71 6F 69 66 | cW9pZ | |
| MP3 with ID3 tag | .mp3 | 49 44 33 | SUQz | MP3 files without a tag start with a frame header instead (often FF FB, Base64 //). |
| FLAC | .flac | 66 4C 61 43 | ZkxhQ | |
| Ogg (Vorbis, Opus) | .ogg .oga .opus | 4F 67 67 53 | T2dnU | |
| WAV | .wav | 52 49 46 4657 41 56 45 @ byte 8 | UklGRQVZF at char 13 | RIFF container like WebP. |
| AVI | .avi | 52 49 46 4641 56 49 20 @ byte 8 | UklGRVkkg at char 13 | RIFF container. |
| AIFF | .aiff .aif | 46 4F 52 4D41 49 46 46 @ byte 8 | Rk9STSUZG at char 13 | |
| MIDI | .mid .midi | 4D 54 68 64 | TVRoZ | |
| MP4 | .mp4 .m4v | 66 74 79 70 69 73 6F 6D @ byte 4 | eXBpc29t at char 9 | Brand varies (isom, mp42, avc1 ...); look for the ftyp box. |
| M4A audio | .m4a | 66 74 79 70 4D 34 41 20 @ byte 4 | eXBNNEEg at char 9 | |
| QuickTime | .mov | 66 74 79 70 71 74 20 20 @ byte 4 | eXBxdCAg at char 9 | |
| Matroska / WebM | .mkv .webm | 1A 45 DF A3 | GkXfo | EBML header. |
| Flash video | .flv | 46 4C 56 | RkxW | |
| Gzip | .gz .tgz | 1F 8B 08 | H4sI | Very common inside JSON, HTTP and Kubernetes secrets. |
| Bzip2 | .bz2 | 42 5A 68 | Qlpo | |
| XZ | .xz | FD 37 7A 58 5A 00 | /Td6WFoA | |
| 7-Zip | .7z | 37 7A BC AF 27 1C | N3q8rycc | |
| RAR | .rar | 52 61 72 21 1A 07 | UmFyIRoH | RAR 4 continues with 00, RAR 5 with 01 00. |
| Zstandard | .zst | 28 B5 2F FD | KLUv/ | |
| LZ4 frame | .lz4 | 04 22 4D 18 | BCJNG | |
| Microsoft Cabinet | .cab | 4D 53 43 46 | TVNDR | |
| Tar (POSIX) | .tar | 75 73 74 61 72 @ byte 257 | c3Rhc at char 345 | The signature is 257 bytes in, so it never appears at the start. |
| Windows executable (PE) | .exe .dll .sys | 4D 5A 90 00 | TVqQA | MZ header with the usual DOS stub. Very common in malware analysis. |
| ELF (Linux executable) | (none), .so, .o | 7F 45 4C 46 | f0VMR | |
| Mach-O 64-bit (macOS) | (none), .dylib | CF FA ED FE | z/rt/ | |
| Java class / Mach-O universal | .class | CA FE BA BE | yv66v | Both formats share this magic number. |
| WebAssembly | .wasm | 00 61 73 6D | AGFzb | |
| Android DEX | .dex | 64 65 78 0A | ZGV4C | |
| Script with shebang | .sh .py | 23 21 2F | IyEv | Text format. |
| Windows shortcut | .lnk | 4C 00 00 00 01 14 02 00 00 00 00 00 | TAAAAAEUAgAAAAAA | |
| WOFF | .woff | 77 4F 46 46 | d09GR | |
| WOFF2 | .woff2 | 77 4F 46 32 | d09GM | |
| TrueType | .ttf | 00 01 00 00 | AAEAA | |
| OpenType (CFF) | .otf | 4F 54 54 4F | T1RUT | |
| SQLite database | .db .sqlite | 53 51 4C 69 74 65 20 66 6F 72 6D 61 74 20 33 00 | U1FMaXRlIGZvcm1hdCAzA | |
| Parquet | .parquet | 50 41 52 31 | UEFSM | |
| pcap capture (little-endian) | .pcap | D4 C3 B2 A1 | 1MOyo | |
| pcapng capture | .pcapng | 0A 0D 0D 0A | Cg0NC | |
| Windows registry hive | (none), .dat | 72 65 67 66 | cmVnZ | |
| PEM text | .pem .crt .key | 2D 2D 2D 2D 2D 42 45 47 49 4E | LS0tLS1CRUdJT | Base64 of a PEM file, i.e. encoded twice. |
| DER certificate or key | .der .cer | 30 82 | MI | ASN.1 SEQUENCE with a two-byte length; in practice usually MII. |
| JSON object | .json | 7B 22 | eyJ | When the first key starts with a letter. Every JWT starts with eyJ. |
| HTML document | .html | 3C 21 44 4F 43 54 59 50 45 | PCFET0NUWVBF | Text format; case and whitespace change the prefix. |
| UTF-8 text with BOM | .txt .csv | EF BB BF | 77u/ | Common in CSV files exported from Excel. |
| UTF-16LE text with BOM | .txt | FF FE | // |
Things that change the prefix
- URL-safe encoding.
+and/become-and_, so a JPEG starts with_9j_and an XZ file with_Td6WFoA. Normalise before you compare. - A data URI header.
data:image/png;base64,comes before the Base64. Compare from the character after the comma. - Line breaks and whitespace. MIME and PEM wrap Base64 every 64 or 76 characters, which can split a long prefix. Remove whitespace first.
- Double encoding. If a string decodes to more Base64, its prefix looks like the Base64 of a Base64 prefix. A PDF encoded twice starts with
SlZCRVJp(the encoding ofJVBERi). - Compression or encryption. Encrypted data has no signature at all, and compressed data only shows the compressor's signature (gzip, zstd), not the file inside.
Checking the prefix in code
Python
PREFIXES = {
"JVBERi0": "pdf", "iVBORw0KGgo": "png", "/9j/": "jpg", "R0lGOD": "gif",
"UklGR": "riff", "UEsDB": "zip", "H4sI": "gzip", "TVqQ": "exe", "eyJ": "json",
}
def sniff(b64: str) -> str:
s = b64.split(",", 1)[-1].strip().replace("-", "+").replace("_", "/")
for prefix, kind in PREFIXES.items():
if s.startswith(prefix):
return kind
return "unknown"
JavaScript
const PREFIXES = { JVBERi0: "pdf", iVBORw0KGgo: "png", "/9j/": "jpg", R0lGOD: "gif",
UklGR: "riff", UEsDB: "zip", H4sI: "gzip", TVqQ: "exe", eyJ: "json" };
function sniff(b64) {
const s = b64.slice(b64.indexOf(",") + 1).trim().replace(/-/g, "+").replace(/_/g, "/");
return Object.entries(PREFIXES).find(([p]) => s.startsWith(p))?.[1] ?? "unknown";
}
Linux / macOS
head -c 16 input.b64; echo # look at the prefix
base64 --decode input.b64 | file - # let file(1) read the magic bytes
PowerShell
$s = (Get-Content -Raw .\input.b64).Trim()
if ($s.StartsWith("JVBERi0")) { "PDF" } elseif ($s.StartsWith("iVBORw0KGgo")) { "PNG" } else { $s.Substring(0, 16) }
A prefix match is a strong hint, not proof: a short signature such as BMP's Qk also matches any text that starts with “BM”. When it matters, decode and check the bytes. Smart Detect and the decoder do this for you in the browser.
Decode a file of a known type
Once you know the type, use the matching tool to preview and download it: Base64 to PDF, PNG, JPG, SVG, or any image. For other formats, the decoder's download button saves the raw bytes.
Published 9 November 2026. Spot an error? Email contactus@base64decode.tools.
Common questions.
It is the Base64 encoding of %PDF-, the signature every PDF file starts with. The string is a Base64-encoded PDF document.
A PNG image. iVBORw0KGgo is the Base64 form of the 8-byte PNG signature 89 50 4E 47 0D 0A 1A 0A.
UEsDB is the Base64 form of PK\x03\x04, the zip signature. Word, Excel and PowerPoint files (.docx, .xlsx, .pptx), EPUB books, Java .jar and Android .apk files are all zip archives, so they start with UEsDB too.
A JWT header is a JSON object beginning with {" followed by a letter. Those bytes always encode to eyJ in Base64.
Usually, yes. Formats with a fixed signature at byte 0 always produce the same leading Base64 characters. Formats with signatures further in (RIFF, MP4, tar) produce fixed characters at a known position instead. Text formats and encrypted data have no reliable signature.