Loading Tool

Blockchain

A big file of bitcoin transactions

Diagram showing the blockchain as a file stored by nodes on the bitcoin network.
Current Blockchain Size:
851.75 GB
953,671 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: 953,671 (0 blocks away) ⇈
Next 0 blocks ↑
Height Block Hash Txs Size Avg Feerate AFR Time (UTC)
953,671 953,671 000000000000000000002d3051602439a2884b896702f9841cdbcdf03a35ee60 4,794 1.00/1.00 vMB 2 ago
953,670 953,670 000000000000000000020d393ad3a0feef1493d3379247f7f8ac51ef501bf1d2 5,930 1.00/1.00 vMB 0 ago
953,669 953,669 00000000000000000001c6513864cc3b0ebb8969f274dcf2c120c61ca8114199 4,507 1.00/1.00 vMB 2 ago
953,668 953,668 0000000000000000000054c0a032c695a284750b37e8b7fde81c37335f982464 6,096 1.00/1.00 vMB 0 ago
953,667 953,667 000000000000000000014e87e4a198eb3ea41bd417f11ce5ea4635150a84c371 5,628 1.00/1.00 vMB 1 ago
953,666 953,666 00000000000000000001d4510e64e3753dbe008d5d89916ed40acc6e297e849f 6,287 1.00/1.00 vMB 1
953,665 953,665 000000000000000000011011c5f720ae0c4e5c43c95bb59b2a52afe06ab5dc9a 6,747 1.00/1.00 vMB 0
953,664 953,664 0000000000000000000026595e0be3a3985db26d1a6bb4c5fa24bb0a9832ecfa 5,567 1.00/1.00 vMB 1
953,663 953,663 00000000000000000000e228bc0657e0e82d68e74dcf0a356851c82f4d3646a8 6,455 1.00/1.00 vMB 0
953,662 953,662 0000000000000000000133d9bd586bb60e79cdd4da9b6fec20dcb2320f266601 4,919 1.00/1.00 vMB 1
953,661 953,661 000000000000000000010a2a5fce596898f4956af628f690095da0f18c5cb46b 4,765 1.00/1.00 vMB 0
953,660 953,660 0000000000000000000095916c7744623b29bff43e46b6ddedea87f34f4dc45a 4,700 1.00/1.00 vMB 1
953,659 953,659 00000000000000000000c2770f8f1e625b59c3992a89c6f58dc066e8af13d290 4,357 1.00/1.00 vMB 3
953,658 953,658 0000000000000000000038c24a63c8072270fa260902a4944fbc44d83aafef98 5,876 1.00/1.00 vMB 1
953,657 953,657 00000000000000000000d2d19c330bfca44c19de152b6c1e7edc2a05271a9d44 5,944 1.00/1.00 vMB 1
953,656 953,656 00000000000000000001eba4bdacc1624c5b8bd14ee91d8a3358e1e4d881ddd6 4,294 1.00/1.00 vMB 1
953,655 953,655 000000000000000000008306d6a885bde8053b1064ec0a22a9955bfb87c22cc0 4,240 1.00/1.00 vMB 2
953,654 953,654 000000000000000000010d15d66405f614d13b96cad86be22aa701c2568a36d0 4,637 1.00/1.00 vMB 1
953,653 953,653 0000000000000000000214ab87f14278c449e7bf353289a31f64af230e96098c 4,074 1.00/1.00 vMB 3
953,652 953,652 00000000000000000001669592381aac6dabd5f247cd98ee73c92a2cc7fb8f59 4,462 1.00/1.00 vMB 4
953,651 953,651 0000000000000000000096a5527bb8d8c55d5171e7fed059cb9f1bd847afc993 6,475 1.00/1.00 vMB 0
Previous 10 blocks ↓
Total Size: 851.75 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-6a2ef07b4538f
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-6a2ef07b45599
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.

  • Due to the processing power required to mine a block and the regularly adjusting target, new blocks are added to the blockchain once every 10 minutes (on average).
  • A node doesn't have to try and mine new blocks. Instead, it can just keep a copy of the blockchain and relay new blocks to other nodes when it receives them.

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