How Does a Lock Work?
One of the first concepts you encounter when studying blockchain is the hash function. It can seem intimidating at first, but once you understand the principle, you'll find yourself thinking: "How elegant."
Simply put, a hash function is a function that converts any data into a fixed-length string.
For example, when you run "Hello, world" through the SHA-256 hash function, you always get the same 64-character hexadecimal output:
Hello, world → a948904f2f0f...c1e4d8f0b9c6
Change just one character — "Hello, World" (capital W) — and you get a completely different result:
Hello, World → 03ba204e50d1...7e9f2d9c84b3
This dramatic change from a tiny input difference is called the Avalanche Effect.
The Four Core Properties of Hash Functions
1. Deterministic
The same input always produces the same output. Hash "blockchain" today or next year and you get the identical result, anywhere in the world. This is the foundation of verification.
2. One-Way (Preimage Resistance)
You cannot reverse-engineer the input from the output. Given only the hash value 8b1a99..., there is no way to recover the original data. Technically it's not mathematically impossible — but with SHA-256 there are 2²⁵⁶ possible combinations, far more than the number of atoms in the observable universe.
3. Fixed Output Length
Whether the input is 1 byte or 1 gigabyte, SHA-256 always outputs exactly 256 bits (64 hexadecimal characters). This property is what allows blockchain to manage data efficiently.
4. Collision Resistance
It is practically impossible for two different inputs to produce the same hash output. Finding a collision in SHA-256 would require running every computer on Earth for hundreds of billions of years.
Why Blockchain Relies on Hashing
Each block in a blockchain contains the hash of the previous block. Block 1's hash → included in Block 2 → Block 2's hash → included in Block 3…
Because of this structure, modifying any past block changes that block's hash, which immediately invalidates the next block (which contains that hash), which invalidates the block after that — a chain reaction that renders all subsequent blocks invalid.
To tamper with history, you would need to re-mine every block from that point forward — while tens of thousands of nodes around the world are simultaneously competing to add new blocks. This is, in practice, impossible.
Mining and the Hash
The reason Bitcoin mining is "hard" is precisely because of hashing.
To create a block, a miner must find a hash value that satisfies a specific condition — for example, "the hash must start with a certain number of zeros." The miner adjusts a number called a nonce (starting from zero, incrementing by one) and recomputes the hash until the condition is met.
Bitcoin's current difficulty requires the hash to begin with more than 20 consecutive zeros. Finding a nonce that satisfies this condition requires, on average, trillions of hash calculations. This is Proof of Work.
Crucially, verification is trivial. Once someone finds a valid nonce, anyone else can run the hash function once and immediately confirm whether the condition is satisfied. This asymmetry — hard to produce, easy to verify — is the key insight behind mining.
Hash Functions in Everyday Life
Hash functions were widely used long before blockchain existed.
Password storage: Websites don't store your password — they store its hash. When you log in, your password is hashed and compared to the stored value. Even if the database is breached, attackers don't learn the original passwords.
File integrity verification: The MD5/SHA checksums provided when downloading software are hash values. After downloading, compute the hash and compare it to the official value to confirm the file hasn't been tampered with.
Git version control: Every Git commit ID is a hash. Change a single character in the code and the commit hash changes completely.
Will SHA-256 Be Secure Forever?
The honest answer: if quantum computers become practical, it will need to be reconsidered.
Quantum computers can use Grover's algorithm to perform hash preimage searches in roughly the square root of the time classical computers require. For SHA-256, that reduces 2²⁵⁶ attempts to roughly 2¹²⁸ — still an astronomically large number, but theoretically weaker.
The cryptography community is already developing quantum-resistant algorithms, and the blockchain ecosystem is actively discussing corresponding upgrades.
If you want to experience hash functions firsthand, the Hash Function interactive module lets you change inputs and observe the avalanche effect in real time.