How Does Blockchain Work?
Short answer: users sign transactions, the network checks them, a chosen node bundles them into a block, other nodes verify and accept the block through a consensus rule, and the block is linked to the chain by its hash. Each step makes cheating expensive.
Step-by-step life of a transaction
- Create: Sara wants to send 1 coin to Ali. Her wallet builds a transaction.
- Sign: the wallet signs it with Sara's private key. Anyone can verify the signature with her public key, but cannot forge it.
- Broadcast: the transaction is sent to nearby nodes, which pass it along.
- Validate: nodes check the signature and that Sara actually has enough balance and has not spent the coin already.
- Pool: valid transactions wait in a pool of pending transactions.
- Propose a block: a miner or validator groups pending transactions into a block.
- Consensus: the network agrees the block is valid (see below).
- Add to chain: every node appends the block, and Ali sees the funds.
- Confirmations: each later block built on top makes reversal less likely.
Hashing and linking
A hash function turns any data into a fixed-length fingerprint. A block stores its own hash and the previous block's hash:
Block 1: hash = H(data1, 000...)
Block 2: hash = H(data2, hash of Block 1)
Block 3: hash = H(data3, hash of Block 2)
If someone edits data in Block 1, its hash changes, so Block 2's stored reference no longer matches, and so on. An attacker would have to redo the work for all later blocks faster than the honest network adds new ones.
Merkle trees
Transactions inside a block are combined into a tree of hashes whose single top value (the Merkle root) is stored in the block header. This lets light clients prove a transaction is in a block without downloading everything.
Consensus mechanisms
| Mechanism | How a block is chosen | Trade-offs |
|---|---|---|
| Proof of Work (PoW) | Miners compete to solve a hard puzzle; the winner adds the block | Very secure, but energy-intensive and slower |
| Proof of Stake (PoS) | Validators lock up coins as a stake and are selected to propose and attest to blocks | Far less energy; dishonest validators can lose their stake |
| Permissioned (BFT-style) | Known validators vote | Fast, but trust is placed in the approved group |
A simple proof-of-work illustration
import { createHash } from 'node:crypto';
function mine(data, difficulty = 4) {
let nonce = 0;
while (true) {
const h = createHash('sha256').update(data + nonce).digest('hex');
if (h.startsWith('0'.repeat(difficulty))) return { nonce, hash: h };
nonce++;
}
}
console.log(mine('Sara pays Ali 1'));
The miner changes the nonce until the hash begins with enough zeros. Finding it is slow; checking it is instant. That asymmetry is the core of proof of work.
Forks and finality
Sometimes two valid blocks appear at nearly the same time. Nodes keep the longest (or heaviest) valid chain, and the shorter branch is dropped. This is why exchanges wait for several confirmations before treating a payment as final.
Why attacks are hard
- Forging a signature would require a private key.
- Rewriting history means redoing the work (or controlling the stake) for all later blocks.
- 51% attacks need control of most of the network's power. On large chains this is extremely expensive; small chains are more vulnerable.
- Double spending is detected because every node checks the shared history.
What a node does
Full nodes store the chain, validate everything independently and relay data. Because each node verifies the rules itself, you do not need to trust any single node.
Beyond payments
Chains like Ethereum also run programs, called smart contracts, as part of block processing; read smart contracts explained.
Next steps
Start with the overview in what blockchain is.
