There are a lot of questions on the Bitcoin SE about blocks, but remarkably I couldn't find any that explicitly lay out what a block is.
A blocks has two things: A block header and a list of transactions.
- Block Header
- Version Number (4 byte integer)
- Previous Block Id (32 byte hash)
- Merkle Root (32 byte hash)
- Time (4 byte integer)
- Difficulty (4 byte integer)
- Nonce (4 byte integer)
- List of Transactions
- Number of transactions in List
In the block header part of the block:
- The version number is a parameter to help in updating how blocks are treated by the network.
- The reference to the hash of the previous block is what makes the group of blocks a "block chain".
- The merkle root is hash that can be used to prove that a transaction is in the block without providing all of the details of the block (this is a bit complicated, see this for more info).
- The time field is to show the network what time the block was solved at, and to help in calculating the difficulty parameter.
- The difficulty (or
nBits as it is called in the code) is shorthand for how difficult it is to solve the block. Essentially, it encodes a target value, and the hash of the block (when treated as a 256 bit integer) must be below that target value to be considered solved.
- The nonce (number used once) is just an integer that miners can change repeatedly to hash the header and get a different result each time, hoping to get a hash that is below the difficulty value encoded by the previous parameter.
The list of transactions is fairly straightforward, it's just the number of transactions and then the transactions themselves concatenated together.
Take for example the genesis block. The raw bytes are:
When we break this up, we can see what is in it:
01000000 // Version
0000000000000000000000000000000000000000000000000000000000000000 // Hash Previous Block
3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a // Merkle Root
29ab5f49 // Time
ffff001d // Difficulty
1dac2b7c // Nonce
01 // Number of Transactions
When you hash the block header of the genesis block, you get:
See how it starts with all these zeroes? That's because many many tries were taken (changing the nonce each time) until the miner was lucky enough to find a nonce that makes the block header hash to a low enough value (look at the hash as a hex encoded integer, with the most significant bits on the left, and the least significant on the right).