Blockchain

A big file of bitcoin transactions

Diagram showing the blockchain as a file stored by nodes on the bitcoin network.
Current Blockchain Size:
650.57 GB
844,034 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: 844,034 (0 blocks away) ⇈
Next 0 blocks ↑
Height Block Hash Time (UTC) Size Txs Avg Fee Rate AFR
844,034 844,034 00000000000000000002ee18a68752b7ede948778ec9a0ba2b1a79b4a5ea0203 ago 1.37 MB 3,407 11
844,033 844,033 00000000000000000001eaebede6d98360326d48f0219311099a574707b4ca87 ago 1.18 MB 2,151 10
844,032 844,032 00000000000000000000b43f7abfb20b647a362213997806b3f9d80d517bfe0c ago 1.27 MB 2,226 10
844,031 844,031 00000000000000000001887266906c6f8240340f884865aed31ffe4c15d0d155 ago 1.50 MB 3,062 11
844,030 844,030 0000000000000000000014e1804035af74cb8843a664d0d2d578b7c151181c87 ago 1.69 MB 3,079 13
844,029 844,029 00000000000000000001fd09e640ed792e7512de3af125528d456685fe8972b2 1.58 MB 4,484 16
844,028 844,028 000000000000000000012728ef7a1136292a41ebc346bc7926ec0783c1dfbcd1 1.49 MB 5,875 23
844,027 844,027 00000000000000000003120f398d2982fc00e453f5d7b239421d7e06b0d4aca4 1.41 MB 6,709 28
844,026 844,026 00000000000000000002f24059cc2db8de431278e0deaa9778b9c4057484b648 1.38 MB 5,958 30
844,025 844,025 00000000000000000002b446551b724b72502d57ec8c42c134128bfa66690ee5 1.55 MB 4,360 14
844,024 844,024 000000000000000000031815523af7aac664242103fc29dd7a3aad3fd9f85482 1.48 MB 4,007 11
844,023 844,023 0000000000000000000362639531e79749469500851bdf225226e11f5b0914d0 1.44 MB 2,545 15
844,022 844,022 00000000000000000000974df7d569a88df274f1f1654997c78fac5a546d146f 1.64 MB 5,018 11
844,021 844,021 0000000000000000000209898d7a7167b88489913966283c32050ed2ecff2a59 1.58 MB 2,937 16
844,020 844,020 000000000000000000003fd2ff9256bafeadd85b2db03d2601ca1e41d857bebf 1.65 MB 4,365 12
844,019 844,019 0000000000000000000143c4b57e5cb81c111dad195e3e83470a1f46e2709cb4 1.63 MB 4,210 12
844,018 844,018 00000000000000000001c5160cd48406c57a2680301df79f65942066744dd074 1.58 MB 3,822 14
844,017 844,017 00000000000000000001ed59f072ff8c35886d6858f9057db77f54eb5d0b4196 1.62 MB 3,718 15
844,016 844,016 00000000000000000001dd7ee5ee7d4b71410e62446774a3bd819940299511c4 1.52 MB 3,166 16
844,015 844,015 000000000000000000001c0be8aade8b54eb7f25df50aafdcd2faf50c98c665e 1.39 MB 2,611 14
844,014 844,014 0000000000000000000077bb2ca8998b5ed2662293309ac7535bf4887edad51d 1.03 MB 281 9
Previous 10 blocks ↓
Total Size: 650.57 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