Guide

File Magic Numbers: Spot a Renamed or Disguised File

Short answer: the extension on a file name is just text anyone can change. The first few bytes of the file, its magic number, say what it really is. Drop a file into the File Magic Number Inspector and it compares those bytes with about 150 known signatures, warns about renamed files and shows the raw bytes. Files are only read, never uploaded or run.

What a magic number is

Many formats begin with a fixed byte pattern. A PNG image starts with 89 50 4E 47 0D 0A 1A 0A. A ZIP archive starts with 50 4B 03 04. The tool matches the start of the file against signatures for formats such as PNG, JPEG, GIF, PDF, ZIP, GZIP, RAR, 7z, ELF, WebP, MP3, WAV, MP4, SQLite and WebAssembly.

Three real examples

  1. A renamed file. photo.jpg that begins with the PNG bytes above is detected as PNG. The extension check reports a mismatch: the extension normally means JPEG, but the content matches PNG, so the file may have been renamed or mislabelled.
  2. A ZIP-based document. report.docx that begins with 50 4B 03 04 is a ZIP container, which is consistent with .docx, because Word documents are ZIP files. The tool still adds notes, for example if the file list does not look like a Word document or the end-of-central-directory record is missing.
  3. An unknown file. data.bin starting with 01 02 03 04 05 06 07 08 matches none of the signatures. .bin is a generic extension and says nothing about the content.

Why a DOCX, XLSX or APK shows as ZIP

Office documents, OpenDocument files, Java packages (JAR), Android packages (APK) and EPUB books are ZIP files with a particular layout. The tool tells them apart from the file list inside the ZIP.

Confidence levels

Short signatures of two or three bytes, such as MZ or BM, can occur by chance. So each match is marked as a low, medium or high hint, depending on how many fixed bytes the signature has and whether header fields agree.

What a match does not prove

"Signature matches PNG" means the bytes at the start look like a PNG. It does not mean the file is valid, complete or safe. The tool also does a light consistency check on a few header fields and end markers, for example PNG chunk checksums or the ZIP central directory, but this is not a full validation. Treat unknown files with care, and before running anything from one, see is this shell command safe.

How to use the File Magic Number Inspector

  1. Open the File Magic Number Inspector.
  2. Drop up to 200 files, or choose them.
  3. Pick how many first bytes to display (16 to 512).
  4. Read the ranked matches, the extension check and the hex and ASCII view.
  5. Open the file in the Hex Viewer, or send an image to the Image Metadata Viewer (see removing EXIF and GPS data).
  6. Download the report as JSON or CSV if you need a record.

Limits to know

  • Only the first and last 64 KiB of each file are read, so a ZIP's type may be unknown when its file list is larger than that.
  • Old Office files (DOC, XLS, PPT) and MSI share one container format and cannot be told apart.
  • Text files with no signature are guessed (JSON, HTML, XML, SVG, CSV, Markdown or plain text). That is a heuristic.

Frequently asked questions

How do I check the real type of a file? Look at its magic number with the File Magic Number Inspector.

Does a match prove the file is safe? No. It proves only that the beginning looks like a known format.

Why is my .docx shown as a ZIP? Word documents are ZIP archives.

Is my file uploaded? No. Only its beginning and end are read in your browser.

Can an extension be wrong on purpose? Yes. Anyone can rename a file, which is why the content check matters.

Related tools and guides