SHA256 * 2 on header - what am I doing wrong? I've been experimenting with the php code here: https://en.bitcoin.it/wiki/Block_hashing_algorithm  (after correcting the small bug of $x=; to $x=""; )

With these blocks 0 and 125552 (for example) it works fine and I get the expected hash.

With blocks 225552 and 300000, I get:

7a7bb195e8bcc8e73205df7906eb68f26144c6fbc577d59dd4e8a0cfdb8b90df (rather than 00000000000001f4f14b09019b23d71c222a2c1245ef3df52875d79ff4488709)

and

178d6fe6cbf696311e7f46263067eeb688797e4c790060c1f6edf6daec76c59e (rather than 000000000000000082ccf8f1557c5d40b21edabb18d2d691cfbf87118bac7254)

...respectively - which doesn't match the hash of either block.

What am I missing or doing incorrectly?

Additional note - I confirmed these results using "openssl dgst -sha256 -binary test-input.bin |openssl dgst -sha256"...

Further to this, using the python code from the same page:

&gt;&gt;&gt; import hashlib
&gt;&gt;&gt; header_hex = ("01000000" +
...     "81cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000" +
...     "e320b6c2fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122b" +
...     "c7f5d74d" +
...     "f2b9441a" +
...      "42a14695")
&gt;&gt;&gt; header_bin = header_hex.decode('hex')
&gt;&gt;&gt; hash = hashlib.sha256(hashlib.sha256(header_bin).digest()).digest()
&gt;&gt;&gt; hash.encode('hex_codec')
'1dbd981fe6985776b644b173a4d0385ddc1aa2a829688d1e0000000000000000'
&gt;&gt;&gt; hash[::-1].encode('hex_codec')
'00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d'


...works fine... but:

&gt;&gt;&gt; import hashlib
&gt;&gt;&gt; header_hex = ("01000000" +
...     "7ef055e1674d2e6551dba41cd214debbee34aeb544c7ec670000000000000000" +
...     "d3998963f80c5bab43fe8c26228e98d030edf4dcbe48a666f5c39e2d7a885c91" +
...     "02c86d53" +
...     "6c890019" +
...     "593a470d")
&gt;&gt;&gt; header_bin = header_hex.decode('hex')
&gt;&gt;&gt; hash = hashlib.sha256(hashlib.sha256(header_bin).digest()).digest()
&gt;&gt;&gt; hash.encode('hex_codec')
'9ec576ecdaf6edf6c16000794c7e7988b6ee673026467f1e3196f6cbe66f8d17'
&gt;&gt;&gt; hash[::-1].encode('hex_codec')
'178d6fe6cbf696311e7f46263067eeb688797e4c790060c1f6edf6daec76c59e'


...gets the same erroneous result as the php code.
You have the wrong block version number.  Block 300000 is a version 2 block, whereas 125552 was version 1.  So the first word in the block header should be "02000000" not "01000000".