Foundations · Blockchain

Blocks & Hashes

A block is a batch of transactions plus the hash of the previous block. A cryptographic hash is a fixed-length fingerprint of data, in which any change to the input changes the output.

  • Beginner
  • 5 min read
  • Updated

Why it matters

“Block” and “hash” are the two words inside “blockchain”, and the whole security of the structure comes from how they combine. Hashes also appear everywhere else in crypto: in addresses, transaction IDs and mining. A clear picture of both removes much of the mystery.

What a hash is

A small change in, a completely different hash out
AspectInputHash (shortened, made up)
OriginalPay Ana 103f9a...c21e
One digit changedPay Ana 11b07d...48a2
One capital letter changedpay Ana 10e654...0b9f
A far longer inputThe full text of a long book91c2...7d03
Illustrative values. Real hashes behave the same way: one character changed gives an unrelated result, and the output length never varies.

A cryptographic hash function takes any data and returns a short, fixed-length string of characters called a hash. It acts as a fingerprint of the data.

What a cryptographic hash function provides
DeterministicThe same input always gives the same output.
Fixed lengthA word or a library gives an output of the same size.
One-wayThe output cannot be run backwards to find the input.
SensitiveThe slightest change to the input changes the output completely.
Collision-resistantFinding two inputs with the same output is not practical.

Bitcoin uses a function called SHA-256. Its output is always 256 bits, usually written as 64 hexadecimal characters. Ethereum uses a different function, Keccak-256, with the same output size. The number of possible outputs is so large that two different inputs producing the same hash by chance is not a practical concern.

A hash does not hide or lock data, and it is not encryption. Nothing can be “decrypted” from it. Its use is comparison: if two pieces of data have the same hash, they are the same data, and if a stored hash no longer matches, something has been altered.

In plain words

A hash is like a wax seal pressed over the flap of an envelope. The seal tells you nothing about the letter inside. But if anyone opens the envelope and changes the letter, the seal breaks, and you can see that at a glance.

What a block is

Inside one block
Previous block hashThe fingerprint of the block before. This is the link in the chain.
Transaction summaryOne hash that stands for every transaction in the block.
Timestamp and consensus dataWhen the block was made, and proof that it was allowed.
TransactionsThe batch of transfers and contract calls themselves.
The first three items form the block header. Hashing the header gives the block's own hash.

A block is a batch of transactions with a small header on top. Exact fields differ between blockchains, but a header typically holds:

Field Purpose
Previous block hash Links this block to the one before it
Transaction summary A single hash representing all transactions in the block
Timestamp Roughly when the block was produced
Consensus data Evidence that the block was validly produced, such as a proof-of-work value

The block’s own hash is the hash of its header. Because the header contains the previous block’s hash, each block’s fingerprint depends on the block before it, and so on back to the first block, known as the genesis block. Bitcoin’s is described in genesis block and early history.

A block’s position in the chain is its height: the genesis block is height 0, the next is height 1, and so on.

Why chaining makes tampering visible

A chain of blocks
  1. Block 100Transactions + fingerprint of block 99
  2. Block 101Transactions + fingerprint of block 100
  3. Block 102Transactions + fingerprint of block 101
Each block stores the hash of the block before it. Changing an old block changes its hash and breaks every link that follows.

Suppose someone edits a transaction in an old block. The transaction summary changes, so the header changes, so the block’s hash changes. The next block still holds the old hash, so the link no longer matches. Repairing it means rebuilding that block too, and then the one after it, all the way to the newest.

On its own, re-hashing is quick for a computer. What makes the rebuild expensive is the consensus rule attached to each block. Under proof of work, every rebuilt block needs a fresh, costly computation. Under proof of stake, it needs signatures from validators who would be penalised for signing two histories. The hash chain makes tampering detectable. Consensus makes it costly.

Going deeper

The transaction summary. Transactions in a block are hashed in pairs, the results are hashed in pairs again, and so on until one hash remains. The structure is a Merkle tree and the final hash is the Merkle root. It lets a device prove that one transaction is in a block by checking a handful of hashes instead of downloading the whole block. Ethereum uses related tree structures for transactions and for account data.

Following a change through three blocksHypothetical illustration

A hypothetical chain, with hashes shortened to four characters for illustration.

  • Block 10: hash A1F3.
  • Block 11: previous hash A1F3, own hash 7C09.
  • Block 12: previous hash 7C09, own hash E2B8.

Someone changes “Pay Ana 10” to “Pay Ana 11” inside Block 11.

  • Block 11’s transaction summary changes, so its header changes, so its hash changes. Call the new hash 51DD.
  • Block 12 still records “previous hash: 7C09”. It no longer points to any block that exists.
  • To repair the chain, Block 12 must be rebuilt with “previous hash: 51DD”, which changes Block 12’s own hash, which breaks Block 13, and so on.

Every honest node holds the original chain and compares hashes automatically. The altered version does not match and is rejected.

What it does NOT mean

  • A hash is not encryption. It cannot be reversed to reveal the data, and it does not keep data secret.
  • A matching hash does not mean the data is true. It means the data is unchanged since the hash was made.
  • A hash chain does not prevent changes by itself. It exposes them. Resistance comes from the consensus rules and the spread of copies.
  • A block is not a file that someone approves by hand. Blocks are assembled and checked by software following fixed rules.
  • Being in a block does not mean being final immediately. Recent blocks can occasionally be replaced before the network settles.

Common misunderstandings

  1. Thinking hashes can be “cracked” to recover data. The function discards information. There is nothing to decode.
  2. Confusing a block hash with a transaction hash. One identifies a block, the other a single transaction inside it.
  3. Believing old data is deleted. Blocks are added, never removed, so the ledger only grows.

Risks and limits

  • Hash functions are trusted because no practical weakness has been found, not because safety is proven for all time.
  • Anything written into a block is permanent and public on an open chain.
  • The ledger grows without end, which raises the cost of running a full node over time.
  • A hash chain kept by a single party offers little protection, since that party can rebuild it at will.

Key takeaway

A hash is a fixed-length fingerprint that changes completely when its input changes. A block is a batch of transactions that carries the previous block’s hash, so altering any old record breaks every link after it.

Sources and further reading