How Files Introduce Themselves
I always thought a file was identified by its extension. A file ending in `.png` was a PNG, and that was the end of the story. Then I learned that extensions are mostly just names. The actual identity of a file is hidden in its first few bytes.
## The first bytes of a file
Many file formats begin with a special sequence of bytes called a **magic number** or **file signature**[^1].
For example, a PNG file begins with:
<details>
<summary>🔍 <strong>Inspect a PNG File</strong> (Click to expand)</summary>
```text
89 50 4E 47 0D 0A 1A 0A
Even if you rename your image to photo.txt, the computer reads these bytes and immediately knows it is still a picture.
A PDF begins with:
25 50 44 46
Those PDF bytes translate directly to: %PDF
The Takeaway
The next time you organize your hard drive, remember how the system actually works:
- Extensions are for humans: They keep our desktops neat and help us know what apps to open.
- Signatures are for computers: They prove to the machine what the data actually is.
The computer does not care what you call the file. It trusts the bytes.