Blockchain

A big file of bitcoin transactions

Diagram showing the blockchain as a file stored by nodes on the bitcoin network.
Current Blockchain Size:
647.70 GB
842,511 blocks
Note: This is the size of the blockchain for my local node.
The size of your blockchain will differ depending on how many chain reorganisations your node has experienced and how many stale blocks you have stored on disk.

The blockchain is a file of transactions. It's the most important file that a bitcoin node maintains.

It is called the "blockchain" because new transactions are added to the file in blocks, and these blocks are built on top of one another to create a chain of blocks. Hence, blockchain.

But ultimately, the blockchain is permanent storage for bitcoin transactions.

Live Bitcoin Blockchain:

Tip: 842,511 (0 blocks away) ⇈
Next 0 blocks ↑
Height Block Hash Time (UTC) Size Txs Avg Fee Rate AFR
842,511 842,511 00000000000000000001c6fa19e010f72e18d2923ee51eadd6aef58441f00dc6 ago 1.60 MB 3,253 36
842,510 842,510 000000000000000000015a0962b2a962f6f37fe6832782d4ffba8e57d2bffe7c ago 1.79 MB 3,058 25
842,509 842,509 000000000000000000017fe1355064885bdb5971693fffa969602f9e5137ca3a ago 2.13 MB 4,531 14
842,508 842,508 000000000000000000025695a7f1a3e77c8c70214c27d63565e79877d370989e ago 1.93 MB 3,090 20
842,507 842,507 00000000000000000002758b62e8bbf387992536ffade5a766f259f79267e241 ago 1.95 MB 2,482 21
842,506 842,506 0000000000000000000154e9ffa5e8b4baa315ec8795d1c38fe8a5fc258d5439 1.93 MB 2,259 23
842,505 842,505 0000000000000000000067de0772343a629d1e23eb0625f0944458518658c03c 1.59 MB 1,839 23
842,504 842,504 00000000000000000001d5f8e044a172c69e0d4a5c336bc6e39e3b4fc8f3b73c 1.60 MB 2,516 36
842,503 842,503 000000000000000000014871fbb7901615e708b28fa427867b1fe46db76a9683 1.60 MB 3,113 34
842,502 842,502 000000000000000000010f61ae2ddbac9085e975a12e77d900e1640bbcc70bbb 2.07 MB 2,794 22
842,501 842,501 0000000000000000000243eb195d63ca7282c30e58a66caefff7f6db0eff6bc2 2.06 MB 2,968 15
842,500 842,500 00000000000000000002af9971cc8dbe439e211cb1a4ccb8feeb14c1f8c33ca2 1.85 MB 1,814 20
842,499 842,499 000000000000000000027bc6ea15a75beaa648ad6107f5bc6eb30b91c1af4542 1.72 MB 2,538 22
842,498 842,498 000000000000000000023edfeecf2c206a750e0eba4b7eda2cb22186216ad739 1.60 MB 2,827 22
842,497 842,497 00000000000000000002ac58211652461ed0e490e5119a22e7acda1f8ced2c21 1.57 MB 2,930 27
842,496 842,496 00000000000000000002afd44a67a0b85596c56d38b8d4c5c0f0386c09fb5c81 1.57 MB 3,223 40
842,495 842,495 00000000000000000001a6c7110b453f369db51cbcb2d108f6909de4460fa6c8 1.58 MB 3,330 32
842,494 842,494 0000000000000000000182474c2064fa544eabaa4dc9be723f8dfe8b8435adc4 1.52 MB 3,192 45
842,493 842,493 00000000000000000001242a35b4ef7a10d533fffeae30f3593c68a4136adcb4 1.62 MB 3,064 23
842,492 842,492 0000000000000000000274bdcf451d76268824b349cd8a7458a7fa814e9c3fa8 1.62 MB 2,969 35
842,491 842,491 00000000000000000000d25bf1ded22f390e7c8cf45c443f1831e58159d4b33b 1.53 MB 3,288 46
Previous 10 blocks ↓
Total Size: 647.70 GB

Download

How do you get a copy of the blockchain?

Diagram showing the blockchain being downloaded from other nodes on the network.

The easiest way to get a copy of the blockchain is to run a Bitcoin node.

When you run the Bitcoin program (e.g. Bitcoin Core) your node will automatically download blocks from other nodes on the network until you have an up-to-date copy of the blockchain on your computer.

When nodes connect to each other, they tell each other the height of their chain (how many blocks they have) during the initial handshake. If another node has more blocks than you, your node will request these blocks from the other nodes until you have a full copy of the blockchain.

As a result, nodes are constantly communicating with each other to replicate the blockchain across every computer on the network.

There is no single or definitive version of "the blockchain". Every node keeps their own local copy of the blockchain, and it can vary from computer to computer at any given time.

It can take a while to download the full blockchain when you run Bitcoin for the first time. This is referred to as the Initial Block Download (IBD).

Mining

