This table of file signatures (also known as "magic numbers") is a continuing work in progres, started by Dr. Gary Kessler in 2002. See also Wikipedia's List of File Signatures Comments, additions and queries can be sent to SEARCH's Cybercrime and Digital Forensics Program at cyber@search.org
This list is not exhaustive, although new files are added when they are found or when someone contributes a signature. Interpret this table as a one-way function: the magic number generally indicates the file type, whereas the file type does not always have the given magic number. If you want to know what a particular file extension refers, check out File Extension Seeker: Metasearch engine for file extensions.
Some other useful information:
Dr. Kessler's software utility page contains a custom signature file based upon this list, for use with FTK, Scalpel, Simple Carver, Simple Carver Lite, and THD. There is also a raw CSV file and JSON file of signatures.
Tim Coakley's File.co.uk site, with Filesig Manager and Simple Carver.
Marco Pontello's THD - File Identifier utility designed to identify file types from their binary signatures.
The National Archives' PRONOM site provides on-line information about data file formats and their supporting software products, as well as their multi-platform DROID (Digital Record Object Identification) software.
If you are using a Linux/MacOS/Unix system, you can use the file command to determine the file type based upon the file signature, per the system's magic file.