<p>This is explained in the <a href="https://bitcoin.org/bitcoin.pdf" rel="nofollow">Bitcoin paper</a>:</p>

<blockquote>
  <p>Nodes always consider the longest chain to be the correct one and will
  keep working on extending it. If two nodes broadcast different
  versions of the next block simultaneously, some nodes may receive one
  or the other first. In that case, they work on the first one they
  received, but save the other branch in case it becomes longer. The tie
  will be broken when the next proof-of-work is found and one branch
  becomes longer; the nodes that were working on the other branch will
  then switch to the longer one.</p>
</blockquote>

<p>The idea is that it's quite rare for the network to find 2 different blocks at around the same time. If it happens, you'll have peers working on one chain and others on the other. It becomes even rarer for it to happen in succession, so it's just a matter of time that the network will converge on a single chain.</p>

CC BY-SA 3.0
2015-05-06T20:21:54.350Z
2015-05-06T20:21:54.350Z
Luca Matteis
<p>You're looking for <a href="https://github.com/bitcoin/bitcoin/blob/1d9d314573ee48f6f51107265f1cf1fa9e36c998/src/main.cpp#L91" rel="noreferrer">CBlockIndexWorkComparator</a>, which operates by three rules. The rules are applied one at a time, and if a rule leads to a tie, then the next rule is applied.</p>

<ul>
<li>Which blockchain has <a href="https://bitcoin.stackexchange.com/a/939/2306">the most work</a>? </li>
<li>Which one was received first? (This can be different for different clients, which is why the previous rule is applied first.)</li>
<li>Which one has a larger pointer address? (This is largely random, and different for different clients.)</li>
</ul>

CC BY-SA 3.0
2015-05-07T12:24:05.490Z
Please explain the meaning of the 3rd rule.
Haddar Macdasi
CC BY-SA 3.0
2015-05-07T13:43:25.403Z
@HaddarMacdasi Programs on a computer use memory, and pointers tell the program where it can find the data it wants to see. What pointer address each one gets is decided by a *memory allocator*, which is usually part of the operating system. The purpose of this rule is to provide a tie-breaker that can always break ties.
Nick ODell
CC BY-SA 3.0
2015-05-07T14:07:42.073Z
If clients will get into deciding the chain to go with based on the 3rd rule, which has I understand is just like flipping a coin, won't the decision splits again 50% going with the 1st chain an the rest with the 2nd ?
Haddar Macdasi
CC BY-SA 3.0
2015-05-07T14:21:49.327Z
@HaddarMacdasi Exactly. But that split won't last forever, because of rule #1. Eventually some miner will win.
Nick ODell
CC BY-SA 3.0
2018-01-26T21:31:26.753Z
If a node receives a second split block, do they drop it immediately or do they keep it around? If they drop it immediately, how do they resolve it if that block they dropped ends up being part of the longest chain?
B T
CC BY-SA 4.0
2018-08-28T18:09:47.873Z
The third rule only applies to old blocks, loaded from disk. It should never affect the outcome on the network, because as soon as a block is received from the network, the second rule takes precedence (one block must have been received before another).
Pieter Wuille
CC BY-SA 3.0
2015-05-06T20:23:36.927Z
2015-05-06T20:36:09.380Z
2017-04-13T12:47:34.187Z
Nick ODell
<p>Let's say two miners created 2 different blocks and broadcast them into the network. Now some clients see blockchain 1 and other blockchain 2 which are different from each other.<br>
I would like to understand technically as possible how in the end the majority of clients will continue with only single chain and the other be abandoned?<br>
Why will they choose one over the other?<br>
I would like to believe this is done automatically by the clients / miners without human touch, only by some kind of coded logic. That logic is what I'm after.    </p>

<p>Related question: <a href="https://bitcoin.stackexchange.com/questions/12462/what-happens-to-extinct-blockchains-and-transactions-inside-of-them/">What happens to extinct blockchains, and transactions inside of them?</a></p>

CC BY-SA 3.0
2015-05-06T20:30:36.663Z
a.k.a. An orphaned block. A valid block that achieved some network propagation but a "better" block came along at the same time and took over.
George
<blockchain><blockchain-fork><consensus><best-chain>
How is a blockchain split resolved?
Haddar Macdasi
# How is a blockchain split resolved?

(Asked by: username_0 on 2015-05-06)

Let's say two miners created 2 different blocks and broadcast them into the network. Now some clients see blockchain 1 and other blockchain 2 which are different from each other.  
I would like to understand technically as possible how in the end the majority of clients will continue with only single chain and the other be abandoned?  
Why will they choose one over the other?  
I would like to believe this is done automatically by the clients / miners without human touch, only by some kind of coded logic. That logic is what I'm after.

Related question: [What happens to extinct blockchains, and transactions inside of them?](https://bitcoin.stackexchange.com/questions/12462/what-happens-to-extinct-blockchains-and-transactions-inside-of-them/)

**Tags:** blockchain, blockchain-fork, consensus, best-chain

> **Comments:**
> **username_1**: a.k.a. An orphaned block. A valid block that achieved some network propagation but a "better" block came along at the same time and took over.  

---

## 2 answers

### Answer by username_3 on 2015-05-06. Score: 10 | Accepted answer

You're looking for [CBlockIndexWorkComparator](https://github.com/bitcoin/bitcoin/blob/1d9d314573ee48f6f51107265f1cf1fa9e36c998/src/main.cpp#L91), which operates by three rules. The rules are applied one at a time, and if a rule leads to a tie, then the next rule is applied.

* Which blockchain has [the most work](https://bitcoin.stackexchange.com/a/939/2306)?
* Which one was received first? (This can be different for different clients, which is why the previous rule is applied first.)
* Which one has a larger pointer address? (This is largely random, and different for different clients.)

> **Comments:**
> **username_0**: Please explain the meaning of the 3rd rule.  
> **username_3**: @username_0 Programs on a computer use memory, and pointers tell the program where it can find the data it wants to see. What pointer address each one gets is decided by a *memory allocator*, which is usually part of the operating system. The purpose of this rule is to provide a tie-breaker that can always break ties.  
> **username_0**: If clients will get into deciding the chain to go with based on the 3rd rule, which has I understand is just like flipping a coin, won't the decision splits again 50% going with the 1st chain an the rest with the 2nd ?  
> **username_3**: @username_0 Exactly. But that split won't last forever, because of rule #1. Eventually some miner will win.  
> **username_4**: If a node receives a second split block, do they drop it immediately or do they keep it around? If they drop it immediately, how do they resolve it if that block they dropped ends up being part of the longest chain?  
> **username_5**: The third rule only applies to old blocks, loaded from disk. It should never affect the outcome on the network, because as soon as a block is received from the network, the second rule takes precedence (one block must have been received before another).  

---

### Answer by username_2 on 2015-05-06. Score: 4

This is explained in the [Bitcoin paper](https://bitcoin.org/bitcoin.pdf):

> Nodes always consider the longest chain to be the correct one and will
> keep working on extending it. If two nodes broadcast different
> versions of the next block simultaneously, some nodes may receive one
> or the other first. In that case, they work on the first one they
> received, but save the other branch in case it becomes longer. The tie
> will be broken when the next proof-of-work is found and one branch
> becomes longer; the nodes that were working on the other branch will
> then switch to the longer one.

The idea is that it's quite rare for the network to find 2 different blocks at around the same time. If it happens, you'll have peers working on one chain and others on the other. It becomes even rarer for it to happen in succession, so it's just a matter of time that the network will converge on a single chain.


---

