user74751: This block:
https://blockchain.info/block/00000000000000000025c089d0a7b2bf6241888c4dd90ab7a4c4baa6a2823551
Shows difficulty at 3,007,383,866,429.73, and bits at 392009692.
If I want to see how many zeros need to be in the hash, I believe I can just do:
(log2(3007383866429.73) + 32) / 4) => 18.362911541451258

Which is correct..  But how does bits come from difficulty?  How can I calculate the number of zeros from the bits instead of the difficulty?

user48884: Contrary to popular belief, Bitcoin's proof of work is not actually based on the number of zeroes. Rather the block hash, when interpreted as a 256 bit integer, must be less than the target value. The target value is what actually determines the difficulty. The target value is represented in a compact form in the nBits field of the block header.
The nBits field of the block header compresses the target from 256 bits into a 32 bits. A description of the format can be found here.
Basically, the nBits field, when represented in Big endian, is split into two parts: the first byte, and the last three bytes. The formula for decompressing the nBits field is as follows: (last three bytes) * 256 ^ ((first byte) - 3). This gives you a 256 bit integer that has the first 3 most significant bytes of the target.

74751: <p>This block:
<a href="https://blockchain.info/block/00000000000000000025c089d0a7b2bf6241888c4dd90ab7a4c4baa6a2823551" rel="noreferrer">https://blockchain.info/block/00000000000000000025c089d0a7b2bf6241888c4dd90ab7a4c4baa6a2823551</a></p>

<p>Shows difficulty at 3,007,383,866,429.73, and bits at 392009692.</p>

<p>If I want to see how many zeros need to be in the hash, I believe I can just do:</p>

<pre><code>(log2(3007383866429.73) + 32) / 4) =&gt; 18.362911541451258
</code></pre>

<p>Which is correct..  But how does bits come from difficulty?  How can I calculate the number of zeros from the bits instead of the difficulty?</p>
 48884: <p>Contrary to popular belief, Bitcoin's proof of work is not actually based on the number of zeroes. Rather the block hash, when interpreted as a 256 bit integer, must be less than the target value. The target value is what actually determines the difficulty. The target value is represented in a compact form in the <code>nBits</code> field of the block header.</p>
<p>The <code>nBits</code> field of the block header compresses the target from 256 bits into a 32 bits. A description of the format can be found <a href="https://developer.bitcoin.org/reference/block_chain.html#target-nbits" rel="nofollow noreferrer">here</a>.</p>
<p>Basically, the <code>nBits</code> field, when represented in Big endian, is split into two parts: the first byte, and the last three bytes. The formula for decompressing the <code>nBits</code> field is as follows: <code>(last three bytes) * 256 ^ ((first byte) - 3)</code>. This gives you a 256 bit integer that has the first 3 most significant bytes of the target.</p>
