user86900: The bitcoin whitepaper (page 3) states

The majority
  decision is represented by the longest chain, which has the greatest proof-of-work effort invested
  in it.

I could not find how exactly this difficulty is calculated.
Is it the sum of prefix zeros of the nonces of each block?

I found this answer but it is too short for me to understand.

user60443: Work is calculated as work = 2^256 / block_target, as stated in the linked answer, which is the minimum hash value that counts as a valid proof-of-work (note this only changes every 2016 blocks). The source code for this is src/chain.cpp L#121. The total chain work is the sum of work for all blocks in the chain, and is calculated here: src/validation.cpp L#3713. So to visualize, the lower the block target, the more work has been done.
Example
Block 0 target: 00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff
Block 1 target:
00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff
Block 0: work = (2^256) / <block 0 hash> = 4.295 × 10^9
Block 1: work = (2^256) / <block 1 hash> = 4.295 × 10^9
You can see that they have both done the same amount of work. In case of a tie, the following rules apply, see https://bitcoin.stackexchange.com/a/37275/60443

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.)


86900: <p>The <a href="https://bitcoin.org/bitcoin.pdf" rel="nofollow noreferrer">bitcoin whitepaper</a> (page 3) states</p>

<blockquote>
  <p>The majority
  decision is represented by the longest chain, which has the greatest proof-of-work effort invested
  in it.</p>
</blockquote>

<p>I could not find how exactly this difficulty is calculated.</p>

<p>Is it the sum of prefix zeros of the nonces of each block?</p>

<p><hr>
<em>I found <a href="https://bitcoin.stackexchange.com/a/939/86900">this answer</a> but it is too short for me to understand.</em></p>
 60443: <p>Work is calculated as <code>work = 2^256 / block_target</code>, as stated in the linked answer, which is the minimum hash value that counts as a valid proof-of-work (note this only changes every 2016 blocks). The source code for this is <a href="https://github.com/bitcoin/bitcoin/blob/v0.16.2/src/chain.cpp#L121" rel="nofollow noreferrer">src/chain.cpp L#121</a>. The total chain work is the sum of work for all blocks in the chain, and is calculated here: <a href="https://github.com/bitcoin/bitcoin/blob/v0.16.2/src/validation.cpp#L3713" rel="nofollow noreferrer">src/validation.cpp L#3713</a>. So to visualize, the lower the block target, the more work has been done.</p>

<h2>Example</h2>

<p>Block 0 target: <code>00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff</code><br>
Block 1 target:
<code>00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff</code></p>

<p><strong><a href="https://www.rapidtables.com/convert/number/hex-to-decimal.html?x=00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048" rel="nofollow noreferrer">Block 0</a>:</strong> <a href="http://www.wolframalpha.com/input/?i=(2%5E256)+%2F+26959946667150639794667015087019630673637144422540572481103610249215" rel="nofollow noreferrer"><code>work = (2^256) / &lt;block 0 hash&gt; = 4.295 × 10^9</code></a><br>
<strong><a href="https://www.rapidtables.com/convert/number/hex-to-decimal.html?x=00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048" rel="nofollow noreferrer">Block 1</a>:</strong> <a href="http://www.wolframalpha.com/input/?i=(2%5E256)+%2F+26959946667150639794667015087019630673637144422540572481103610249215" rel="nofollow noreferrer"><code>work = (2^256) / &lt;block 1 hash&gt; = 4.295 × 10^9</code></a></p>

<p>You can see that they have both done the same amount of work. In case of a tie, the following rules apply, see <a href="https://bitcoin.stackexchange.com/a/37275/60443">https://bitcoin.stackexchange.com/a/37275/60443</a></p>

<ul>
<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>
