A cryptographic hash function is a mathematical algorithm that takes an arbitrary input and produces a fixed-size output, commonly referred to as a hash, digest, or fingerprint. Hash functions are the foundational primitive upon which blockchain security is built. Without them, the properties of immutability and tamper-evidence that define blockchains would not be possible.

How Hash Functions Work

A hash function maps input data of any size to an output of a fixed size. For example, SHA-256—the hash function used in Bitcoin—always produces a 256-bit (64-character hexadecimal) output, regardless of whether the input is a single character or an entire library of text.

Consider these examples using SHA-256:

Input SHA-256 Output
hello 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
Hello 185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969
hello! ce06092fb948d9ffac7d1a376f0e0de0953aac2f25beefc2c33e4e8e22529cb4

Note that even a trivial change in the input—capitalizing a single letter or adding a punctuation mark—produces a completely different hash. This behavior is known as the avalanche effect.

Essential Properties of Cryptographic Hash Functions

For a hash function to be considered cryptographically secure, it must exhibit the following properties:

1. Deterministic

The same input will always produce the same output. There is no randomness involved. If you hash hello with SHA-256 today, tomorrow, or a decade from now, you will always get the same 64-character result. This determinism is what allows independent nodes to verify data integrity without coordinating with each other.

2. Fixed-Length Output

Regardless of input size, the output is always the same length. SHA-256 always produces 256 bits. Keccak-256 (used in Ethereum) also produces 256 bits. This fixed size makes hashes practical for use in data structures like Merkle trees and block headers, where a predictable format is required.

3. Pre-image Resistance (One-Way)

Given a hash output h, it should be computationally infeasible to find any input m such that hash(m) = h. In practical terms, you cannot reverse-engineer the original data from its hash. This one-way property is what makes hashes useful for password storage, digital signatures, and proof-of-work mining.

4. Collision Resistance

It should be computationally infeasible to find two distinct inputs m1 and m2 that produce the same hash output. While collisions must exist mathematically (since the input space is infinite and the output space is finite), a secure hash function ensures that finding one requires an impractical amount of computation. For SHA-256, the expected effort to find a collision is approximately 2128 operations.

5. Avalanche Effect

A small change in the input should produce a dramatically different output. There should be no discernible relationship between similar inputs and their hashes. This property ensures that an attacker cannot incrementally approach a target hash by making small adjustments to the input.

Hash Functions Used in Major Blockchains

Blockchain Hash Function Output Size Primary Use
Bitcoin SHA-256 (double) 256 bits Block hashing, proof-of-work
Ethereum Keccak-256 256 bits State trie, addresses, signatures
Litecoin Scrypt 256 bits Proof-of-work mining
Zcash Equihash / Blake2b 256 bits Proof-of-work, privacy proofs

The Role of Hashes in Blockchain

Hash functions serve multiple critical roles within blockchain systems:

  • Block linking: Each block header includes the hash of the previous block, forming the chain. Any change to a historical block would alter its hash, breaking the chain from that point forward.
  • Transaction integrity: Each transaction is hashed and included in a Merkle tree. The root of this tree (stored in the block header) provides a single fingerprint for all transactions in the block.
  • Address derivation: In most blockchains, wallet addresses are derived from public keys through a series of hashing operations. For instance, an Ethereum address is the last 20 bytes of the Keccak-256 hash of the public key.
  • Proof-of-work: Mining in PoW systems is fundamentally a hashing competition. Miners repeatedly hash block header data with different nonce values until they find a hash that falls below a target threshold.
  • Data verification: Light clients can verify that a specific transaction is included in a block by requesting a Merkle proof—a set of hashes that, when combined with the transaction hash, reproduces the Merkle root.
SHA-256 vs. Keccak-256: While Bitcoin uses SHA-256 (a member of the SHA-2 family standardized by NIST), Ethereum uses Keccak-256. Keccak is the algorithm that won the NIST SHA-3 competition, though the version used in Ethereum predates the final SHA-3 standard and differs slightly in padding. This is why Ethereum documentation often refers to Keccak-256 rather than SHA-3.

Hashing in Practice: A Concrete Example

Suppose block #500,000 on a blockchain has the hash 0x7a3b.... Block #500,001 includes this hash in its header. When block #500,001 is itself hashed, the result (say, 0x9f1c...) is embedded in block #500,002. Now imagine an attacker changes a transaction in block #500,000. The hash of block #500,000 changes to something entirely different—say, 0x2d8e.... This no longer matches the reference stored in block #500,001, which invalidates block #500,001's hash, which in turn invalidates block #500,002, and so on for every subsequent block. The attacker would need to recompute every block from #500,000 onward, which is computationally prohibitive on any sufficiently decentralized network.

Key Takeaways

  • A cryptographic hash function maps arbitrary input to a fixed-size output with properties that make reversal and collision computationally infeasible.
  • The five critical properties are: deterministic output, fixed length, pre-image resistance, collision resistance, and the avalanche effect.
  • Hashes serve as the connective tissue of blockchain systems, linking blocks, summarizing transactions, deriving addresses, and powering consensus mechanisms.
  • Understanding hash functions is prerequisite to understanding nearly every other component of blockchain technology.

Related articles