Tag Archives: magic numbers

Magic Numbers a glance


Ever wonder how files are identified correctly as jpeg, gif or even class file for that matter by the OS.

Its all magic.. 🙂

Magic numbers are those which are prefixed at the start of the file in ASCII code to identify the file format.

Some of the common magic numbers are

Class bytecode starts with hex CAFEBABE
GIF image files have ‘GIF89a‘ (47 49 46 38 39 61) or ‘GIF87a‘ (47 49 46 38 37 61)
JPEG image files begin with ‘FF D8‘ and end with ‘FF D9'
PNG image files begin with “\211 P N G \r \n 32 \n” (89 50 4E 47 0D 0A 1A 0A)
ZIP files begin with ‘PK‘ (50 4B)
PDF files start with ‘%PDF‘ (25 50 44 46)

Advertisements