Home/Tools/Security/File Magic Number Checker

File Magic Number Checker

Identify file types by magic numbers and signatures. Detect file extension spoofing and verify true file formats for security analysis.

100% Private - Runs Entirely in Your Browser
No data is sent to any server. All processing happens locally on your device.
Loading File Magic Number Checker...

Filter analyzed files by type or mismatch status

Loading interactive tool...

Need Professional Security Testing?

Our penetration testers find vulnerabilities before attackers do. Get a comprehensive security assessment.

What Is a File Magic Number

A file magic number (also called a file signature) is a sequence of bytes at the beginning of a file that identifies its format. Unlike file extensions (which are part of the filename and easily changed), magic numbers are embedded in the file's binary content and reliably indicate the actual file type regardless of what extension is used.

Magic numbers are critical for security because attackers frequently disguise malicious files by changing their extensions — renaming a .exe to .pdf, for example. File upload validators, antivirus scanners, and forensic tools use magic number checks to determine the true file type and detect such deception.

How Magic Numbers Work

The first few bytes of a file contain a signature that file identification tools compare against a database of known formats:

File TypeMagic Bytes (Hex)ASCII RepresentationPosition
PDF25 50 44 46%PDFOffset 0
PNG89 50 4E 47 0D 0A 1A 0A.PNG....Offset 0
JPEGFF D8 FF...Offset 0
ZIP/DOCX/XLSX50 4B 03 04PK..Offset 0
ELF (Linux executable)7F 45 4C 46.ELFOffset 0
PE (Windows executable)4D 5AMZOffset 0
GIF47 49 46 38GIF8Offset 0
SQLite53 51 4C 69 74 65SQLiteOffset 0
Java .classCA FE BA BE....Offset 0
gzip1F 8B..Offset 0

The Unix file command, Python's python-magic library, and this tool all use magic number databases to identify files. The most comprehensive database is maintained by the libmagic project.

Common Use Cases

  • Upload validation: Verify that uploaded files match their claimed type before processing. A file with a .jpg extension but PE (MZ) magic bytes is likely a disguised executable.
  • Forensic analysis: Identify file types on seized storage media, especially when files have been renamed or have no extension
  • Malware analysis: Detect files disguised with incorrect extensions, a common technique in malware distribution and social engineering
  • Data loss prevention: Scan outbound files to ensure employees are not exfiltrating sensitive data disguised as innocuous file types
  • Content filtering: Web application firewalls and proxy servers use magic number checks to enforce upload and download policies

Best Practices

  1. Never trust file extensions alone — Always validate the magic number in addition to the extension. Extensions are metadata that users and attackers can change freely.
  2. Check magic numbers server-side — Client-side extension checks are trivially bypassed. Perform magic number validation on the server before processing any uploaded file.
  3. Validate deep structure, not just headers — Some polyglot files contain valid magic numbers for multiple formats simultaneously. For high-security applications, parse the file structure beyond just the initial bytes.
  4. Whitelist allowed file types — Rather than trying to detect all malicious types, maintain a whitelist of permitted magic numbers and reject everything else.
  5. Combine with antivirus scanning — Magic number checks confirm file type but do not detect malicious content within valid files. Always complement with content scanning for defense in depth.

References & Citations

  1. Gary Kessler. (2024). List of File Signatures (Magic Numbers). Retrieved from https://www.garykessler.net/library/file_sigs.html (accessed January 2025)
  2. DigitalPreservation.gov. (2024). File Format Specifications. Retrieved from https://www.digitalpreservation.gov/formats/ (accessed January 2025)
  3. NIST. (2024). Computer Forensics Tool Testing Program - Forensic File Carving. Retrieved from https://www.nist.gov/itl/ssd/software-quality-group/computer-forensics-tool-testing-program-cftt/cftt-technical-0 (accessed January 2025)

Note: These citations are provided for informational and educational purposes. Always verify information with the original sources and consult with qualified professionals for specific advice related to your situation.

Frequently Asked Questions

Common questions about the File Magic Number Checker

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).

⚠️ Security Notice

This tool is provided for educational and authorized security testing purposes only. Always ensure you have proper authorization before testing any systems or networks you do not own. Unauthorized access or security testing may be illegal in your jurisdiction. All processing happens client-side in your browser - no data is sent to our servers.