BR Academy
0%
Blocks, Hashes, and Cryptography·Lesson 6 of 25·12 min

How Hashing Works

The Concept

A cryptographic hash function — SHA-256 is the one Bitcoin uses — takes any input, of any length (a single word, a photo, an entire block of transactions), and produces a fixed-length output that looks like random noise. For SHA-256, that output is always 256 bits, usually displayed as 64 hexadecimal characters, no matter whether the input was three letters or three gigabytes.

Three properties make this useful for blockchains:

  1. Deterministic. The same input always produces exactly the same output. Hash "Hello" today, next year, on a different computer — identical result every time. This is what lets every node in the network independently verify a block's hash matches, without any coordination.
  1. Avalanche effect. Changing even one character of the input — a single letter, a trailing space — produces a completely different, unrelated-looking output. There's no "partial match": the new hash shares no visible pattern with the old one. This is precisely what makes tampering detectable — you can't make a small edit and expect a small, hidden change in the hash.
  1. One-way (pre-image resistant). Given a hash output, there's no practical way to work backward and reconstruct the input that produced it, other than guessing inputs and hashing each one to see if it matches (computationally expensive at scale). You can verify an input matches a known hash almost instantly, but you can't reverse a hash into its input.

Put together: hashing turns any amount of data into a small, fixed-size "fingerprint" that's cheap to compute, impossible to fake convincingly, and that changes unpredictably if anything in the original data changes. That's exactly the property a block header needs (previous lesson) to detect any tampering in the chain instantly.

A fourth, related property worth naming is collision resistance: it should be computationally infeasible to find two different inputs that produce the same hash output. If collisions were easy to find, an attacker could craft a fraudulent transaction that hashes to the same value as a legitimate one and substitute it without detection. SHA-256's 256-bit output space is so astronomically large (2^256 possible outputs) that finding a collision by chance would, with current computing power, take longer than the age of the universe many times over — which is why "just brute-force a matching hash" isn't a realistic attack.

It's worth being precise about one common misconception: hashing is not encryption. Encryption is reversible by design (you encrypt a message, and the intended recipient decrypts it back to the original using a key). Hashing is deliberately one-way — there is no "unhash" operation, by key or otherwise. This distinction matters directly for the next module: a private key is kept secret and never hashed away, while transaction data gets hashed precisely because no one needs to "decrypt" a block — they only need to verify it matches.

Hash functions also show up well beyond their role in blocks. Many blockchain addresses (Module 3) are themselves derived by hashing a public key, which is one reason addresses look like unpredictable strings of characters rather than readable names. Password storage on well-built conventional websites uses the same one-way principle — your password is hashed before storage, so even the website operator can't "look up" your original password, only verify a guess against the stored hash. Recognizing this one pattern — fixed-size, deterministic, one-way, collision-resistant fingerprinting — will keep showing up throughout this course, from Merkle trees in the next lesson, to proof-of-work mining in Module 5, to how wallet addresses are generated in Module 3.

Worked Example

Hashing the string "Hello" with SHA-256 produces:

185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969

(This is illustrative of the format — a 64-character hex string — the exact output of any proper SHA-256 implementation for a given input is always identical.)

Now hash "Hello!" — just one character added. The output is completely different in every character, with no visual relationship to the first hash. There's no way to look at the two outputs and guess that the inputs were nearly identical. That unpredictability is the avalanche effect in action, and it's why altering a single transaction inside a block's body (previous lesson) cascades into a completely different Merkle root and header hash — the tampering can't be hidden or minimized.

Exercise

Find a free, reputable online SHA-256 tool (search "SHA-256 hash generator"). Hash your own first name, and record the 64-character output. Then hash it again with a single trailing space added (e.g., "Alex" vs. "Alex "). Compare the two outputs character by character and write one sentence describing how different they look, despite the input being nearly identical.

Then write one more sentence distinguishing hashing from encryption, in your own words, using the one-way property from the Concept section — specifically, what operation exists for encryption that has no equivalent for hashing.

Recap

  • A cryptographic hash turns any input into a fixed-size fingerprint — deterministic, unpredictable (avalanche effect), and one-way.
  • A tiny input change produces a totally different output, with no partial or hidden similarity.
  • This is the core building block that lets every node in a blockchain detect tampering instantly, without trusting a central authority.

Resources