This has been bugging me. I’d have expected the magic number to be in the chainParams.cpp but I can’t find it.

Where is bitcoin's magic number stored in the source code?

1 Answer 1


You may not have been able to find them because they're encoded as separate bytes. You can find them in src/chainparams.cpp, currently on lines 102–105. I found the code section after noticing that the Bitcoin Developer Guide referred to the value as "Start String" and searching the code base for that term.

This is the relevant section of code.

     * The message start string is designed to be unlikely to occur in normal data.
     * The characters are rarely used upper ASCII, not valid as UTF-8, and produce
     * a large 32-bit integer with any alignment.
    pchMessageStart[0] = 0xf9;
    pchMessageStart[1] = 0xbe;
    pchMessageStart[2] = 0xb4;
    pchMessageStart[3] = 0xd9;
  • OMG, I went code blind and was fixated on a single assignment. It’s right bloody there!!!
    – LeosSire
    Jan 23, 2022 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.