Hash Function

A cryptographic hash function is a mathematical tool that takes any kind of input—called a preimage—and turns it into a fixed-size string of characters, usually known as a hash or digest. No matter how big or small your input is, the output is always the same length for a given hash function.

These functions have some important characteristics:

  • They are deterministic: the same input will always produce the same hash.
  • They are one-way: it’s easy to compute a hash from input, but practically impossible to reverse the process and figure out the input from only the hash.
  • Their output appears random: even a tiny change in the input creates a completely different output, with no clear link between old and new hashes.

These properties are vital in Bitcoin. Hash functions make mining fair by keeping hash prediction impossible and help protect users’ privacy by turning public keys and scripts into addresses. Hashes give every Bitcoin transaction and block a unique “fingerprint,” while structures like Merkle Trees, built with hashes, make it efficient to verify transaction data.

Bitcoin primarily uses a few hash functions: SHA-256 (used twice to create transaction IDs and for mining), and hash160 (a combination of SHA-256 followed by RIPEMD160) to generate addresses. Each plays a key role in securing and running the Bitcoin network.