Blockchain

A big file of bitcoin transactions

Diagram showing the blockchain as a file stored by nodes on the bitcoin network.
Current Blockchain Size:
763.91 GB
904,828 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: 904,828 (0 blocks away) ⇈
Next 0 blocks ↑
Height Block Hash Time (UTC) Size Txs Avg Feerate AFR
904,828 904,828 0000000000000000000039ec409e6c7f09de7873e919a9d4d2e6ecd5345f1359 ago 1.64 MB 3,885 3
904,827 904,827 0000000000000000000176973d48e137bcfa3c7c25975ec95379b67263a443e0 ago 1.73 MB 4,312 3
904,826 904,826 00000000000000000001f05e1c2f3ffcbcbb3adf5f6bb7b0aad6a59c5a9eeb32 ago 1.63 MB 3,713 5
904,825 904,825 00000000000000000000badb0026926ba98b30dfb966506dee84e4698d38e789 ago 1.59 MB 3,653 4
904,824 904,824 000000000000000000004076383a25b6bb36c86cce1a5c01589ea9f21a359a1d ago 1.30 MB 1,742 1
904,823 904,823 000000000000000000008d72c0520f6ccdafffee6484fb0eda0eeedf99bb8ede 1.78 MB 2,975 2
904,822 904,822 00000000000000000002263eb71e24b8a739ef868697b28c7cb1823809b2f1b4 1.53 MB 3,595 5
904,821 904,821 0000000000000000000061585fa370468fdf3a38baff9d85a432bff6209ac967 1.98 MB 3,113 2
904,820 904,820 000000000000000000013d69ac9d0babba993d996f70a904c32bd6835892a9b8 1.80 MB 2,710 2
904,819 904,819 00000000000000000000f317b9ee5d828dc82c9ade705f1a26f6d16591572faa 2.11 MB 2,537 1
904,818 904,818 0000000000000000000016465c17bae02ea828db7022fd00a59c8a5e959bd681 1.55 MB 2,893 3
904,817 904,817 000000000000000000000826bb9ead728bf705f9dd701ab794dc6afd11469f90 1.15 MB 2,026 2
904,816 904,816 000000000000000000011d791696f8768796d7071f142288398824d055464012 1.66 MB 2,348 2
904,815 904,815 0000000000000000000182b9ad93fe8070f3f0f736ec3a9b1ec611686070dcf3 0.21 MB 420 1
904,814 904,814 00000000000000000000278f4813979d88f19281048051d35f2302c1c466ec72 2.15 MB 3,488 1
904,813 904,813 000000000000000000024caa0d256c29496e73743a9366f8e001d924091fc966 1.89 MB 1,239 1
904,812 904,812 00000000000000000001f3d19867c436713d579cd2d951f342f6b2e9e0ab5d0d 1.56 MB 1,612 2
904,811 904,811 00000000000000000001521b7495133125cd2e2edabb3d3862d99bc9682a9e8e 1.63 MB 3,429 4
904,810 904,810 00000000000000000001a72dd0bf179182f30c9260cae6ba5ddffcdec47b176a 1.45 MB 2,238 3
904,809 904,809 000000000000000000023d9805186bf3da9baf3609f93a66b06f96706f04b24a 1.65 MB 3,808 5
904,808 904,808 000000000000000000017b575fb6fa0ea0e3de28729b0a0ea66c9cf5073b19c7 1.69 MB 2,201 2
Previous 10 blocks ↓
Total Size: 763.91 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.

tool-686f0dbb55fe1
Tool Icon

Block Hash

Create a block hash from a block header.

0 bytes

Used internally inside raw block headers

0 bytes

Used externally when searching for blocks on block explorers

0 bytes
0 secs
tool-686f0dbb5637c
Tool Icon

Target Adjustment

Calculate the next target value based on the current target and the time between blocks.

0x
0 bytes
Time (seconds)
0d
0d

The target adjustment period is 2016 blocks. A block is mined on average every 600 seconds (10 minutes), so the expected time is 2016 * 600 = 1209600 seconds.

Ratio

The actual time divided by the expected time. We multiply the current target by this ratio to get the new target.

0x
0x
0 bytes

Note: This target value has been truncated slightly for storage in the bits field of the block header, and that's the target value that's actually used when mining.

0 secs

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