Before I get to explaining the topic of this post, I would like to clarify a few things in case some readers are beginners in Blockchain technology.

What is a hash?

Hash is a 256-bit Hexadecimal Number. Since hexadecimal numbers take up 4 bits in storage each, the total length of a hash is 64 (256 / 4). Below is a sample hash:

In the Decimal System that would be: 102987336249554097029535212322581322789799900648198034993379397001115665086549

What do miners do?

Miners solve Cryptographic Puzzle, which is simply finding a hash below (smaller than) certain Target $T$. They randomly generate hashes, and for each one check if it’s between $0 - T$ (Greater than 0, and smaller than T).

How to get Hash Target?

Hash Target along with other important information should be stored in a block. However, there’s no such field as Target or Hash Target. So, how is miner supposed to know what the range of valid hashes is?

Where is Hash Target stored?

Actually, Hash Target is stored in Bits field. However, it’s not straightforward, and doesn’t remain a Hexadecimal Number.


How to decode Bits field?

Here, I will guide you step by step, how to decode Hash Target, so it doesn’t look scary and complicated.

  1. Convert Bits field to Hexadecimal number.

    Bits to Hexadecimal

  2. Take first two digits and convert them back to the Decimal system.

    Prefix to Decimal
    Now, this 23 stands for the length of the resulting hexadecimal number (in BYTES). Since 23 bytes can hold ($23 \times 2$) 46 hexadecimal digits, the true length of the hexadecimal number is 46. Let’s fill it with zeros for now.

    Target Hash length

  3. Plug the rest of the digits at the very beginning of the resulting hexadecimal number.

    Plug in the rest

  4. Add missing zeros.
    Since, the total length of a hash is 64, we have to fill the gap and add 18 (64 - 46) zeros to the beginning of our hexadecimal number.

    Missing zeros

So, 392009692 in the Bits field produces the following Hash Target: 0000000000000000005d97dc0000000000000000000000000000000000000000

Now, some of you may ask why not store Hash Target in its exact form? The answer is simple:
Because it saves vital storage space. Since blocks have limited storage size (1MB as for Bitcoin), representing Hash Target in Bits code, could potentially result in more transactions recorded in a block.

Congratulations, you have made it this far! I can’t wait to see you in other posts too. Keep up the great work on discovering the revolutionary Blockchain technology.