Skip to content

Hash

  • by
What Is A Cryptographic Hash?

What Is A Hash?

A hash, or cryptographic hash, is a mathematical function that takes digital data of any size as an input and produces a digital output of a fixed size. It is a one-way function, meaning that it is practically impossible to reverse the process and obtain the original input from the output. Hash functions are deterministic, meaning that they will always produce the same output for a given input.

Hashes are often used to verify the integrity of digital data, such as downloaded files. When a file is downloaded, a hash value can be calculated and compared to the hash value shown on the website. If the two values match, then you can be sure that the file has not been modified or corrupted in transit.

SHA-256 Hash

SHA-256, short for secure hashing algorithm, is the type of hash function that Bitcoin uses for bitcoin mining. The SHA-256 algorithm produces a 256-bit (32-byte) output, which is typically represented as a 64-digit hexadecimal number. The output hash is always the same size, regardless of the size or type of input data.

The number of possible outputs of a SHA-256 Hash is 2^256 which is 115,792,089,237,316,195,423,570,985,008,687,907,853,269,984,665,640,564,039,
457,584,007,913,129,639,936.

That’s a really big number.

For comparison, there are about 10^80 atoms in the visible universe.

If you’re wondering how to say that number, it’s pronounced like this…

115 quattuorvigintillion 792 trevigintillion 89 duovigintillion 237 unvigintillion 316 vigintillion 195 novemdecillion 423 octodecillion 570 septendecillion 985 sexdecillion 8 quindecillion 687 quattuordecillion 907 tredecillion 853 duodecillion 269 undecillion 984 decillion 665 nonillion 640 octillion 564 septillion 39 sextillion 457 quintillion 584 quadrillion 7 trillion 913 billion 129 million 639 thousand 936

Try It Out Yourself

If you would like to learn more about how it works, you can experiment with this SHA-256 algorithm tool. If you would like to learn more about multiple different types of cryptographic hashes, you can use this hash tool.

Here are a few SHA-256 inputs and their outputs.

If you input “Stack Sats!”, the output is 8c0b8a606f38d43e07022d621b16a26c748f06c6d230b527d1419b09ab93d011

…but if you remove the “!” and only input “Stack Sats”, then the output is 66800a66051f0a01f3e199453de848335ad32a618aa9958395044d990f21aa5b

…and if you keep the “!” but make it all lower case and hash “stack sats!”, then the output is 0c4a04e4806f6dc595b04577656eeb254e87242e8c86669f75e690d7901d8b80

Notice how even a tiny change in each one of these inputs results in a vastly different output? That’s because SHA-256 is deterministic and will always produce the exact same output for any given input.

Collisions

In mathematics, a collision occurs when two distinct inputs map to the same output. In the case of a SHA-256 hash, there are an infinite number of possible inputs (strings of any length) but a limited number of possible outputs for a SHA-256 hash (2^256, or around 10^77). Therefore, it is mathematically possible for two different inputs to produce the same output. However, due to the large number of possible outputs, the probability of a collision occurring is practically impossible.