Proof of Work: Hashing and Difficulty
The Concept
To understand mining precisely, you need to understand cryptographic hash functions. A hash function takes any input — a word, a file, an entire block of transactions — and produces a fixed-length output that looks like random characters, called a hash. Bitcoin uses a hash function called SHA-256. Three properties make it useful for mining:
- Deterministic: the same input always produces the same hash.
- One-way: given a hash, there's no shortcut to figure out what input produced it — you can only guess inputs and check.
- Avalanche effect: changing even one character of the input produces a completely different, unpredictable hash.
Mining works by repeatedly hashing a candidate block's header while changing one small piece of data called the nonce (short for "number used once"), searching for a resulting hash that is numerically below a target value — in practice, this means a hash starting with a certain number of leading zeros. Because of the one-way and avalanche properties, there's no clever shortcut to find a qualifying hash — miners must simply try nonce after nonce, as fast as their hardware allows, until one works.
The difficulty is how many leading zeros (roughly speaking) the network currently requires. The more zeros required, the exponentially rarer a qualifying hash becomes, and the longer, on average, it takes to find one. The next lesson explains exactly how the network adjusts this difficulty to keep block times steady near 10 minutes.
Input: "hello0" → hash: 2f8b9c1a... (doesn't start with 00)
Input: "hello1" → hash: 7d3e4f02... (doesn't start with 00)
Input: "hello2" → hash: a19cfe88... (doesn't start with 00)
...
Input: "hello41" → hash: 00e7b2d4... (starts with 00 — a "win"!)
What's Actually Inside a Block Header
The nonce isn't the only field miners can change while searching for a valid hash, but it's the simplest one to grasp. A block header also includes the previous block's hash (which is what links every block into a chain — change any earlier block and every hash after it changes too, thanks to the avalanche effect), a timestamp, the difficulty target, and a single hash summarizing every transaction in the block (called a Merkle root). Because the Merkle root changes if even one transaction in the block changes, miners can't quietly swap in a different set of transactions after finding a winning nonce — doing so would produce a completely different hash and force them to restart the search from zero. This is what makes proof of work a commitment to a specific set of transactions, not just a generic "proof of effort."
Worked Example
Imagine a toy puzzle: find a number N such that hashing the text "hello" + N produces a hash starting with "00". You don't know which N will work in advance — there's no formula to calculate it. So you try N = 0, hash "hello0", check the result. Not a match. Try N = 1, hash "hello1". Not a match. You keep incrementing and hashing until, say, N = 41 happens to produce a hash starting with "00".
Here's the key asymmetry: finding that N = 41 works might take you (or a computer) thousands of attempts. But once someone tells you "N = 41 works," verifying it takes exactly one hash computation — instant. This is exactly what happens at Bitcoin's scale: the global network collectively tries about as many guesses per second as it takes to find a winning block roughly every 10 minutes, but any single node can verify a submitted block's proof of work in a fraction of a second.
Requiring more leading zeros makes the puzzle harder exponentially, not linearly: requiring one leading zero digit means roughly 1-in-16 hashes qualify (hexadecimal); requiring two leading zero digits means roughly 1-in-256 qualify; three digits, roughly 1-in-4,096. Bitcoin's actual difficulty target requires far more than this, which is why real mining requires specialized hardware performing trillions of hash attempts per second. To make this concrete: at Bitcoin's real-world difficulty level in recent years, the network as a whole performs on the order of 500–600 exahashes per second (500–600 followed by 18 zeros) collectively, just to find one valid block roughly every 10 minutes.
Exercise
Below are ten pre-computed toy hashes. Circle (or list) which ones would satisfy a "must start with 0" difficulty rule:
1: 7a3f... 2: 0d91... 3: 4c22... 4: 09ab... 5: f001... 6: 0e4d... 7: a000... 8: 0021... 9: bb12... 10: 00c3...
(Answer: #2, #4, #6, #8, and #10 qualify — each starts with the digit 0. Notice #7 "a000" does not qualify, because the rule requires the hash to start with 0, not merely contain it.) Now imagine the rule tightened to "must start with 00" — cross out any of your qualifying answers that no longer meet this stricter bar, and notice how few remain. This is difficulty scaling in miniature. Finally, write one sentence explaining why the Merkle root field means a miner cannot swap in a higher-fee transaction after already finding a winning nonce without restarting the entire search.
Recap
- A hash function is a one-way fingerprint: easy to compute forward, practically impossible to reverse, with small input changes producing unpredictable output changes.
- Mining repeatedly hashes a block with a changing nonce until the output meets a difficulty target — expensive to find, instant to verify.
- This asymmetry converts electricity into unforgeable proof of effort, the foundation of Bitcoin's security model, explored further as difficulty adjustment in the next lesson.