Overview
A hash is the output of a hash function -- a fixed-size string of characters that uniquely represents an input of any size. In Bitcoin, hashes are used pervasively: to identify transactions, to link blocks together, to create the proof-of-work puzzle, and to derive addresses from public keys. The hash is often described as a "digital fingerprint" because even a tiny change in the input produces a completely different output.
Properties of a Good Hash
Input: "Hello" → SHA-256 → 185f8db32271fe25f561a6fc938b2e26...
Input: "Hello." → SHA-256 → 2d8bd7d9bb5f85ba643f0110d50cb506...
Input: "hello" → SHA-256 → 2cf24dba5fb0a30e26e83b2ac5b9e29e...
Key observations:
1. Fixed length: Always 256 bits (64 hex characters) regardless of input size
2. Deterministic: Same input always produces the same hash
3. Avalanche effect: Tiny input change → completely different hash
4. One-way: Cannot recover input from hash
5. Collision resistant: Practically impossible to find two different
inputs that produce the same hash
How Bitcoin Uses Hashes
Transaction IDs (TXIDs): Each transaction is identified by the double-SHA-256 hash of its serialized data. This provides a compact, unique identifier for every transaction.
Block hashes: Each block is identified by the double-SHA-256 hash of its 80-byte header. This hash must be below the current target for the block to be valid (proof of work).
Blockchain linking: Each block header contains the hash of the previous block, creating an unbreakable chain:
┌──────────┐ ┌──────────┐ ┌──────────┐
│ Block N │ │ Block N+1│ │ Block N+2│
│ │ │ │ │ │
│ Prev: ◄──┼────│ Prev: ◄──┼────│ Prev: │
│ Hash │ │ Hash │ │ Hash │
│ │ │ │ │ │
│ Merkle │ │ Merkle │ │ Merkle │
│ Root │ │ Root │ │ Root │
└──────────┘ └──────────┘ └──────────┘
Merkle trees: Transaction hashes are paired and hashed together repeatedly to form a Merkle tree, with the root hash included in the block header.
Address generation: Bitcoin addresses are derived by hashing public keys through SHA-256 and RIPEMD-160.
Hash Functions Used in Bitcoin
- SHA-256: Used for mining (double-SHA-256), transaction IDs, and Merkle trees
- RIPEMD-160: Used in combination with SHA-256 for generating shorter address hashes (HASH160)
- SHA-512: Used in HMAC-SHA512 for HD wallet key derivation
- SipHash: Used internally for hash table operations to prevent DoS attacks
Common Misconceptions
- A hash is not encryption. Encryption is reversible with the right key; hashing is a one-way process.
- While collisions (two inputs with the same hash) are theoretically possible, finding one for SHA-256 is computationally infeasible with current technology.
- The term "hash" in Bitcoin mining refers to a single attempt at computing the hash of a block header with a particular nonce value.