a magic number
Imagine every brand of canned food stamping the same secret symbol just inside the lid, so a factory robot can tell tomato soup from peaches without reading the label. A magic number is that stamp for files: a short, fixed pattern of bytes placed at a known position (almost always the very start of the file) that reliably identifies the file's format.
When a program needs to know what a file really is, it opens the file, reads the first few bytes, and compares them against a table of known signatures. A PNG image always begins with the bytes 137 80 78 71 (which spell a near-invisible byte followed by PNG); a PDF file starts with the characters %PDF; a Java class file starts with the famous value written in hexadecimal as CAFEBABE; a Unix script can announce its interpreter with the first two characters being a hash and an exclamation mark, called the shebang. Because these bytes are inside the data itself, they survive renaming, copying, and emailing. The OS or library matches the pattern and concludes, for example, "this is a PNG, hand it to the image decoder."
Why it matters: the magic number is the trustworthy counterpart to the easily faked extension. Tools like the Unix file command identify a file's type almost entirely by its magic number. The honest caveat is that a magic number only proves the file STARTS like a given format; a corrupted or maliciously crafted file can carry a valid-looking signature and still be broken or dangerous, so a magic number is strong evidence of intent, not a guarantee of safety.
Dumping the first eight bytes of a PNG shows: 137 80 78 71 13 10 26 10. The leading 137 80 78 71 is the magic number that says "PNG" no matter what the file is named.
A fixed signature at the start of the data, immune to renaming.
A magic number proves a file BEGINS like a format; it is not a proof of validity or safety. A truncated or hostile file can still carry a correct-looking signature.