Episode 1: How Does a Blockchain Work?
Episode 1: How Does a Blockchain Work?*Before we talk about Bitcoin, we first need to understand how a blockchain works: What is a hash, how are blocks connected, and why does Proof of Work make later changes so difficult?*A blockchain is a chain of connected data blocks.
Its security does not come from encryption or a certificate. It comes from the way the blocks are connected and the enormous amount of work that would be required to change the chain without being detected.
To understand this connection, we begin with a hash.
The Hash
A short hash can be calculated from any content.
The hash is not generated randomly. It is determined by the content.
Example 1
Text Hello Anna!
Hash 3dcdffChange just one letter and the result is a different hash:
Example 2
Text Hello Anne!
Hash 2dededThe same content always produces the same hash. If the content changes, the hash changes as well.
This makes it easy to compare content.
Instead of comparing two large files in full, we calculate the hash of each file and compare only these two short values.
If the hashes are different, the contents are different as well. If the hashes are the same, we can assume with a very high degree of certainty that the contents are also the same.
The size of the content does not matter. A short text, a photo, and a huge file each produce a hash of the same fixed length.
A hash is therefore a short comparison value derived from the complete content.
The First Block
A block is initially just a container for data.
We can imagine it as a package. The actual data is inside the package, while the technical information about the block appears on a label.
Our first block contains the data “Hello Anna!”
Block 1
Data Hello Anna!
Previous hash –
Hash 3dcdffThe first block in a blockchain is called the genesis block.
Because no block exists before it, it has no previous hash.
The genesis block is the defined starting point of the blockchain. Using a different genesis block would create a different blockchain with its own chain.
A single block is not yet a blockchain. To create one, we need to connect several blocks.
Connecting the Blocks
We create a second block.
It contains its own data. We also write the hash of Block 1 on its label.
Block 2
Data Hello Anne!
Previous hash 3dcdff
Hash 2dededThe previous hash is not part of the actual data “Hello Anne!” It is a technical property of the block.
However, it is included when the new hash is calculated.
The hash of Block 2 therefore results from its data and the previous hash.
Now we add a third block:
Block 3
Data Hello Anna and Anne!
Previous hash 2deded
Hash 731be2Block 2 points to Block 1 with 3dcdff. Block 3 points to Block 2 with 2deded.
This creates a chain of connected blocks — a blockchain.
Verifying the Chain
The hash connections make the entire chain verifiable.
First, we calculate the hash of Block 1. We then compare the result with the previous hash stored in Block 2.
If both values match, the connection between Block 1 and Block 2 is correct.
Next, we calculate the hash of Block 2 and compare it with the previous hash stored in Block 3.
In this way, the complete chain is verified one block at a time.
Only if every connection is correct can the chain be traced continuously back to its genesis block.
What Happens If Something Is Changed?
Suppose the data in Block 2 is changed later.
The modified data produces a different hash.
At first, nothing happens. The change is only detected when the blockchain is verified.
The newly calculated hash of Block 2 no longer matches the previous hash stored in Block 3.
The connection between the two blocks is broken.
From this point onward, the chain can no longer be verified continuously. Block 2 and all following blocks can no longer be accepted as part of this valid chain.
The hash connections do not prevent a change. Initially, they only ensure that the change is detected during verification.
Are the Hash Connections Enough?
No.
The altered chain could be made consistent again.
To do that, the new hash of Block 2 would have to be written into Block 3.
This would change Block 3 and produce a new hash for it. That new hash would then have to be written into the next block.
This process would have to continue all the way to the end of the chain.
Because ordinary hashes can be calculated very quickly, this alone would not provide sufficient protection.
The blocks are therefore not only connected. Every block must also meet an additional condition.
An Additional Condition for Every Block
For our simplified blockchain, we define the following rule:
The hash of every block must begin with *00.*Only blocks whose hashes meet this condition may be part of our blockchain.
Our current hashes do not yet meet the condition:
Block 1 3dcdff does not begin with 00
Block 2 2deded does not begin with 00
Block 3 731be2 does not begin with 00The hash of a block results from its data and its technical properties. We cannot simply replace it with the hash we want.
To produce a hash that begins with 00, we must change something in the block and calculate the hash again.
The actual data must, of course, remain unchanged. We do not want to keep changing “Hello Anna!” until a different text happens to produce a suitable hash.
The block is therefore given an additional number.
This number is called the nonce.
The Nonce
The nonce has no meaning for the actual content. It is simply added to the block’s label and included when the hash is calculated.
For Block 1, we begin with the nonce 1.
First attempt
Data Hello Anna!
Nonce 1
Hash 74ac21The hash does not begin with 00. We therefore change only the nonce and calculate the hash again.
Second attempt
Data Hello Anna!
Nonce 2
Hash 936be8This hash does not begin with 00 either.
The nonce is changed repeatedly, and the hash is recalculated every time. The actual data remains unchanged.
After several attempts, we might find the nonce 183:
Block 1
Data Hello Anna!
Previous hash –
Nonce 183
Hash 00ab71This hash begins with 00. The genesis block now meets the additional condition of our blockchain.
The new hash of Block 1 is then written on the label of Block 2.
For Block 2, the nonce is also changed until a hash beginning with 00 is found.
The same process is then repeated for Block 3.
Our complete blockchain now looks like this:
Block 1
Data Hello Anna!
Previous hash –
Nonce 183
Hash 00ab71Block 2
Data Hello Anne!
Previous hash 00ab71
Nonce 4,927
Hash 003f92Block 3
Data Hello Anna and Anne!
Previous hash 003f92
Nonce 716
Hash 00c841Every block contains the hash of its predecessor. Every block also contains a nonce that causes its own hash to begin with 00.
The 00 condition applies to every block in the entire blockchain — including the genesis block.
What Does Proof of Work Mean?
A nonce that produces a hash beginning with 00 cannot be calculated directly.
Different nonces must be tried and their corresponding hashes calculated until the condition is met by chance.
Once a suitable nonce has been found, it is stored in the block.
Anyone can then calculate the block’s data, previous hash, and nonce once. If the result begins with 00, this proves that a suitable nonce was found for the block.
That is the Proof of Work.
Proof of Work means that the necessary calculations were performed for this block.
The proof is not a separate certificate. It is already contained in the block: in its data, its previous hash, the nonce that was found, and the resulting hash.
Finding a suitable nonce is expensive. Verifying the result is easy and requires only a single calculation.
How Much Work Is Required?
In our simplified blockchain, an average of only about 256 attempts is required to find a hash beginning with 00.
For a modern computer, this would be insignificant. Our 00 rule exists only to make the process understandable.
In a real blockchain, the condition can be set so high that finding a single block requires many billions upon billions of calculations.
This work must be performed separately for every block.
What Would Be Required to Manipulate the Chain?
Suppose once again that the data in Block 2 is changed.
The modified data, the previous hash, and the existing nonce produce a new hash. This new hash will most likely no longer begin with 00.
Block 2 therefore no longer meets the condition of the blockchain.
A new suitable nonce would first have to be found for the altered Block 2.
The change also gives Block 2 a new hash. Block 3, however, still contains the original hash of Block 2.
The new hash of Block 2 would therefore have to be written into Block 3.
This changes one of Block 3’s technical properties. Its existing nonce will now also no longer produce a hash beginning with 00.
A new suitable nonce would have to be found for Block 3 as well.
This process continues to the final block in the chain.
Anyone who wants to change Block 2 must therefore perform new Proof of Work for Block 2 and every following block.
The total effort is the Proof-of-Work effort for one block multiplied by the number of blocks that must be recalculated from the changed point onward.
The further back a changed block lies, the more blocks build on top of it and the greater the required effort becomes.
Why Is a Blockchain Considered Secure?
A blockchain is not secure because its data is encrypted. The data can be completely open and readable.
It is also not secure because a central authority certifies the blocks.
Its security is based on two connected properties:
Every block contains the hash of its predecessor. This makes the complete chain continuously verifiable.
In addition, every block must meet a condition for which a suitable nonce had to be found. Every block therefore contains verifiable computational work.
A change is not mathematically impossible. In a long blockchain, however, the required computational effort can become so great that completely recalculating the chain without being detected is practically impossible.
In Episode 2, we look at where this blockchain is stored, how its different copies are verified, and why not every computer has to keep every block forever.
Top comments (0)