How are new blocks added to the blockchain?

Diagram showing the a block being mined on to the blockchain by a node on the network.

New blocks of transactions must be mined on to the blockchain.

In short, the process of mining involves collecting transactions from the memory pool in to a candidate block, and then using processing power to produce a block hash that is below a specific target value. This means that any node on the network can mine a new block, but you need to use energy to be able to do so.

Block Hash
Target Recaluclator

When a node (or "miner") successfully mines a new block, they will share it with the other nodes on the network. When other nodes receive this new block, they will add it to their blockchain, and miners will start trying to mine a new block on top of it.

Diagram showing a newly-mined block being propagated to other on the network.

As a result, miners are constantly working to extend the blockchain with new blocks of transactions.

Here's a video on how mining works in Bitcoin.

Chain Reorganisations

Can two blocks be mined at the same time?

As the blockchain is being built, it's perfectly normal for two blocks to be mined at the same time.

Diagram showing a temporary fork in the blockchain due to two blocks being mined at the same time.
If two blocks are mined at the same time it will cause a temporary "fork" in the chain.

In this situation, nodes will consider the first block they receive as part of their blockchain, but also keep the second block they receive just in case. However, the second block to arrive (and the transactions inside it) will not be considered as part of their active blockchain.

Consequently, nodes on the network will be in temporary disagreement about which of these two blocks belongs at the top of the chain.

This disagreement is resolved when the next block is mined. The next block will build on top of one of these blocks, creating a new longest chain of blocks, and as a rule nodes will always adopt the longest known chain of blocks as their active blockchain.

As a result, nodes with the shorter chain will perform a chain reorganisation to move out blocks from their old active chain in favour of blocks that make up a new longer chain.

Diagram showing a temporary fork in the blockchain being resolved via a chain reorganisation.
A fork is resolved when a new block is mined, as this will create a new longest chain.

So although there may be disagreements across the network about which block(s) belong at the top of the blockchain at any given time, the mining of new blocks and the adoption of the longest chain means that nodes will always eventually be in sync.

A temporary fork like this is rare. It happens about once a month (roughly), and usually only affects the top block on the blockchain.

Longest Chain

Can blocks in the blockchain can be replaced?

Due to the way the blockchain is built, it's possible for blocks at the top of the chain to be replaced.

Nodes always adopt the longest chain as the "true" version of the blockchain. Therefore, you could always try and build a new longer chain of blocks to replace an existing one, and every node on the network will adopt it.

As a result, this allows you to "undo" or reverse a bitcoin transaction from the blockchain.

Diagram showing nodes on the network adopting the longest chain of blocks as their blockchain.
If you build a new longest chain of blocks, other nodes will adopt it as their blockchain.

However, the problem is that all miners are incentivized to always be building on to the longest known chain. This means that the combined processing power of miners on the network will be focused on building one single chain, which will be built faster than any chain you could build on your own.

Diagram showing nodes on the network adopting the longest chain of blocks as their blockchain.
Miners naturally work to extend the current longest chain.

In other words, the combined processing power of the network working to build the blockchain helps to protect blocks (and transactions) that have already been mined on to the blockchain.

So the only way you could perform an intentional chain reorganisation (to "undo" a transaction in an existing block) would be to have more processing power than every other miner combined so that you could out-mine the network and build a longer chain for everyone to adopt. This is referred to as a "51% Attack".

Nobody has performed a successful 51% attack on the Bitcoin blockchain.

Location

Where is the blockchain stored?

If you're running a Bitcoin Core node, the blockchain files can be found in the following location on your computer:

The blockchain is split in to multiple files named blk00000.dat, blk00001.dat, blk00002.dat, and so on. This is because it's easier to work with multiple small files than it is to work with one giant file. See blk.dat for details.

Summary

Diagram showing a blockchain being built by nodes across a network of computers.
Click on the image to see a nice and slow visualization of a blockchain being built over time, including a chain reorganisation.

The blockchain is permanent storage for bitcoin transactions. New transactions are added to the file in blocks, and these blocks are built on top of each other to create a chain.

New blocks are added to the blockchain through mining, which involves the use of computer processing power. This means it takes energy to mine a block, but any node can work to try and add the next block on to the chain.

When a new block is mined, it will be relayed across the network, which nodes will verify and add on to their chain. This makes the blockchain a constantly growing ledger of transactions, distributed across multiple computers on a network.

Nodes always adopt the longest chain of blocks as the active version of the blockchain, which resolves disagreements about which blocks belong at the top of the chain. This also protects blocks that are already in the blockchain, as it would require large amounts of energy to build a chain that replaces blocks lower down in the chain.

The mechanism of mining and adopting the longest chain allows multiple computers over a network to agree on the same set of blocks and transactions, whilst also making it difficult for anyone to make historic changes to the blocks (and therefore transactions) in the blockchain.

As a result the blockchain is a secure, distributed, and regularly updated file of transactions.

Resources