Blockchain

A big file of bitcoin transactions

Diagram showing the blockchain as a file stored by nodes on the bitcoin network.
Current Blockchain Size:
657.52 GB
847,853 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: 847,853 (0 blocks away) ⇈
Next 0 blocks ↑
Height Block Hash Time (UTC) Size Txs Avg Fee Rate AFR
847,853 847,853 00000000000000000001f209c9e4074dc6cbe1857105bfe3bc8e8249f2256237 ago 1.44 MB 5,806 69
847,852 847,852 00000000000000000002e26533da82196bf9b2fbac516cc2e692e0a08739272a ago 1.47 MB 6,393 57
847,851 847,851 00000000000000000001bf1aaa7ce2d33fd1e01c2fbbef8ea2a79890a5509c6a ago 1.47 MB 6,021 72
847,850 847,850 00000000000000000002a6b2cf7169de3cbaeb996807942be5e264c3e5a7740c ago 1.46 MB 5,771 81
847,849 847,849 0000000000000000000042613bb47ecfd5ff53930df02463dd4269a4f9f09e49 ago 1.07 MB 786 97
847,848 847,848 00000000000000000001fbff16e137d8878a5406d260927018da7606510f5865 1.13 MB 1,385 93
847,847 847,847 00000000000000000002dc684315cb287ad3f1f52e590444bcc628973d43ce45 1.45 MB 6,817 86
847,846 847,846 000000000000000000019fd2f35f21a8f8d2e821f023de2e216a7e17e9ae64f8 1.43 MB 6,027 88
847,845 847,845 000000000000000000027181d55de8ac436a7c4ec6049329d5f653b9e3cc592c 1.42 MB 6,120 64
847,844 847,844 000000000000000000011cab1c6f804ce64a216cf2961c2014b0e930e7ab6a7e 1.53 MB 6,451 28
847,843 847,843 00000000000000000000e332d8137146de1741782254877f41c3600df9cb128b 1.46 MB 5,332 30
847,842 847,842 000000000000000000030a2c1639fdd0abcafc5671fa327a18bc36104df5a2f8 1.49 MB 6,422 26
847,841 847,841 00000000000000000000b36ff52470ac51495a87e1f386ab21ac1ef3eb24d91a 1.52 MB 5,625 30
847,840 847,840 00000000000000000003041d0e77cc604cf0afb83377674419d5e0962ed6540d 1.46 MB 7,377 26
847,839 847,839 00000000000000000001cd8eedc9aa1726dbce3cd70757b8ab307bf12321bded 1.52 MB 4,052 35
847,838 847,838 000000000000000000025c0634d020af85a846d33acceffb5d6c9456f3328f64 1.46 MB 5,749 30
847,837 847,837 000000000000000000029c2842e5481bae3fb199f419d255b82826da2ef3405d 1.49 MB 7,138 27
847,836 847,836 00000000000000000000c3065263728083c44b4971904b872b421a2917a7e006 1.51 MB 4,573 32
847,835 847,835 00000000000000000003106b089dcef88a7a5c85b44831f87ba458f77b21349c 1.48 MB 5,764 30
847,834 847,834 00000000000000000002950919cdaf20a9d99d1218de03d4c50e62e4d82a0529 1.47 MB 5,982 28
847,833 847,833 000000000000000000021cb5aedc52f136391dd6c39c7800b0c76975f2e59cbd 1.49 MB 5,289 31
Previous 10 blocks ↓
Total Size: 657.52 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 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