How to Identify File Type Without Extension
In this article
When a file arrives without an extension—whether from a download, a renamed attachment, or an old backup—you can still determine its true type by inspecting its contents. The most reliable method is to read the file's magic bytes (the first few bytes that identify the format) using a hex editor or a command-line tool. This guide covers both graphical and terminal approaches, plus how to handle common pitfalls.
What You'll Need
- Access to the file itself (copy it to a working directory if needed).
- A hex editor (e.g., HxD for Windows, Hex Fiend for macOS) OR a command-line tool like
file(built into Linux/macOS, available for Windows via Git Bash or WSL). - Optional: a text editor to view the file if it's plain text.
Step-by-Step
- Start with the simplest clue: open the file in a text editor. Many files are plain text (e.g., .txt, .csv, .html, .xml, .json, .md). If you see readable words, the file is likely a text-based format. Note the first few lines—they often contain a declaration like
<!DOCTYPE html>or{for JSON. - If the text is garbled, it's binary. Close the text editor. Binary files (images, executables, archives, etc.) will show random symbols or replacement characters.
- Use the
filecommand (Linux/macOS/Windows with WSL). Open a terminal, navigate to the file's directory, and run:file filename
The output will say something likefilename: PNG image data, 800 x 600orfilename: gzip compressed data. This command reads magic bytes and prints a human-readable description. - If
fileis not available, use a hex editor. Open the file in a hex editor. Look at the first 8–16 bytes in the hexadecimal column. Compare them against known magic byte signatures (see Tips section). For example,FF D8 FFindicates a JPEG,89 50 4E 47is PNG,25 50 44 46is PDF, and7F 45 4C 46is an ELF executable. - Check for archive signatures. If the file starts with
1F 8Bit's gzip,50 4B 03 04is ZIP (which includes DOCX, XLSX, JAR, and APK),52 61 72 21is RAR, and37 7A BC AF 27 1Cis 7z. - For text-based files, look for XML or JSON structure. If the first bytes are
3C 3F 78 6D 6C(i.e.,<?xml), it's an XML file. If the first non-whitespace character is{or[, it's likely JSON. If it starts withPKbut you see[Content_Types].xmllater, it's an Office Open XML file (DOCX, XLSX, PPTX). - Use online file identifier tools (as a last resort). If you don't have a hex editor or terminal, upload the file to a reputable online service like
filext.comorfilesignatures.net(they allow manual signature lookup). However, be cautious about uploading sensitive files. - Rename the file with the correct extension. Once you know the type, add the appropriate extension (e.g.,
.png,.pdf). Then try opening it with the associated program to confirm.
Common Mistakes
- Assuming a file is text because it opens in Notepad. Some binary files contain readable strings (e.g., PDFs start with
%PDF). Always check the magic bytes, not just the visible text. - Trusting the file's icon. The icon may be misleading if the file was renamed or if the OS is guessing based on a previous association.
- Using a hex editor and misreading the bytes. Make sure you're looking at the hexadecimal column, not the ASCII column. The ASCII column shows characters, which can be misleading for binary data.
- Overlooking that some formats are containers. For example, a .docx file is a ZIP archive. If you see
PKat the start, you need to look inside to determine if it's a document or a regular ZIP. - Renaming the file before verifying. Adding an extension without checking the content can make the file unopenable or, worse, cause you to run a malicious executable.
Tips
- Memorize common magic bytes: JPEG:
FF D8 FF, PNG:89 50 4E 47, GIF:47 49 46 38, PDF:25 50 44 46, ZIP:50 4B 03 04, gzip:1F 8B, ELF:7F 45 4C 46, MP3:49 44 33(ID3 tag) orFF FB, MP4:00 00 00 18 66 74 79 70(contains 'ftyp'), and Windows PE:4D 5A(MZ). - Use the
filecommand with verbose output:file -i filenamegives MIME type (e.g.,image/png), which can be more specific. - For text files, check the encoding. If you see
EF BB BFat the start, it's UTF-8 with BOM. If you seeFF FE, it's UTF-16 LE. - If you're on Windows without WSL, use PowerShell. You can read the first bytes with:
Format-Hex -Path filename -Count 16
Then compare the output to known signatures. - When in doubt, use a file identification library. If you're a developer, libraries like
libmagic(used by thefilecommand) can be integrated into your own tools.
Troubleshooting
- The
filecommand says "data" or "unknown". This means the magic bytes don't match any known signature. The file could be corrupted, encrypted, or a custom format. Try opening it in a hex editor to see if there's a header you recognize. If not, you may need to guess based on the context (e.g., a file from a specific application). - The hex editor shows the file starts with
00 00. Some files (like MP4) have leading zeros. Look further into the file for a recognizable pattern, such asftypat offset 4. - You think it's a text file but it has binary characters. It might be a compressed text format (e.g., .gz) or an encoded file (like Base64). Try running
fileon it again after decompressing or decoding. - The file extension you added still doesn't open. The file might be a different subtype. For example, a ZIP file could be a DOCX, but if you rename it to .zip, it will open as an archive. If you rename it to .docx, Word may complain it's corrupt. Use a tool like 7-Zip to inspect the contents and look for
word/orxl/folders to confirm the Office type. - You're on a Mac and double-clicking does nothing. Use
filein Terminal (it's built-in). If you don't have a hex editor, you can usexxdto dump the first bytes:xxd -l 16 filename.
Frequently Asked Questions
Can I determine the file type just by looking at the file name?
No, the file name is unreliable. A file can be renamed to anything, but the content remains the same. Always inspect the content.
Is it safe to open a file without an extension?
It can be risky, especially if the file came from an untrusted source. Even after identifying the type, opening an executable (like an .exe) can harm your system. Use caution and scan with antivirus if possible.
What if the file is encrypted or password-protected?
Encrypted files often have no recognizable magic bytes because the header is encrypted. You'll need the password or decryption key to identify the underlying format.
Can I use online tools to identify a file?
Yes, but avoid uploading sensitive files. If you must, use a reputable site and consider that the file may be stored temporarily.
Why does the file command sometimes say "ASCII text" for a file that should be binary?
Some binary files contain long runs of ASCII characters (e.g., a PDF with mostly text). The file command uses heuristics and may misclassify if the magic bytes aren't at the very start. Check the first few bytes manually.
How can I identify a file without any tools?
You can open it in a text editor to see if it's readable. If not, you can search for known signatures in the binary data using a hex editor. Without tools, it's nearly impossible for binary files.