- [Home](https://linkinseconds.com/)

- /

- [Glossary](https://linkinseconds.com/glossary)

- /

- Magic bytes

[Behind the link](https://linkinseconds.com/glossary#tech)

# What are magic bytes?

Definition

Magic bytes are the first few bytes of a file, which reveal its real format whatever its name says. A PDF starts with %PDF, for example, so checking them catches a program renamed to look like a document.

Also called: File signature, Magic number, File header

## How do magic bytes work?

Magic bytes work because most file formats begin with a fixed pattern that the format requires. Programs that read the format look for that pattern, so it is there in every valid file. A PNG image always opens with the same eight bytes, and a ZIP archive opens with the letters PK, the initials of Phil Katz, who created the format.

Because the pattern sits inside the file, renaming the file does not change it. That makes magic bytes a more honest signal than the file extension or the [MIME type](https://linkinseconds.com/glossary/mime-type), which are labels anyone can edit. The file command on Mac and Linux identifies files this way.

## Why do file hosts check magic bytes?

File hosts check magic bytes to catch files that pretend to be something else. The classic case is a program renamed to look harmless, such as setup.exe saved as setup.pdf. Windows programs start with the letters MZ, so a host that reads the first bytes sees through the new name. A magic-byte check helps a host:

- Refuse programs and scripts, even when they are renamed.

- Make sure a file really opens in the viewer it is sent to.

- Stop broken files, such as an image whose header is missing or damaged.

## What can a magic-byte check not catch?

A magic-byte check confirms the format, not whether the contents are safe. A real PDF can still hold a phishing link, and a real image can still show something that breaks the rules. That is why hosts follow it with [content moderation](https://linkinseconds.com/glossary/content-moderation).

Some formats also share a signature. Word, Excel and PowerPoint files (.docx, .xlsx and .pptx) are [ZIP archives](https://linkinseconds.com/glossary/zip-file) inside, so they all start with PK. Plain text formats such as HTML, CSV and code have no magic bytes at all, so hosts check them in other ways.

Magic bytes of common file types

| File type | Starts with (hex) | Readable part |

| PDF | 25 50 44 46 | %PDF |

| PNG image | 89 50 4E 47 | PNG |

| JPEG image | FF D8 FF | None |

| ZIP, DOCX, XLSX, PPTX | 50 4B 03 04 | PK |

| Windows program (.exe) | 4D 5A | MZ |

In Link in Seconds

In Link in Seconds, every upload is checked by its magic bytes once it reaches storage. We read the first bytes, check they match the type the file name claims, and refuse Windows, macOS and Linux programs even when they are renamed. If a check fails, the uploaded bytes are deleted and nothing is published.

[Supported file types](https://linkinseconds.com/docs/file-types)

## Magic bytes: common questions

### Are magic bytes the same as a file extension?

No. The extension is part of the file name and anyone can change it. Magic bytes are inside the file and only change if the file itself changes.

### How can I see a file's magic bytes?

Open the file in a hex viewer and read the start of the first row. On Mac or Linux, the file command in the terminal reads them for you and names the format.

### Do all files have magic bytes?

No. Plain text formats such as .txt, .csv, .html and code files have no fixed start, so tools identify them by their contents and name instead.

### Why is a .docx file detected as a ZIP?

Because it is one. Modern Office files are ZIP archives of XML files, so they start with the same PK bytes, and a checker has to look inside to tell them apart.

### Is a magic-byte check enough to make a file safe?

No. It proves the format, not the contents. A real PDF or image can still be harmful, so hosts run content checks as well.

## Related terms

- [MIME typeA MIME type is the label that says what kind of data a file is, such as application/pdf or image/png. Browsers use it to decide how to open a file, but it is easy to fake, so careful hosts do not trust it alone.](https://linkinseconds.com/glossary/mime-type)

- [Content moderationContent moderation is the set of checks a host runs to keep illegal or harmful files off its service: automated scanning at upload, human review of anything flagged, and a way for anyone to report a link.](https://linkinseconds.com/glossary/content-moderation)

- [Hash matchingHash matching is comparing a short fingerprint of a file against a list of fingerprints of files already known to be bad, such as known malware. It finds exact or near copies without anyone needing to look at the file.](https://linkinseconds.com/glossary/hash-matching)

- [ZIP fileA ZIP file is one file that holds many files and folders, usually compressed to take less space. It lets you send a whole folder as a single download, and the person who gets it unzips it to see the files.](https://linkinseconds.com/glossary/zip-file)

- [File hostingFile hosting is keeping a file online at a stable address so people can open it whenever they like, often in the browser. It suits files you share again and again: a resume, a menu, a price list.](https://linkinseconds.com/glossary/file-hosting)

## Go deeper

- [How file hosts scan uploads](https://linkinseconds.com/blog/how-file-hosts-scan-uploads)

- [Safety, scanning and reporting](https://linkinseconds.com/docs/safety)

Updated December 5, 2026

[Previous termllms.txt](https://linkinseconds.com/glossary/llms-txt)[Next termMCP server](https://linkinseconds.com/glossary/mcp-server)

Share a file as a link in seconds

Upload any file and get one clean link, with every setting on this page.

[Try Link in Seconds](https://linkinseconds.com/)

Source: https://linkinseconds.com/glossary/magic-bytes
