Understanding Bitcoin Mining: A Complete Interactive Walkthrough
From Transactions to Block Hashes - How a Bitcoin Block Is Built
Bitcoin mining is the process that keeps the blockchain secure and new blocks added consistently to the chain. It involves gathering unconfirmed transactions from the mempool, organizing them into a Merkle tree, and building a block header that miners then hash repeatedly until one meets the current network difficulty. This process is what creates consensus and ensures the integrity of the Bitcoin ledger.
On this page, you can explore mining step-by-step using real blockchain data. Start by pulling in the latest block header to see how new blocks link to previous ones. Then look at a selection of live transactions from the mempool and learn how they are combined into a Merkle root. From there, dive into the components of the Bitcoin block header - including version, previous hash, Merkle root, timestamp, difficulty target, and nonce - before generating real block header hashes.
To give you the full picture, the guide also walks through the raw block data, including coinbase transactions and transaction counts, so you can see exactly how every part fits together.
Merkle Tree
p = reverse(SHA256(SHA256(reverse(h1)|reverse(h2))))
In Bitcoin’s Merkle tree, the first two transactions h1 and h2 are combined by a very specific process:
Each transaction hash is reversed (byte order flipped) due to Bitcoin’s little-endian internal use.
The two reversed hashes are concatenated.
This combined buffer is then hashed twice with SHA-256.
The resulting hash is reversed again to convert back from little-endian.
This final hash becomes the parent node representing those two transactions in the Merkle tree.
This double SHA-256 + byte reversal process is repeated for every pair of nodes at each level in the tree. If there is an odd number of nodes, the last one is duplicated before hashing to keep pairs complete.
Block Header Construction
The Bitcoin block header is a fixed 80-byte structure containing vital metadata to identify and secure each block.
The key components, in order, are:
Version (4 bytes): A signed integer signaling which block validation rules to use.
Previous Block Hash (32 bytes): The SHA-256 double hash of the preceding block’s header, linking the chain.
Merkle Root (32 bytes): The SHA-256 double hash root of the Merkle tree derived from all transactions in this block.
Timestamp (4 bytes): The approximate time the miner started hashing this block, in Unix epoch format.
Nonce (4 bytes): The miner-adjustable counter used to find a proof-of-work hash that meets the difficulty target.
These fields together form the serialized block header that miners hash repeatedly to try to mine a valid block.
0x20000000
Rest Of The Raw Block Data
How It Works
The previous block hash ties blocks together, securing chain immutability.
The Merkle root summarizes all the included transactions.
The timestamp helps nodes ensure blocks are timely.
The difficulty target and nonce relate to the mining proof-of-work puzzle that miners solve by finding a header hash under the target.