File Magic Bytes Checker

Check a file's magic bytes to reveal its real type. Free in-browser signature checker with hex dump, extension-spoofing alerts and a magic number list.

By

Advertisement

File Magic Number Checker: Identify a File by Its Magic Bytes

A file’s extension is a label anyone can change. Its magic number — the handful of bytes at the very start of the file — is what the operating system, the browser and the parsing library actually read to decide what the file is. This checker reads those bytes for you: drop one file or a whole batch onto the page, and each one is matched against a signature database, shown with a hex dump, and flagged when the real format disagrees with the extension on the filename.

Files are read locally through the browser’s File API. Nothing is uploaded, so you can inspect malware samples, customer artefacts or evidence copies without them leaving the machine. Only the first 512 bytes of each file are read, which keeps the check instant even on multi–gigabyte files.

Common File Signatures (Magic Bytes List)

These are the header bytes people look up most often. Hex is shown as it appears at offset 0 unless noted, alongside the printable ASCII that makes many of them recognisable at a glance in a hex editor.

FormatMagic bytes (hex)ASCII
PDF25 50 44 46%PDF
PNG89 50 4E 47 0D 0A 1A 0A.PNG....
JPEG / JPGFF D8 FF E0 (also E1, E2, E8)—
GIF47 49 46 38 37 61 / 47 49 46 38 39 61GIF87a / GIF89a
ZIP (also DOCX, XLSX, JAR, APK)50 4B 03 04PK..
RAR52 61 72 21 1A 07 00Rar!...
7–Zip37 7A BC AF 27 1C7z…
Gzip1F 8B—
Bzip242 5A 68BZh
TAR75 73 74 61 72 at offset 257ustar
Windows PE (EXE, DLL)4D 5AMZ
Linux ELF7F 45 4C 46.ELF
Java classCA FE BA BE—
WebAssembly00 61 73 6D.asm
MS Office 97–2003 (DOC, XLS, PPT)D0 CF 11 E0 A1 B1 1A E1—
RTF7B 5C 72 74 66{\rtf
SQLite database53 51 4C 69 74 65 20 66 6F 72 6D 61 74 20 33SQLite format 3
RIFF container (WAV, AVI, WebP)52 49 46 46RIFF
MP3FF FB / FF F3 / FF F2, or 49 44 33 (ID3 tag)—
MP4… 66 74 79 70 at offset 4ftyp
Matroska (MKV, WebM)1A 45 DF A3—
Ogg4F 67 67 53OggS
FLAC66 4C 61 43fLaC
BMP42 4DBM
TIFF49 49 2A 00 / 4D 4D 00 2AII*. / MM.*
Photoshop PSD38 42 50 538BPS
PEM certificate or key2D 2D 2D 2D 2D 42 45 47 49 4E-----BEGIN

The full database behind this tool holds 56 signature entries with their aliases, spanning images, video, audio, documents, archives, executables, databases, fonts, system files, crypto material and disk images.

How to Check a File Signature

  1. Add your files. Drag them onto the drop zone or click to browse. Multiple files at once are fine — each is analysed independently and listed with a category icon.
  2. Read the summary counters. Total files, detected, mismatches and unknown. On a batch, the mismatch count is the number worth looking at first.
  3. Open a file for detail. Selecting it shows the detected format and MIME type, a confidence score, the magic bytes in hex, any warnings, and alternative formats that share the same opening bytes.
  4. Inspect the hex dump. The first bytes are laid out in the classic offset / hex / ASCII columns, so you can confirm the signature yourself rather than trusting the verdict.
  5. Filter and export. Narrow the list to a single category or to Mismatches Only, then export the whole result set as JSON or CSV for a report or a ticket.

Detecting Extension Spoofing

The security value of a magic header check is that it catches the gap between what a file claims to be and what it is. When the signature and the extension disagree, the tool raises a warning naming both — for example, a file called invoice.pdf whose header reads 4D 5A is a Windows executable wearing a document’s name, which is a classic phishing payload.

Not every mismatch is an attack. Legitimate causes are common:

  • A file renamed by hand or by a download manager that guessed the type from a Content-Type header.
  • A truncated or partially downloaded file, where the header survives but the body does not.
  • A container format used for something else — DOCX, XLSX, PPTX, JAR, APK, EPUB and ODT are all ZIP archives, so all of them legitimately begin 50 4B 03 04.
  • RIFF containers, where WAV, AVI and WebP share the same first four bytes and are distinguished by a further tag deeper in the header.

That ambiguity is exactly why the tool lists alternatives rather than pretending to a single answer. If your file reports “ZIP archive” with alternatives, the honest reading is “this is a ZIP container” — what is inside it decides the rest.

The corresponding lesson for anyone building an upload feature: never trust the extension, and never trust the client–supplied Content-Type either. Both are attacker–controlled. Validate the magic bytes server–side, then re–encode or sandbox the file. Header validation on its own is also not sufficient, because a polyglot file can carry a valid image header and still be executed as a script by a permissive parser.

Where Magic Number Checks Are Used

In digital forensics, signature analysis is how deleted or renamed files are recovered from unallocated space — file carving works by scanning a disk image for known headers and reconstructing files from them. In incident response, it identifies what an unknown artefact from a compromised host actually is before anything opens it. In CTF competitions, a corrupted or deliberately mislabelled file is a standing forensics puzzle, and repairing the header is usually the first move; the hex editor is the natural companion for editing those bytes, and the hash lookup for checking a sample against known–bad databases.

It is also the everyday explanation for a mundane frustration: an image that will not open, a spreadsheet an application rejects, a “corrupt” archive. Checking the header settles in seconds whether the file is the wrong type, truncated, or genuinely damaged.

Frequently Asked Questions

What is a file magic number?+

It is a short, fixed byte sequence at a known position — usually the very start — that identifies a file’s format. %PDF for PDFs, MZ for Windows executables, PK for ZIP archives. Because it lives inside the file rather than in its name, it survives renaming and is what parsers actually rely on.

What are the magic bytes for PNG, JPG and PDF?+

PNG is 89 50 4E 47 0D 0A 1A 0A, an eight–byte signature designed to detect corruption during transfer. JPEG starts FF D8 FF followed by a marker byte such as E0 (JFIF) or E1 (Exif). PDF is 25 50 44 46, the ASCII text %PDF, normally followed by a version like -1.7.

Are my files uploaded to a server?+

No. Files are read in your browser with the File API and analysed locally. Nothing is transmitted or stored, which makes the tool safe for suspicious samples and confidential material.

Does it read the whole file?+

Only the first 512 bytes of each file are read, since that is where signatures live. That is why a 4–GB disk image checks as fast as a text file — and also why the tool cannot comment on anything beyond the header.

Why do a DOCX and a ZIP have the same magic number?+

Because a DOCX is a ZIP archive — an Open Packaging Convention bundle of XML parts. The same is true of XLSX, PPTX, JAR, APK, EPUB and ODT. Distinguishing them requires looking at the file names inside the archive, not at the header.

Can a file fake its magic number?+

Yes. Headers are just bytes and can be written deliberately. Polyglot files are valid in two formats at once, and attackers use them to slip past validators that only check the first few bytes. Treat a signature check as one strong signal, not as proof.

What does “unknown file type” mean?+

No signature in the database matched the opening bytes. Usually that means a plain–text or source file — text formats such as CSV, JSON, HTML and most scripts have no magic number at all — or an encrypted, compressed or proprietary format. A file that reports unknown but has a known extension is flagged separately as possibly corrupted or renamed.

Can I check many files at once?+

Yes. Add a whole batch, then use the Mismatches Only filter to jump straight to the files whose contents contradict their names, and export the results as JSON or CSV.

What are file magic numbers and why are they important?+

File magic numbers (file signatures) are byte sequences at the beginning of files that identify file types: Definition: Fixed byte pattern at start of file (typically first 2-16 bytes), used by operating systems to determine file type, independent of file extension. Common magic numbers: (1) JPEG: FF D8 FF (hex), starts every JPEG image. (2) PNG: 89 50 4E 47 0D 0A 1A 0A (hex) or ".PNG" in ASCII. (3) PDF: 25 50 44 46 (hex) or "%PDF" in ASCII. (4) ZIP: 50 4B 03 04 (hex) or "PK" in ASCII. (5) EXE (Windows): 4D 5A (hex) or "MZ" in ASCII. (6) ELF (Linux): 7F 45 4C 46 (hex). Why important: (1) Detect file extension spoofing - Malware disguised as safe file (malware.exe renamed to document.pdf), real type revealed by magic number. (2) Security analysis - Email attachments claiming to be images but are executables, identify hidden file types in forensic analysis. (3) Data recovery - Recover files with corrupted/missing extensions, identify fragments from unallocated disk space. (4) Malware detection - Polyglot files (valid multiple file types), steganography (data hidden in images), obfuscation techniques. (5) Compliance verification - Ensure uploaded files match allowed types, prevent policy violations (uploading executables to document portal). How it works: (1) Read first N bytes of file (header), (2) Compare against database of known signatures, (3) Identify file type regardless of extension. Tools: Unix file command, TrID (File Identifier), this magic number checker, hex editors (HxD, 010 Editor). Real-world example: Email attachment "invoice.pdf" has magic number 4D 5A = Windows executable, victim opens "PDF" and runs malware. File extensions lie, magic numbers don't (unless deliberately crafted).

How do attackers use file extension spoofing in malware?+

Extension spoofing exploits user trust in file extensions: Attack technique 1: Double extension - malware.pdf.exe (Windows hides .exe), user sees malware.pdf and thinks it's safe, icon shows PDF icon (can be customized), clicking executes malware. Attack technique 2: Right-to-left override - Unicode character U+202E reverses text display, filename: resume[U+202E]fdp.exe displays as: resume[exe.pdf backward] = resumeexe.pdf, actual file: resume.exe (PDF part is just display trick). Attack technique 3: Renamed executables - malware.exe → document.pdf, if email filters only check extension (not magic number), email delivered as "safe" PDF, user opens with default PDF viewer → error, user "tries again" by running with different program → executes. Attack technique 4: Archive containing executables - compressed_docs.zip contains: report.pdf (legitimate), setup.exe (malware), users extract all files, unknowingly run setup.exe. Attack technique 5: Polyglot files - File that is valid in multiple formats, example: file is both valid JPEG and ZIP, displayed as image in preview, but can be extracted as ZIP containing malware. Detection methods: (1) Check magic numbers - Read first bytes to identify real type, compare with file extension. (2) Deep file inspection - Scan entire file structure (not just header), detect embedded executables, identify suspicious sections. (3) Behavior analysis - Sandbox execution to observe behavior, detect payload extraction/execution. Email security: Modern mail gateways check: magic numbers vs extension, double extensions, RLO characters, macros in Office documents. User protection: (1) Show file extensions (Windows: unhide file extensions), (2) Hover over files to see full path, (3) Check file properties (right-click → Properties → Details), (4) Verify sender before opening attachments, (5) Use antivirus with heuristic detection. Statistics: 45% of malware uses extension spoofing, double extension attacks increased 300% in 2023, most effective against non-technical users. This tool helps verify true file type by examining magic numbers.

Related tools

This tool is provided for informational and educational purposes only. While we strive for accuracy, we make no warranties about the completeness or reliability of results. Results are based on the information you enter and do not constitute a security audit, a formal compliance assessment, or legal advice, and they do not establish that any system or organisation meets a given standard. Coverage of a framework may be partial — check what the tool states it assesses. For anything you intend to rely on, consult a qualified assessor.