Member-only story
What’s in a Bitcoin Block?
How to make sense of the data that makes up a block of a the Bitcoin blockchain

A block is a data structure that contains transactions as well as metadata about the block. All transactions must be included in a valid block in order to be considered final. All full nodes on the network will store a copy of the block in order to validate new transactions and share the data with other nodes.
This is part of a video course, join people in 22 countries around the world in my course on Become a Bitcoin + Blockchain Programmer.
Block Structure
$ bitcoin-cli -regtest getblockhash 0
0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206$ bitcoin-cli -regtest getblock 0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206 0
0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4adae5494dffff7f20020000000101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4d04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73ffffffff0100f2052a01000000434104678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5fac00000000
This is the genesis block for the regtest network, and as you can see, it is not really human readable. We are going to learn how the data is encoded from left to right.
{block header}
{transaction counter}
{transactions}
Block Header
{version 4B}
{previous block hash 32B}
{merkle root hash 32B}
{time 4B}{bits 4B}
{nonce 4B}
version
(4 Bytes) - Block format version.previous block hash
(32 Bytes) - The hash of the preceding block. This is important to include in the header because the hash of the block is calculated from the header, and thus depends on the value of the previous block, linking each new block to the last. This is the link in the chain of the blockchain.merkle root hash
(32 Bytes) - The hash of the…