The First Bytes Act Like a File’s Fingerprint

A program does not have to trust a filename to recognize what it is opening. Many file formats begin with a short, characteristic sequence of bytes—values that are invisible in ordinary text but can be inspected by software. A PNG image, for example, begins with a defined byte pattern; a PDF begins with the readable characters `%PDF`.

These patterns are often called magic numbers or file signatures. They are not secret keys or cryptographic signatures. They are format markers embedded at the start of the file, where a program can check them before deciding how to interpret the rest.

Why the Extension Isn’t Enough

The ending of a filename, such as `.jpg` or `.pdf`, is just a label. It can be mistyped, changed, or deliberately misleading. If a file named `photo.jpg` actually starts with the signature of a PDF, software that checks the bytes can flag the mismatch or open it using the format it detects instead.

That check helps operating systems, file managers, and applications choose an appropriate handler. It is also useful when filenames are missing—for example, when a file is recovered from a damaged drive or downloaded without its original name.

A Clue, Not a Guarantee

A matching opening pattern is useful evidence, but it does not prove that the entire file is valid or safe. A file may be damaged after its opening bytes, and someone can copy a familiar signature onto unrelated data. Some formats also allow extra data or unusual structures that make identification less straightforward.

So the opening bytes serve as a quick first test: they tell software what format the file claims to follow, while the rest of the file must still be checked before it can be reliably processed.