Blockchain

A big file of bitcoin transactions

Diagram showing the blockchain as a file stored by nodes on the bitcoin network.
Current Blockchain Size:
743.25 GB
893,125 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 reorganizations 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: 893,125 (0 blocks away) ⇈
Next 0 blocks ↑
Height Block Hash Time (UTC) Size Txs Avg Feerate AFR
893,125 893,125 0000000000000000000154ba8761cc956d8c2cd320d0ee09da24a41e523ee6c0 ago 1.45 MB 5,052 6
893,124 893,124 000000000000000000008211f3efd883759782c5e6aa05d607479f30c6fb95c0 ago 1.47 MB 4,890 5
893,123 893,123 000000000000000000008bde5f911f7330a8a8d529061dbf98a7d88efc31ed65 ago 1.58 MB 4,998 3
893,122 893,122 00000000000000000001f9d98e0db28905e672b5c59cc026f9b28b3ef9c8d780 ago 1.49 MB 4,707 5
893,121 893,121 00000000000000000001d1cbbcf15cf9b008c9e3a45fb2d4803d4a89ecba2a7b ago 1.50 MB 5,166 3
893,120 893,120 0000000000000000000050e077a0c99acfaea23ca93bc7b84418fb6b8841bc59 1.52 MB 4,566 5
893,119 893,119 00000000000000000000c0bf46356feea701fbf0ccf5d9946689360aace46adf 1.76 MB 3,476 3
893,118 893,118 0000000000000000000112121483092a181530f705f1e6e3522a110d2f231804 1.52 MB 4,114 4
893,117 893,117 00000000000000000002115e16262b609f88d36e528859a8d85bd1448c5d10b5 2.10 MB 497 2
893,116 893,116 00000000000000000001e36c52a835bff83dd3debabe2d58780f7fa26fa1afb6 1.48 MB 3,635 3
893,115 893,115 0000000000000000000116d1ad330e8d17824467ee4d1658b654d68d1102bb61 1.61 MB 3,835 3
893,114 893,114 00000000000000000001464e32059710b55f16ecb1bcfaaf60af9ec784ac8abc 1.52 MB 4,168 3
893,113 893,113 0000000000000000000135936430598e8c77187877c727abada1a9f5719d5851 1.77 MB 4,439 2
893,112 893,112 00000000000000000000a0f5d425560571c46e2e7b4cde2375eb899becf3da0c 1.67 MB 4,041 4
893,111 893,111 00000000000000000000c575d583d7f1b91005f99296b8dc575da0355cca77e9 1.62 MB 3,987 3
893,110 893,110 00000000000000000000963dc330e9bbe5c8739cab7f1fd42f274943c68bf71e 1.50 MB 4,295 8
893,109 893,109 000000000000000000006783de2875cf44bec4c75c584163e501a8f5aab21296 1.63 MB 4,424 3
893,108 893,108 000000000000000000020a96264033aad71a74dbee99bf1c2a09ed94d82329ff 1.52 MB 4,306 8
893,107 893,107 000000000000000000012e830461303b91938d9b1619b68a6da1cdc17aa17cf7 1.54 MB 4,261 8
893,106 893,106 000000000000000000015f7a3915a254a79cd53bb4b750d9f29f68ee525e8815 1.69 MB 4,941 3
893,105 893,105 00000000000000000001a066bca5bffd4cd27fe20bc46ac0f4758158d8cf38b7 1.66 MB 4,520 4
Previous 10 blocks ↓
Total Size: 743.25 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 into 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 Recalculator

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 Reorganizations

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 be built 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 reorganization to move out blocks from their old active chain in favor of blocks that make up a new longer chain.

Diagram showing a temporary fork in the blockchain being resolved via a chain reorganization.
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. This 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 top of 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 reorganization (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 into 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 reorganization.

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