<p>Bitcoin uses SHA256d to hash block headers, which is <code>sha256(sha256(x))</code>. </p>

<p>In anticipation of your next question, it uses a double hash to protect against length extension attacks (<a href="https://bitcoin.stackexchange.com/questions/4317/why-does-bitcoin-use-two-rounds-of-sha256">source</a>). </p>

CC BY-SA 3.0
2015-09-03T21:47:45.233Z
In reality extension attacks aren't really applicable to proof of work anyway, but convention is probably as good of a reason as any I suppose.
Claris
CC BY-SA 3.0
2015-09-03T14:30:28.497Z
2015-09-03T14:30:28.497Z
2017-04-13T12:47:34.187Z
morsecoder
<p>From <a href="https://en.bitcoin.it/wiki/Block_hashing_algorithm" rel="nofollow">Bitcoin Wiki PoW</a> and tangentially, <a href="https://en.bitcoin.it/wiki/Hashcash" rel="nofollow">HashCash</a>:</p>

<blockquote>
  <p>SHA256(SHA256(Block_Header)) but you have to be careful about byte-order.</p>
</blockquote>

<p>Specifically, <a href="https://en.bitcoin.it/wiki/Comparison_of_cryptocurrencies" rel="nofollow">it is <code>SHA256d</code></a></p>

<p>Implementations are often standard libraries, like Python's <code>hashlib</code>.</p>

CC BY-SA 3.0
2015-09-03T14:30:12.753Z
2015-09-03T14:30:12.753Z
Wizard Of Ozzie
<p>Probably a simple question, but I believe it is important to state it clearly for the beginners like me out there.</p>

<p>What is the hash function used for the Bitcoin proof-of-work? What implementations are available? Any Java implementation?</p>

CC BY-SA 3.0
2015-09-03T14:25:22.483Z
Related: http://bitcoin.stackexchange.com/questions/6037/why-are-hashes-in-the-bitcoin-protocol-typically-computed-twice-double-computed
morsecoder
CC BY-SA 3.0
2015-09-03T14:27:00.950Z
Related: http://bitcoin.stackexchange.com/questions/4317/why-does-bitcoin-use-two-rounds-of-sha256
morsecoder
<proof-of-work>
What is the hash function used by Bitcoin proof-of-work?
Peter Mel
# What is the hash function used by Bitcoin proof-of-work?

(Asked by: username_0 on 2015-09-03)

Probably a simple question, but I believe it is important to state it clearly for the beginners like me out there.

What is the hash function used for the Bitcoin proof-of-work? What implementations are available? Any Java implementation?

**Tags:** proof-of-work

> **Comments:**
> **username_1**: Related: http://bitcoin.stackexchange.com/questions/6037/why-are-hashes-in-the-bitcoin-protocol-typically-computed-twice-double-computed  
> **username_1**: Related: http://bitcoin.stackexchange.com/questions/4317/why-does-bitcoin-use-two-rounds-of-sha256  

---

## 2 answers

### Answer by username_1 on 2015-09-03. Score: 2 | Accepted answer

Bitcoin uses SHA256d to hash block headers, which is `sha256(sha256(x))`.

In anticipation of your next question, it uses a double hash to protect against length extension attacks ([source](https://bitcoin.stackexchange.com/questions/4317/why-does-bitcoin-use-two-rounds-of-sha256)).

> **Comments:**
> **username_2**: In reality extension attacks aren't really applicable to proof of work anyway, but convention is probably as good of a reason as any I suppose.  

---

### Answer by username_3 on 2015-09-03. Score: 1

From [Bitcoin Wiki PoW](https://en.bitcoin.it/wiki/Block_hashing_algorithm) and tangentially, [HashCash](https://en.bitcoin.it/wiki/Hashcash):

> SHA256(SHA256(Block\_Header)) but you have to be careful about byte-order.

Specifically, [it is `SHA256d`](https://en.bitcoin.it/wiki/Comparison_of_cryptocurrencies)

Implementations are often standard libraries, like Python's `hashlib`.


---

