<p>The magic number is not something specific to bitcoin. </p>

<p><a href="https://en.wikipedia.org/wiki/Magic_number_(programming)" rel="noreferrer">Magic numbers</a> are used in computer science for both files and protocols. They identify the type of the file/data structure. A program receiving such a file/data structure can check the magic number and immediately know the supposed type of that file/data structure.</p>

<p>This is what the Unix/Linux command <a href="https://en.wikipedia.org/wiki/File_(command)" rel="noreferrer"><code>file</code></a> uses to quickly identify the type of file. It only requires to check only the first bytes of a file to determine its (supposed) type. A list of files and their magic numbers can be found <a href="https://en.wikipedia.org/wiki/List_of_file_signatures" rel="noreferrer">here</a>.</p>

<p>Protocols like bitcoin use data structures to talk to each other (e.g. propagating blocks through the network). Nodes check the first bytes to identify the type of data structure.</p>

<p>Another use of magic numbers is that you can check the type of the file or data structure on a text editor. E.g. while a png image is binary if you open it with a text editor you will notice that it starts with <code>.PNG....</code>. Another example, the SMB protocol replies start with <code>FFSMB</code>. Note, however, that this is not always the case. </p>

<p>Other files/structures have magic numbers that do not make much sense; they may be some geeky code or inside joke of the developers that chose it.</p>

<p>So that is what it is used for. As far as I can tell <code>0xD9B4BEF9</code> is quite arbitrary... but maybe there is some meaning for its creator.</p>

CC BY-SA 3.0
2016-03-04T23:49:53.107Z
The way it was chosen is documented [here](http://bitcoin.stackexchange.com/a/2355/2306).
Nick ODell
CC BY-SA 3.0
2016-03-05T09:38:28.767Z
Thanks @NickODell. Interesting. Actually, unless you stream the blocks I find that the probability of these bytes occurring in normal data is irrelevant.
karask
CC BY-SA 3.0
2016-03-05T09:48:32.970Z
I also commented in the answer you linked in case someone can clarify.
karask
CC BY-SA 3.0
2016-03-04T21:02:29.503Z
2016-03-04T23:25:21.730Z
2016-03-04T23:25:21.730Z
karask
<p>What is the Magic no used in the block structure, why is the value always 0xD9B4BEF9 and what is it used for ?</p>

<p>Thanks</p>

CC BY-SA 3.0
2016-03-04T18:58:02.463Z
http://bitcoin.stackexchange.com/questions/2337/how-was-the-magic-network-id-value-chosen
GiM
CC BY-SA 3.0
2016-03-04T23:42:04.823Z
Also http://bitcoin.stackexchange.com/questions/41495/what-block-version-is-this-d9b4bef9-decimal-3652501241
Nick ODell
<block>
What is the magic number used in the block structure?
user1892955
# What is the magic number used in the block structure?

(Asked by: username_0 on 2016-03-04)

What is the Magic no used in the block structure, why is the value always 0xD9B4BEF9 and what is it used for ?

Thanks

**Tags:** block

> **Comments:**
> **username_1**: http://bitcoin.stackexchange.com/questions/2337/how-was-the-magic-network-id-value-chosen  
> **username_2**: Also http://bitcoin.stackexchange.com/questions/41495/what-block-version-is-this-d9b4bef9-decimal-3652501241  

---

## 1 answers

### Answer by username_3 on 2016-03-04. Score: 12

The magic number is not something specific to bitcoin.

[Magic numbers](https://en.wikipedia.org/wiki/Magic_number_(programming)) are used in computer science for both files and protocols. They identify the type of the file/data structure. A program receiving such a file/data structure can check the magic number and immediately know the supposed type of that file/data structure.

This is what the Unix/Linux command [`file`](https://en.wikipedia.org/wiki/File_(command)) uses to quickly identify the type of file. It only requires to check only the first bytes of a file to determine its (supposed) type. A list of files and their magic numbers can be found [here](https://en.wikipedia.org/wiki/List_of_file_signatures).

Protocols like bitcoin use data structures to talk to each other (e.g. propagating blocks through the network). Nodes check the first bytes to identify the type of data structure.

Another use of magic numbers is that you can check the type of the file or data structure on a text editor. E.g. while a png image is binary if you open it with a text editor you will notice that it starts with `.PNG....`. Another example, the SMB protocol replies start with `FFSMB`. Note, however, that this is not always the case.

Other files/structures have magic numbers that do not make much sense; they may be some geeky code or inside joke of the developers that chose it.

So that is what it is used for. As far as I can tell `0xD9B4BEF9` is quite arbitrary... but maybe there is some meaning for its creator.

> **Comments:**
> **username_2**: The way it was chosen is documented [here](http://bitcoin.stackexchange.com/a/2355/2306).  
> **username_3**: Thanks @username_2. Interesting. Actually, unless you stream the blocks I find that the probability of these bytes occurring in normal data is irrelevant.  
> **username_3**: I also commented in the answer you linked in case someone can clarify.  

---

