<p>What is a magic number?</p>

<p>Why should it be avoided?</p>

<p>Are there cases where it's appropriate?</p>

A magic number is a sequence of characters at the start of a file format, or protocol exchange.  This number serves as a sanity check.
Example:
Open up any GIF file, you will see at the very start: GIF89.  "GIF89" being the magic number.
Other programs can read the first few characters of a file and properly identify GIFs.
The danger is that random binary data can contain these same characters.  But it is very unlikely.
As for protocol exchange, you can use it to quickly identify that the current 'message' that is being passed to you is corrupted or not valid.
Magic numbers are still useful.