The Double-Hash Algorithm (HASH160)
The Double-Hash Algorithm (HASH160)
Bitcoin does not use a single hash for its addresses. Instead, it uses a specific sequence known as HASH160. This choice was a deliberate design decision by Satoshi Nakamoto to combine the strengths of two different cryptographic families.
1. The Sequence
The math behind a Public Key Hash is: $$PKH = RIPEMD160(SHA256(PublicKey))$$
-
Step 1: The raw bytes of the public key are put through the SHA256 algorithm. This produces a 32-byte output.
-
Step 2: That 32-byte output is immediately put through the RIPEMD160 algorithm. This produces the final 20-byte output.
2. Why two different algorithms?
Using two different hashing families (NSA-designed SHA and European-designed RIPEMD) provides a "Safety Net."
-
Cryptographic Heterogeneity: If a mathematical flaw is discovered in SHA256 in the future, the RIPEMD160 layer acts as a shield.
-
Collision Resistance: SHA256 is extremely strong against collisions, while RIPEMD160 is excellent for producing short, unique fingerprints.
3. The 20-Byte Sweet Spot
Satoshi chose 20 bytes (160 bits) as the final length.
-
2^160 is a number so large that it is impossible to find two different public keys that result in the same hash (a collision).
-
At the same time, it is small enough to keep the UTXO Set compact, allowing nodes to validate transactions faster.
4. Implementation in Scripts
In raw Bitcoin Script, this is represented by the opcode OP_HASH160.
- When a node sees
OP_HASH160, it automatically performs both SHA256 and RIPEMD160 on the item at the top of the stack.
| Algorithm | Developer | Output Size |
|---|---|---|
| SHA256 | NSA (USA) | 32 Bytes |
| RIPEMD160 | KU Leuven (Belgium) | 20 Bytes |
| Combined | HASH160 | 20 Bytes |
In the next section, we will look at the Space Efficiency of this hash.
TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation: