<p>No.  The whole point of a hash is that it's a <em>one way</em> function.  You can't "decode" <em>any</em> of the header data from the block hash.</p>

<p>Moreover, the block height isn't even contained in the block header.  You're supposed to calculate the block height by looking at the previous block hash in the header, which hopefully refers to a block whose height you already know; if not, get that block and recurse.  (For sufficiently recent blocks, the block height is contained in the scripts of the coinbase transaction, but that's not part of the header.)</p>

CC BY-SA 3.0
2016-08-22T21:48:35.970Z
2016-08-22T21:48:35.970Z
Nate Eldredge
<p>No.</p>

<p>The block hash is a hash of the block header... but even if you could reverse the hash function (which is impossible, or Bitcoin would be broken), you wouldn't know the height, as the height is not stored in the header.</p>

<p>The header does contain a hash of the transaction Merkle root... but even if you could reverse the hash functions in the transaction Merkle tree, you wouldn't know the height, as the height is not stored in the transaction Merkle tree.</p>

<p>The Merkle tree does contain transaction ids... and if you could reverse the hash function used for computing the transaction ids, you would could learn the height, as since <a href="https://github.com/bitcoin/bips/blob/master/bip-0034.mediawiki">BIP34</a>, the block height is stored in the input of the first transaction of a block (the coinbase transaction).</p>

<p>So, if you want to know a block's height for sure, you need to request at least its coinbase transaction, the Merkle path from the coinbase to the root, and the full block header. If they all match, you can be pretty sure.</p>

CC BY-SA 3.0
2016-08-22T21:49:07.547Z
2016-08-22T21:49:07.547Z
Pieter Wuille
<p>I'm creating a bitcoin network client and I'm wondering if it's possible to decode the block height from a blockhash whenever I receive a new block inventory vector. </p>

<bitcoin-core><client><thin-clients>
is it possible to decode block height from a blockhash?
Sarodh Uggalla
# is it possible to decode block height from a blockhash?

(Asked by: username_0 on 2016-08-22)

I'm creating a bitcoin network client and I'm wondering if it's possible to decode the block height from a blockhash whenever I receive a new block inventory vector.

**Tags:** bitcoin-core, client, thin-clients


---

## 2 answers

### Answer by username_2 on 2016-08-22. Score: 7 | Accepted answer

No.

The block hash is a hash of the block header... but even if you could reverse the hash function (which is impossible, or Bitcoin would be broken), you wouldn't know the height, as the height is not stored in the header.

The header does contain a hash of the transaction Merkle root... but even if you could reverse the hash functions in the transaction Merkle tree, you wouldn't know the height, as the height is not stored in the transaction Merkle tree.

The Merkle tree does contain transaction ids... and if you could reverse the hash function used for computing the transaction ids, you would could learn the height, as since [BIP34](https://github.com/bitcoin/bips/blob/master/bip-0034.mediawiki), the block height is stored in the input of the first transaction of a block (the coinbase transaction).

So, if you want to know a block's height for sure, you need to request at least its coinbase transaction, the Merkle path from the coinbase to the root, and the full block header. If they all match, you can be pretty sure.


---

### Answer by username_1 on 2016-08-22. Score: 7

No. The whole point of a hash is that it's a *one way* function. You can't "decode" *any* of the header data from the block hash.

Moreover, the block height isn't even contained in the block header. You're supposed to calculate the block height by looking at the previous block hash in the header, which hopefully refers to a block whose height you already know; if not, get that block and recurse. (For sufficiently recent blocks, the block height is contained in the scripts of the coinbase transaction, but that's not part of the header.)


---

