Strip away the warehouses and a miner does one thing: tries to find a block header whose hash is below the current target.
Step by step
- Build a template. Select transactions from the mempool, usually by highest fee rate, up to the block weight limit. Add the coinbase transaction paying the subsidy and fees to the miner's address. Compute the Merkle root.
- Hash. Take the 80-byte header and run SHA-256 twice. Compare with the target. If not below it, change the nonce and hash again. The nonce is only 4 bytes, so miners also vary the coinbase (the "extra nonce") and the timestamp to get fresh headers.
- Repeat at hundreds of trillions of hashes per second per machine, across millions of machines.
- Found one. Broadcast the block. Every node checks it in milliseconds. Other miners drop their templates and start on the next block.
- Get paid. The coinbase output becomes spendable after 100 blocks.
The odds
The target today requires a hash with roughly 19 leading hexadecimal zeros. The network as a whole makes hundreds of exahashes (10¹⁸) per second to find one block every ten minutes. A single machine would wait years. That is why pools exist (lesson 3).
What the work is for
The hash is worthless. The proof that work happened is what makes rewriting history cost real resources. See Mining and proof of work for the security argument.