Skip to content
CryptoAcademy logo CryptoAcademy
Menu
Lesson Beginner

Blocks, Hashes and the Chain That Cannot Be Quietly Edited

In the last lesson you learned that a blockchain is a shared ledger that many computers keep in sync. But how does the chain part actually work? The answer is surprisingly simple: every block carries a digital fingerprint of the block before it. Change one old block, and its fingerprint no longer matches — and everyone can see it instantly. In this lesson we will open up a block, look at what is inside it, and build the intuition for why a blockchain cannot be quietly edited.

In this lesson

  • Describe what a block contains and explain the role of the block header
  • Explain a cryptographic hash function as a one-way digital fingerprint
  • Show why changing an old block would break every block that comes after it
  • Recognize why silent tampering is detectable by anyone on the network

What Is Inside a Block?

Think of a blockchain block like a page in a shared notebook that everyone can read. Each page has two parts:

  1. The header — a small summary box at the top of the page.
  2. The body — the list of transactions recorded on that page.

The block header is the part that matters most for security. It is a compact set of fields:

  • Previous block hash — the fingerprint of the block that came before it.
  • Merkle root — a single fingerprint summarizing all transactions in the body.
  • Timestamp — roughly when the block was created.
  • Nonce — a number miners change to try to solve the proof-of-work puzzle.
  • Difficulty target — how hard the puzzle is right now.
  • Block version — which rules the block follows.

Because the header contains the previous block hash, each block is literally glued to the one before it. That single field is the secret to the whole chain.

Anatomy of a block
A block contains a header with linking metadata and a list of transactions Block #840,123 ~10 minutes · Bitcoin BLOCK HEADER (80 BYTES) Previous block hash 0000000000000000…00d4b1f Merkle root a3f9c1…7c2e90 Timestamp 1758… (UTC) Difficulty target 0x1703… Nonce (the number miners change) 2,145,903,771 TRANSACTIONS (2,431) tx #1 Alice → Bob · 0.5 BTC tx #2 Carol → Dan · 1.2 BTC tx #3 Coinbase → Miner · 3.125 BTC Header hash = the block's fingerprint. Changing any field changes the hash and breaks the chain.
The header holds the previous block hash, the Merkle root, the timestamp and the nonce. The body holds the actual transactions.

A Hash Is a One-Way Digital Fingerprint

A cryptographic hash function takes any input — a word, a file, an entire block — and produces a fixed-length output called a hash (or digest). Bitcoin uses SHA-256, which always produces 256 bits, written as 64 hexadecimal characters.

Three properties matter here:

  1. Deterministic. The same input always gives the same hash. No randomness.
  2. Fast to compute, impossible to reverse. You can hash a gigabyte in milliseconds, but you cannot go from a hash back to the input.
  3. Avalanche effect. Change a single character of the input and roughly half of the output bits flip. There is no "close" hash.

Think of a hash like a fingerprint: it uniquely identifies a person, but you cannot reconstruct the person from the fingerprint. And no two people share one — unless someone tries very hard to fake it, which is what the avalanche effect prevents.

SHA-256 as a function

H : \{0,1\}^* \rightarrow \{0,1\}^{256}

Any input of any length maps to a fixed 256-bit output. The map is one-way and collision-resistant.

Example · One letter changes everything

Let's hash two almost identical sentences with SHA-256:

  • Input: The quick brown fox jumps over the lazy dog
  • Input: The quick brown fox jumps over the lazy cog

The only difference is the last letter (d vs g). The outputs look completely unrelated — there is no way to guess from one hash that the inputs were nearly the same. This is the avalanche effect in action. It is exactly why tampering with a block cannot be hidden: even a tiny edit produces a wildly different fingerprint.

Try hashing your own text

Type any sentence, change one letter at a time, and watch how the hash output completely changes each time. This is the avalanche effect you just read about.

Try it yourself

How a Block Seals the One Before It

Here is the trick that makes a blockchain a chain:

  1. Block 1 is created. Its header is hashed, producing hash H1.
  2. Block 2 is created. Its header includes H1 as the "previous block hash". Its own hash is H2.
  3. Block 3 includes H2. Its hash is H3.
  4. And so on.

Now imagine an attacker wants to secretly change a transaction inside Block 1. They edit the body. But the Merkle root in Block 1's header changes, so H1 changes. Since Block 2's header stores the old H1, Block 2 no longer matches. Its hash H2 also changes. That breaks Block 3, then Block 4, and so on to the tip of the chain.

To hide the edit, the attacker would have to redo the proof-of-work for every block after the edited one, faster than the honest network adds new blocks. On Bitcoin, that means out-computing thousands of machines — practically impossible. This is what people mean when they say the chain is immutable or tamper-evident.

