What Actually Determines a File's Type
dev.to·2d·
Discuss: DEV
💾Digital Archiving
Preview
Report Post

Every file format has a specification, “an agreed-upon structure that defines how the bytes in that file are organized”. Just like we have standards for internet protocols, we have standards for file types. When an application opens a PDF or parses a PNG, it’s reading bytes according to that format’s predefined rules.

We usually identify files by their extension: .zip, .txt, .jpg. But extensions are really just hints for humans and the operating system. They’re convenient labels, not the actual source of truth, which is why renaming photo.jpg to photo.png doesn’t convert the image.

Extensions are just hints, the real determining of the type is done through “Magic Numbers”

Magic Numbers

*A magic number is a sequence of bytes, located at the beginning or specific offsets …

Similar Posts

Loading similar posts...