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:
825.45 GB
939,297 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: 939,297 (0 blocks away) ⇈
Next 0 blocks ↑
Height Block Hash Txs Size Avg Feerate AFR Time (UTC)
939,297 939,297 00000000000000000000201ea23eb8d15d300677ce90a26aa9370fbbaa8c4888 3,925 1.00/1.00 vMB 4 ago
939,296 939,296 000000000000000000019ef1ab9c380f421d232bb77dcc9a992e479719cf1534 4,212 1.00/1.00 vMB 0 ago
939,295 939,295 00000000000000000000ae49ed2271aea03bc79385043bb86d4468519455af20 3,683 1.00/1.00 vMB 1 ago
939,294 939,294 00000000000000000000c3e0d6319c6c50edfbd3dd57443def5b953bd09b62f3 3,178 1.00/1.00 vMB 3 ago
939,293 939,293 000000000000000000010add9056fa3f9d09aebc7a9d90cf119a32862862715b 4,075 1.00/1.00 vMB 1 ago
939,292 939,292 000000000000000000015a667ea8ed5640ad091ac42395ff4bb37d56d44c9fa0 3,300 1.00/1.00 vMB 2
939,291 939,291 00000000000000000001efa0eb45d4336567e1dc198ee7e7c66b99c230753861 4,089 1.00/1.00 vMB 6
939,290 939,290 000000000000000000004b7bf507400f7e83117dbc9b3908dc6cea5076dce957 2,999 1.00/1.00 vMB 2
939,289 939,289 00000000000000000000e94587a2cd8f76bc0424a7d178b2b04b029a7c6db87c 3,421 1.00/1.00 vMB 2
939,288 939,288 000000000000000000007204ab0a0b009a77db24bd33483219ab6f99dc936d35 3,491 1.00/1.00 vMB 3
939,287 939,287 0000000000000000000032f8f7cc90acdaa272a19b952d678c20a2586bb7ff8b 3,570 1.00/1.00 vMB 7
939,286 939,286 000000000000000000005d1a1d7ebadf91692834982192f6aadfd8ca0aae18d2 1,829 0.67/1.00 vMB 2
939,285 939,285 00000000000000000000db41f4282d6415c089564ce1682a9cf5efb572c84a57 3,298 1.00/1.00 vMB 4
939,284 939,284 0000000000000000000095fb604e72dc748553c922117679dc8895493ba0f87a 2,869 1.00/1.00 vMB 1
939,283 939,283 0000000000000000000031445974772f586029b5c167e68c55f489e7d3aaf718 2,667 1.00/1.00 vMB 1
939,282 939,282 00000000000000000000d9feaa7cfca7f4a7e582175653d88a5abb8da163dfc7 4,249 1.00/1.00 vMB 0
939,281 939,281 0000000000000000000034ce2235445549a571f872fc68b20b311cff0de01572 1,950 0.62/1.00 vMB 1
939,280 939,280 000000000000000000016ffd734d375d789ead10d856e31234dcae0fc263fd77 3,494 1.00/1.00 vMB 3
939,279 939,279 00000000000000000000b8fc5071f5c499b5076d55f7f0667fa87303dd1b61c8 2,970 0.99/1.00 vMB 2
939,278 939,278 00000000000000000000604d137f0b337c764399d25ec5e2c95b40358b8e2abe 2,796 1.00/1.00 vMB 3
939,277 939,277 0000000000000000000020e1eba28805d9b5346692cbb0e244907fb530dd3371 4,350 1.00/1.00 vMB 0
Previous 10 blocks ↓
Total Size: 825.45 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-69a87b33cb29a
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-69a87b33cb3a2
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