Blocks linked by hashes
Blocks are linked by hashes; editing one block breaks every link after it Block n-1 hash 9c1a…f4 valid Block n hash 0007…b2 edited by an attacker Block n+1 hash 41de…09 valid Block n+2 hash 77b0…aa valid prev hash ✗ attacker edits a value → block hash changes The integrity cascade 1. Editing a transaction in block n changes its Merkle root → changes the header hash. 2. Block n+1 stores the old hash → the link is broken and the chain from n+1 on is invalid. 3. To stay valid the attacker must re-mine every later block — faster than the network grows them.
Each block header stores the hash of the previous block. Editing an old block invalidates every hash that follows.

A Tiny Python Blockchain

The code below builds a small chain of three blocks and then tries to tamper with the first one. Run it and watch the validation fail — this is the exact property we have been describing, in about 40 lines of Python.

mini_chain.py python
import hashlib, json


def sha256(text: str) -> str:
    return hashlib.sha256(text.encode()).hexdigest()


class Block:
    def __init__(self, index, data, prev_hash):
        self.index = index
        self.data = data
        self.prev_hash = prev_hash
        self.hash = self.compute_hash()

    def compute_hash(self):
        payload = f"{self.index}|{self.data}|{self.prev_hash}"
        return sha256(payload)


# Build three linked blocks
b1 = Block(1, "Alice pays Bob 5 coins", "0" * 64)
b2 = Block(2, "Bob pays Carol 2 coins", b1.hash)
b3 = Block(3, "Carol pays Dave 1 coin", b2.hash)
chain = [b1, b2, b3]


def is_valid(chain):
    for i in range(1, len(chain)):
        if chain[i].prev_hash != chain[i - 1].hash:
            return False, f"Block {chain[i].index} does not match previous hash"
        if chain[i].hash != chain[i].compute_hash():
            return False, f"Block {chain[i].index} hash does not match its contents"
    return True, "Chain is valid"


print(is_valid(chain))  # (True, 'Chain is valid')

# Now tamper with block 1
b1.data = "Alice pays Bob 5000 coins"
print(is_valid(chain))  # (False, 'Block 2 does not match previous hash')

A hash is not encryption

Hashing is one-way — you cannot "decrypt" a hash back to its input. Encryption is reversible with a key; hashing is not reversible at all. Do not confuse the two. Also, do not confuse tamper-evident with impossible to tamper: a chain can be rewritten if an attacker controls more than half of the network's mining power (a 51% attack) — it just becomes extremely expensive and obvious.

One Edit, Many Consequences

The table below shows what happens at each step when someone tries to quietly edit an old block. Notice how the damage cascades.

Step What the attacker does What everyone else sees
1 Change a transaction in Block 100 Block 100's Merkle root no longer matches its body
2 Recompute Block 100's hash Block 101 still stores the old hash of Block 100
3 Try to fix Block 101 Block 101's own hash changes, breaking Block 102
4 Keep fixing forward Every block up to the tip must be re-mined
5 Publish the rewritten chain Honest nodes reject it because it is shorter or has less work
Editing a normal database
  • Admin can change a row in place
  • No one may notice the change
  • Trust depends on the admin
  • Audit logs can be deleted
  • Cheap to alter
Editing a blockchain
  • Changing a block changes its hash
  • Every later block stops matching
  • Trust depends on the math
  • History is public and replicated
  • Requires redoing proof-of-work for every later block

Why this matters for wallets

When your wallet shows a balance, it is not asking a bank. It is reading the chain and verifying that the transaction history matches the hashes. If someone silently edited an old block, your wallet's verification would fail — which is why you can trust the number without trusting any single company.

Frequently Asked Questions

Can two different inputs produce the same hash?

<p>In theory yes — this is called a collision. For SHA-256, finding one on purpose would take more energy than exists on Earth. In practice, we treat hashes as unique fingerprints.</p>

If hashing is one-way, how do miners prove they did the work?

<p>They do not reveal the input — they reveal the block header itself. Anyone can hash that header and check that the result starts with enough zeros. The work is verifiable without being reversible.</p>

What stops someone from just re-mining all the blocks after an edit?

<p>Time and cost. To rewrite history, an attacker must redo the proof-of-work for every block since the edit faster than the honest network produces new blocks — which on a large network like Bitcoin is economically unrealistic.</p>

Does every blockchain use the same hash function?

<p>No. Bitcoin uses SHA-256, Ethereum uses Keccak-256, and other chains use different functions. The property that matters is the same: deterministic, one-way and avalanche-resistant.</p>

What is the Merkle root in the header for?

<p>It summarizes every transaction in the block into one hash. If any single transaction changes, the Merkle root changes, and so does the block hash — which is how one small edit breaks everything.</p>

Check Your Understanding

Check your understanding

Practice · server-graded
  • An attacker edits a transaction inside an old block. Why does this break the chain?

    1 pt

You now understand the core of blockchain security: hashes link blocks, and any edit breaks the link. In the next lesson, we will look at how you interact with this chain — through keys and wallets — and why losing your private key is very different from losing a password.

Share this page

Send this link to a friend, or scan the QR code to open it on your phone.