Cryptographic Foundations

SHA-256 Explained

The one-way function that makes Bitcoin possible. Input anything, get a unique 256-bit fingerprint.

What is SHA-256?

SHA-256 (Secure Hash Algorithm 256-bit) is a hash function—a mathematical formula that takes any input and produces a fixed-size output. No matter if you input a single letter or an entire library, the output is always exactly 256 bits (64 hexadecimal characters).

256
Bits in output
64
Hex characters
2²⁵⁶
Possible outputs
Possible inputs

Try It Yourself

Type anything below. Watch the hash change instantly. Every input produces a completely different output—even changing a single character transforms the entire result.

Live Hash Generator

Type or paste any text and see its SHA-256 hash in real-time.

SHA-256 Hash:
Unique inputs hashed this session: 1

The Avalanche Effect

One of SHA-256's most important properties: tiny changes in input cause massive changes in output. This is called the "avalanche effect." Change one letter, one bit, one anything—and roughly half of all output bits flip.

Avalanche Demo

Compare two nearly-identical inputs. Watch how different their hashes are.

128/256 bits are different
There's no pattern. You cannot predict how the hash will change. This unpredictability is essential for Bitcoin's security.

One-Way Only

SHA-256 is easy to compute forward but impossible to reverse. Given an input, you can calculate the hash instantly. But given a hash, there's no way to figure out what input produced it—except by guessing.

Direction Difficulty Time
Input → Hash Trivial Microseconds
Hash → Input Impossible Longer than the universe

This asymmetry is what makes proof of work possible. Miners must guess trillions of inputs to find one that produces a hash meeting certain criteria. But once found, anyone can verify it with a single computation.

Always the Same

SHA-256 is deterministic: the same input always produces the same output. Always. Run it on any computer, any operating system, any time—identical input means identical hash.

Determinism Check

The hash of "Bitcoin" is always:

b4056df6691f8dc72e56302ddad345d65fead3ead9299609a826e2344eb63aa4

Try it above. Type exactly "Bitcoin" (capital B) and you'll get this exact hash. Every time. Forever.

Collision Resistance

A "collision" is when two different inputs produce the same hash. With 2²⁵⁶ possible outputs, finding a collision by chance is essentially impossible.

2²⁵⁶
Possible hashes
10⁷⁷
As a number
10⁸⁰
Atoms in universe

There are more possible SHA-256 outputs than atoms in the observable universe. The odds of accidentally finding two inputs with the same hash are so low that it has never happened and almost certainly never will.

Why Bitcoin Uses SHA-256

Bitcoin uses SHA-256 (actually double SHA-256) for several critical functions:

Use Case Why SHA-256
Mining / Proof of Work Miners hash block headers looking for outputs below a target. The one-way property means they must guess.
Block Linking Each block contains the hash of the previous block. This chains them together immutably.
Transaction IDs Every transaction has a unique ID derived from its hash. Determinism ensures everyone calculates the same ID.
Merkle Trees Transactions in a block are hashed into a tree structure, allowing efficient verification.
Address Generation Public keys are hashed (with other algorithms too) to create Bitcoin addresses.
SHA-256 is Bitcoin's foundation. Its properties—one-way, deterministic, avalanche effect, collision resistant—enable trustless verification. Without it, proof of work and blockchain immutability wouldn't be possible.
📌 TL;DR
SHA-256 is a one-way hash function that turns any input into a fixed 256-bit output. Change one character, the entire hash changes. It's easy to compute forward but impossible to reverse—making it perfect for Bitcoin's proof of work system.

Frequently Asked Questions

Can SHA-256 be reversed?

No. SHA-256 is a one-way function. Given a hash, there's no mathematical way to find the original input except by guessing—which would take longer than the age of the universe.

Has anyone found a SHA-256 collision?

No. With 2²⁵⁶ possible outputs (more than atoms in the observable universe), the odds of accidentally finding two inputs with the same hash are essentially zero.

Why does Bitcoin use SHA-256 twice?

Double SHA-256 (hashing the hash) helps prevent length-extension attacks and adds an extra layer of security. It's a simple change that makes the protocol more robust.

Next: Proof of Work →

Now that you understand hashing, see how Bitcoin uses it to secure the network through mining.

Next: Proof of Work →