Hash Function

A one-way function that turns any input into a fixed-length fingerprint, the backbone of mining and commitments.

Basically

A hash function turns data into a fixed-length result. You cannot work backwards from that result to find the original data.

Key Takeaways

  • A hash function takes any input and produces a fixed-size output called a digest. The same input always produces the same output, but changing one character produces a completely different result. You can use hashes to verify data integrity across peer-to-peer networks.
  • Bitcoin relies on two primary hash functions: SHA-256 for mining and transaction IDs, and RIPEMD-160 for compact wallet addresses. Together, they secure everything from proof-of-work consensus to payment verification.
  • Hash functions are computationally one-way. Computing a hash from an input is trivial, but working backwards from the hash is infeasible. This asymmetry powers Bitcoin mining, Merkle trees, and Lightning Network payment routing.

What Is a Hash Function?

A hash function is a mathematical algorithm that converts an arbitrary amount of data into a fixed-size string of characters called a hash, digest, or fingerprint. The output always has the same length, whether the input is a single byte or an entire book. SHA-256, the most widely used hash function in Bitcoin, always produces 256 bits (32 bytes), typically represented as a 64-character hexadecimal string.

Cryptographic hash functions are a specific class designed to resist deliberate manipulation. Unlike general-purpose hash functions used for data indexing, cryptographic hashes must satisfy strict security properties for authentication, integrity verification, and digital signatures. Bitcoin's entire security model depends on the strength of these properties.

Hash functions are deterministic, so the same input always produces the same output, no matter when or where the computation runs. Every node in the Bitcoin network can therefore independently verify every transaction and block without trusting any other participant.

How It Works

A cryptographic hash function must satisfy five core properties to be considered secure. Breaking any of these properties would undermine the systems built on top of it.

The Avalanche Effect in Practice

A simple demonstration shows how dramatically hash outputs change after minimal input modifications. Even a small edit produces a very different output.

Changing a single character from uppercase to lowercase produces an entirely unrelated hash. No mathematical shortcut can predict the new output, so you must compute it from scratch.

Hash Functions in Bitcoin

Bitcoin uses hash functions in two standard compositions. Each composition serves a different purpose.

Proof-of-Work Mining

Bitcoin mining is fundamentally a hash function race. Miners repeatedly hash a block header with different nonce values, searching for an output below the network's current difficulty target. Hash functions are pre-image resistant, so brute-force trial and error is the only way to find a valid hash.

The Bitcoin network's combined hashrate exceeded 800 exahashes per second (EH/s) as of 2026. Miners collectively computed over 800 quintillion SHA-256 hashes every second. This massive computational effort secures the network against 51% attacks by making it prohibitively expensive to rewrite transaction history; for a deeper analysis, see the Bitcoin mining economics research.

Transaction Identification

Every Bitcoin transaction is identified by its transaction ID (txid), which is the double SHA-256 hash of the serialised transaction data. Any modification, even a single byte, produces a completely different txid. Nodes use these IDs to reference transactions across the network, build the UTXO set, and detect tampering.

Merkle Trees

Each Bitcoin block organises its transactions into a Merkle tree. Each leaf node in this binary tree is the hash of a transaction, each parent node is the hash of its two children, and the Merkle root is included in the block header. Lightweight clients can use this structure to verify that a specific transaction is included in a block by downloading only a small Merkle proof rather than the entire block.

Address Generation

Bitcoin addresses are derived from public keys through hashing. For legacy addresses, HASH160 applies SHA-256 followed by RIPEMD-160 to the public key, producing a 20-byte hash that is then encoded with a checksum. The process is irreversible, so an attacker who knows a Bitcoin address cannot determine the underlying public key, which is only revealed when the owner spends from that address.

Lightning Network Payments

The Lightning Network uses hash functions to create hash time-locked contracts (HTLCs). A payment sender locks funds behind a payment hash, and the receiver must reveal the corresponding preimage, the original input that produces that hash, to claim the funds. Hash functions are one-way, so only the party that generated the preimage can settle the payment, enabling trustless multi-hop payments across the network.

SHA-256 Compared to Other Hash Functions

SHA-256 is not the only cryptographic hash function in use. It remains the standard for Bitcoin when compared with alternatives.

SHA-3 was selected by NIST in 2012 as the successor to SHA-2. SHA-256 remains unbroken and is deeply embedded in Bitcoin's consensus rules, so changing Bitcoin's hash function would require a hard fork with unanimous network agreement. That makes it one of the most stable aspects of the protocol.

Why It Matters

Hash functions are the cryptographic bedrock of Bitcoin. Without them, there would be no way to create proof-of-work, generate addresses from public keys, identify transactions, or build the Merkle trees that enable lightweight verification. Every block mined, every address generated, and every Lightning payment routed depends on the one-way nature of cryptographic hashing.

Developers building on Bitcoin Layer 2 solutions like Spark also rely on hash functions. Spark uses cryptographic commitments and hash-based verification to enable off-chain transactions that can be trustlessly settled on Bitcoin's base layer, while the same pre-image resistance that secures mining also secures HTLCs, commitment transactions, and the atomic swap mechanisms that connect on-chain and off-chain systems. The Spark Layer 2 overview provides more information.

Quantum Computing Threats

Quantum computers pose a theoretical risk to hash functions through Grover's algorithm, which can search an unsorted database quadratically faster than classical computers. For SHA-256, this effectively halves the security level from 256 bits to 128 bits, although 128-bit security remains strong by current standards. The cryptographic community monitors quantum progress closely, and Bitcoin's double-hashing construction (HASH256) provides additional margin; for a deeper analysis, see the post-quantum cryptography research.

RIPEMD-160 Concerns

RIPEMD-160 has a 160-bit output, providing approximately 80 bits of collision resistance. No practical attacks exist, but this security margin is narrower than SHA-256's. Modern Bitcoin address types introduced with SegWit and Taproot continue to use HASH160 for backward compatibility, but newer proposals explore alternatives that rely solely on SHA-256 for address derivation.

Hardware Centralisation

SHA-256's suitability for ASIC implementation has led to highly specialised mining hardware. This increases network security through raw hashrate, but it also concentrates mining among operators who can afford dedicated equipment. The trade-off comes from the hash function choice rather than a flaw, since ASIC-resistance in other algorithms often leads to different centralisation vectors.

Irreversibility by Design

The one-way nature of hash functions means that lost private keys cannot be recovered from addresses or public keys. If you lose your seed phrase and have no backup, the funds at hash-derived addresses are permanently inaccessible. The same property that protects you from attackers also prevents recovery, which is an inherent trade-off of hash function security.

This glossary entry is for informational purposes only and does not constitute financial or investment advice. Always do your own research before using any protocol or technology.

0

← All 1876 glossary terms