If SHA256 produces an alphanumeric hash, how can a hash be "less than a certain value"?



I was under the impression that Bitcoin's method for validating a hash involved making sure the hash started with a pre-determined number of zeroes. However, after reading the docs here, I see the following sentence:

To prove you did some extra work to create a block, you must create a hash of the block header which does not exceed a certain value. To prove you did some extra work to create a block, you must create a hash of the block header which does not exceed a certain value. For example, if the maximum possible hash value is 2^256 − 1, you can prove that you tried up to two combinations by producing a hash value less than 2^255.

This is confusing to me, since according to my research the Bitcoin protocol uses the SHA256 hashing algorithm, which produces alphanumeric hashes. For instance, when I hash an empty file named "foobar.txt", I get "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855".

My question is, how can one alphanumeric hash output be "less than" another?

Richie Thomas

Posted 2016-07-16T22:24:21.973

Reputation: 133

2You are confusing values with representations of values. That sequence of characters is not a value, it's a representation of a value. – David Schwartz – 2016-07-17T03:24:32.450



The hash is not alphanumeric, it's hexadecimal, that is base-16. You can convert that to a decimal number. In your case:

0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 = 102987336249554097029535212322581322789799900648198034993379397001115665086549

The actual bytes are actually base-256 (8 bits to a byte), but it's relatively easy to represent the base-256 string in hexadecimal.

Jimmy Song

Posted 2016-07-16T22:24:21.973

Reputation: 7 330


Not that other answers are wrong here, but just to approach your confusion from another angle:

SHA256 hashing algorithm, which produces alphanumeric hashes.

That's not true. The hashing algorithm produces a stream of bytes. Only when you display that bunch of bytes on your screen it's common for it to be in hexadecimal (containing "alphanumeric" characters A to F) but that's just for display purposes to make it human-readable.

You may as well display that same bytes as a large decimal number (requires more screen space and doesn't have the advantage that each two digits represent exactly one byte from the original. Or you could display it in binary: 256 zeroes and ones.

My question is, how can one alphanumeric hash output be "less than" another?

Even disregarding the above, what stops you from sorting a list of words alphabetically? One word will be "less than" another word.


Posted 2016-07-16T22:24:21.973

Reputation: 6 046

RE: your question at the end: I thought of that, the difference is that hashes contain numbers and letters, whereas words are letters-only. Take a case of two single-digit alphanumeric strings. Is "5" greater or less than "b"? I wasn't aware until now that hashes are hexadecimal (not alphanumeric); this fact answers my question. – Richie Thomas – 2016-07-17T02:33:00.623

3@toomanyrichies It's less. Use the order 0123456789abcdef (case insensitive) when sorting hexadecimal alphabetically. – wizzwizz4 – 2016-07-17T11:44:33.183


You treat the hash as a base 16 number, and compare it like you would an integer.

So, for example, with normal numbers, to determine that 926 is less than 941, you basically follow this reasoning:

  1. The numbers have the same number of digits, so nothing can be determined yet.
  2. The numbers both have a 9 in the 100s place, so nothing can be determined yet.
  3. 926 has a 2 in the 10s place, where 941 had a 4, so 926 is less.
  4. The rest of the digits don't matter.

With SHA256 hashes, it's basically the same algorithm (conceptually), you just have to include a-f in the numbers. So, if we have two hashes 1a2cf... and 1b67e..., the first is smaller, because the second digit 'a' (which is 10 in normal numeric notation) is less than 'b' (which is 11 in normal numeric notation).


Posted 2016-07-16T22:24:21.973

Reputation: 13 123


Those are numbers written in hexadecimal (or base 16) as opposed to decimal (base 10) which you are used to. Decimal uses 0-9 giving 10 independent numerals. So 12 in decimal is written as '12'. Hexadecimal uses 0-9 and a-f in addition giving 16 independent numerals so decimal 12 in hexadecimal is 'c'.


Posted 2016-07-16T22:24:21.973

Reputation: 131