SHA-256 is the hash function that powers Bitcoin. You've already seen what a hash function does — now let's look at SHA-256 specifically: why Satoshi chose it, how it processes data internally, and why it's still considered secure while older algorithms like MD5 and SHA-1 have been broken.
Type anything below and watch the SHA-256 digest update in real time. Notice that the output is always exactly 64 hex characters — that's 256 bits — regardless of whether you type one word or a whole paragraph.
Not all hash functions are created equal. MD5 and SHA-1 were once the industry standard — until researchers found ways to create collisions (two different inputs with the same hash). Once a hash function is broken, it cannot be used to secure financial history. Satoshi chose SHA-256 because it was the strongest standardised option available in 2008, and it remains unbroken today.
You don't need to implement SHA-256 yourself — you'll always use an audited library. But understanding the processing model helps you reason about performance and protocol choices: why inputs are padded, why processing happens in 512-bit blocks, and where that 256-bit output comes from.
| Aspect | SHA-256 | Keccak-256 |
|---|---|---|
| Internal design | Merkle-Damgård construction | Sponge construction (different family) |
| Output size | 256 bits (32 bytes) | 256 bits (32 bytes) |
| Standardised as | SHA-2 family (FIPS 180-4) | SHA-3 family — but Ethereum uses pre-standard padding |
| Used in | Bitcoin: PoW, Merkle root, double-SHA256d | Ethereum: address derivation, storage slots, events |
| Status | No known practical attack | No known practical attack |
| Speed | Fast; hardware acceleration (SHA-NI) | Fast; slightly different performance profile |
import hashlib
# Standard SHA-256:
digest = hashlib.sha256(b'Hello Bitcoin').hexdigest()
print(digest) # 64 hex characters, always
# Double SHA-256 (SHA-256d) — used in Bitcoin:
inner = hashlib.sha256(b'Hello Bitcoin').digest() # raw bytes, not hex
sha256d = hashlib.sha256(inner).hexdigest()
# Keccak-256 — used in Ethereum (NOT standard SHA-3):
from Crypto.Hash import keccak # pip install pycryptodome
k = keccak.new(digest_bits=256)
k.update(b'Hello Ethereum')
print(k.hexdigest()) # Different from SHA-256 of same input