What is Magic Number (File Signature)?

Published on November 10, 2026 • Last updated November 10, 2026

Official Definition

A magic number, or file signature, is a fixed sequence of bytes at the start of a file that identifies its real format regardless of its name or extension.

Detailed Explanation

In-Depth Guide

Key Takeaway

Many formats begin with a recognisable byte pattern. A PDF starts with the characters %PDF, a PNG starts with the bytes 89 50 4E 47 0D 0A 1A 0A, a JPEG starts with FF D8 FF and a ZIP archive (which also covers DOCX and XLSX) starts with PK.

Upload validators read these first bytes to confirm that a file named photo.jpg really is a JPEG. This catches files that were simply renamed, which is why a spoofed-extension test file is a standard part of upload security testing.

Frequently Asked Questions

No. It confirms the format family but not that the content is harmless. Combine it with size limits, re-encoding of images, malware scanning and storing files outside the web root.

They are ZIP archives containing XML parts, so they share the ZIP signature. Inspect the archive contents to tell them apart.

Upload a file whose content and extension disagree, such as PNG bytes named .jpg. The Sample File Library includes this as a ready-made edge-case file.

What do you need to work out next?

Search 276+ free tools by name, or pick a category below. Every one runs instantly in your browser — no signup, nothing to install.

More Developer Tools
AI ADVISOR & COACH

Ask AI Advisor

Ask AI