Search
Duplicate
♦️

File Magic Number

File Magic Numbers
Magic numbers are the first bits of a file which uniquely identify the type of file. This makes programming easier because complicated file structures need not be searched in order to identify the file type.
For example, a jpeg file starts with ffd8 ffe0 0010 4a46 4946 0001 0101 0047 ......JFIF.....G ffd8 shows that it's a JPEG file, and ffe0 identify a JFIF type structure. There is an ascii encoding of "JFIF" which comes after a length code, but that is not necessary in order to identify the file. The first 4 bytes do that uniquely.
This gives an ongoing list of file-type magic numbers.
Image File Magic Number
File type
Typicalextension
Hex digitsxx = variable
Ascii digits. = not an ascii char
FITS format
Open
.fits
53 49 4d 50 4c 45
SIMPLE
GIF format
Open
.gif
47 49 46 38
GIF8
Graphics Kernel System
Open
.gks
47 4b 53 4d
GKSM
IRIS rgb format
Open
.rgb
01 da
..
ITC (CMU WM) format
Open
.itc
f1 00 40 bb
....
JPEG File Interchange Format
Open
.jpg
ff d8 ff e0
....
NIFF (Navy TIFF)
Open
.nif
49 49 4e 31
IIN1
PM format
Open
.pm
56 49 45 57
VIEW
PNG format
Open
.png
89 50 4e 47
.PNG
Postscript format
Open
.[e]ps
25 21
%!
Sun Rasterfile
Open
.ras
59 a6 6a 95
Y.j.
Targa format
Open
.tga
xx xx xx
...
TIFF format (Motorola - big endian)
Open
.tif
4d 4d 00 2a
MM.*
TIFF format (Intel - little endian)
Open
.tif
49 49 2a 00
II*.
X11 Bitmap format
Open
.xbm
xx xx
XCF Gimp file structure
Open
.xcf
67 69 6d 70 20 78 63 66 20 76
gimp xcf
Xfig format
Open
.fig
23 46 49 47
#FIG
XPM format
Open
.xpm
2f 2a 20 58 50 4d 20 2a 2f
/* XPM */
Compressed files magic number
File type
Typicalextension
Hex digitsxx = variable
Ascii digits. = not an ascii char
Bzip
Open
.bz
42 5a
BZ
Compress
Open
.Z
1f 9d
..
gzip format
Open
.gz
1f 8b
..
pkzip format
Open
.zip
50 4b 03 04
PK..
Archive files Magic number
File type
Typicalextension
Hex digitsxx = variable
Ascii digits. = not an ascii char
TAR (pre-POSIX)
Open
.tar
xx xx
(a filename)
TAR (POSIX)
Open
.tar
75 73 74 61 72
ustar (offset by 257 bytes)
Excecutable files
File type
Hex digitsxx = variable
Ascii digits. = not an ascii char
MS-DOS, OS/2 or MS Windows
Open
4d 5a
MZ
Unix elf
Open
7f 45 4c 46
.ELF
Miscellaneous files
File type
Hex digitsxx = variable
Ascii digits. = not an ascii char
pgp public ring
Open
99 00
..
pgp security ring
Open
95 01
..
pgp security ring
Open
95 00
..
pgp encrypted data
Open
a6 00
¦.
TOP