Skip to content
Tutorials Center
My learning

Topics

Lesson 28 of 41 ยท Using Blockchains in Practice

Bitcoin in Practice

Bitcoin's fixed supply and halving schedule, block size and weight, how Script locks coins, how fees work, and how to read a real block header in Python.

You have built a toy chain, so Bitcoin should now look familiar: blocks linked by hashes, proof of work, signed transactions and a UTXO ledger. This lesson connects your toy to the real network. You will see the rules that fix Bitcoin's total supply, how fees and block space work, how coins are locked with a tiny scripting language, and how to take the real first block ever mined and check its proof of work with a few lines of Python.

Numbers in this lesson are the protocol's consensus rules (they are the same on every full node), not market data. Prices and fee levels change daily, so none appear here.

Money in satoshis

Bitcoin amounts are integers. The smallest unit is the satoshi ("sat"), and one bitcoin is 100,000,000 satoshis. Inside the software there are no decimals, for the same reason as in the token lesson (Tokens, ERC-20 and NFTs): floating-point rounding errors and money do not mix.

A fixed supply with halvings

New bitcoins appear in exactly one way: the first transaction of every block, the coinbase transaction, may pay the miner a subsidy plus the fees of the block's transactions. The subsidy started at 50 BTC and is cut in half every 210,000 blocks. At one block per ten minutes on average, that is about four years.

The subsidy is computed with integer arithmetic: start with 50 BTC in satoshis and shift the number right by one bit for each completed halving. After 33 shifts the value reaches zero and no more coins are created. Adding up all the subsidies gives the supply limit, which is slightly under 21 million BTC because of rounding down.

Python The halving schedule and the supply limit

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The real halvings happened in 2012, 2016, 2020 and 2024, a little earlier than a pure ten-minute calculation would predict, because growing mining power made blocks arrive slightly faster than ten minutes until difficulty caught up (Difficulty Adjustment and Block Time). As the subsidy shrinks toward zero over the following decades, miners must increasingly be paid by fees.

flowchart LR
    S["Block subsidy<br/>(halves every 210,000 blocks)"] --> R["Miner's coinbase reward"]
    F["Fees from all<br/>transactions in the block"] --> R

A miner's reward is subsidy plus fees; over time the fee share grows.

Blocks, size and weight

A Bitcoin block has an 80-byte header and a list of transactions. The header holds exactly six fields:

Field Size Purpose
Version 4 bytes Rule-set and signalling bits
Previous block hash 32 bytes The link in the chain
Merkle root 32 bytes Summary of all transactions (Merkle Trees and Proofs of Inclusion)
Time 4 bytes Miner's timestamp (Unix seconds)
Bits 4 bytes Compact encoding of the difficulty target
Nonce 4 bytes The number miners vary

Block space is deliberately scarce. Originally a block could not exceed 1 MB. The 2017 SegWit upgrade changed the limit to block weight: at most 4,000,000 weight units, where ordinary bytes count 4 units and signature ("witness") bytes count 1. Transactions are measured in virtual bytes (vbytes, weight divided by 4), so a block holds up to about one million vbytes, and real blocks are often between 1 and 2 MB in raw size. Scarce space is what creates a fee market: when many people want to transact, those who bid more per vbyte get in first.

Reading a real block

Your toy chain's header was a Python object. Bitcoin's header is exactly 80 bytes with little-endian numbers, and the block hash is the double SHA-256 of that header, printed with its bytes reversed. The genesis block (block 0, mined in January 2009) has fields that are well known, so we can rebuild its header and prove it meets its own target.

Python Verify the genesis block's proof of work

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The printed hash starts with ten zeros: 000000000019d668.... That is the work the first miner did, and anyone can verify it with one hash. This is the asymmetry from Proof of Work and Mining at full scale. The "bits" field is a compact way of writing the target, so each node can recompute the required difficulty and reject blocks that do not meet it. (The block's first transaction also carries a message from its creator, a newspaper headline from 3 January 2009, which proves the block was not created earlier.)

Transactions and Script

Bitcoin uses the UTXO model from UTXO vs Account Model. Each output carries a locking script, and each input provides an unlocking script (or witness data). The node runs both on a stack machine; if the script finishes with a true value on top, the spend is valid.

Script is intentionally small. It has no loops, so it cannot run forever, and it cannot read outside data. The classic payment type, pay-to-public-key-hash (P2PKH), locks coins like this:

TEXT
locking:   OP_DUP OP_HASH160 <hash of public key> OP_EQUALVERIFY OP_CHECKSIG
unlocking: <signature> <public key>

In words: duplicate the public key, hash it, check that the hash equals the one in the lock, then check that the signature is valid for that key. Only the holder of the matching private key can produce that signature (Digital Signatures with a Toy Scheme). Newer output types (pay-to-script-hash, native SegWit and Taproot) move or compress data but follow the same idea: a condition that must be satisfied.

Python's hashlib may not include RIPEMD-160, and real signature checking needs elliptic curves, so the stand-in below uses simplified "toy" hash and signature functions. It shows the stack mechanics, not real cryptography.

Python A stack machine running a P2PKH-style script (toy)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Fees

A transaction's fee is not a field. It is simply the total of its inputs minus the total of its outputs; whatever is not claimed goes to the miner. Because block space is measured in vbytes, miners rank transactions by fee rate, in satoshis per vbyte. A transaction's size depends on how many inputs and outputs it has, not on how much money it moves, so sending a million dollars can cost the same as sending ten.

Python Choosing transactions by fee rate

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A wallet estimates a fee rate from recent blocks. If the fee is too low, the transaction waits in the mempool; features such as replace-by-fee (rebroadcasting the same payment with a higher fee) and child-pays-for-parent let you speed it up.

Confirmations and finality in practice

Bitcoin uses probabilistic finality (Longest Chain Rule, Forks and Reorgs). A transaction in the newest block is a 1-confirmation transaction; each later block adds one more. Common practice: small purchases accept 1 confirmation, large ones wait for around 6 (about an hour). Coinbase rewards cannot be spent until 100 blocks later, which protects against the reward vanishing in a reorganization.

What to take away

Bitcoin is an intentionally conservative system: a small scripting language, a hard supply cap, a block-space market and a 10-minute heartbeat. Those limits are exactly why many people trust its rules, and they are also why most complex applications are built elsewhere, as you will see in Ethereum in Practice.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. How often does the block subsidy halve?

    The halving interval is fixed in the protocol at 210,000 blocks. At ten minutes per block that is about four years.
  2. 2. Why is the total supply slightly less than exactly 21 million BTC?

    Right-shifting the satoshi amount discards fractions of a satoshi at each halving. The sum ends up a little under 21 million BTC, and the subsidy reaches zero after 33 eras.
  3. 3. How is a Bitcoin block hash computed from the header?

    Only the 80-byte header is hashed, twice with SHA-256. Because the header contains the Merkle root, it still commits to every transaction.
  4. 4. What is a transaction's fee?

    Any value not assigned to an output is left for the miner. Miners prefer transactions with the highest fee per vbyte.
  5. 5. Why is Bitcoin Script deliberately limited, with no loops?

    Without loops, a script always finishes quickly, which prevents denial-of-service attacks and keeps verification simple.

Summary

  • Amounts are integers of satoshis (1 BTC = 100,000,000 sat).
  • The block subsidy starts at 50 BTC and halves every 210,000 blocks, giving a limit just under 21 million BTC; fees must replace the subsidy over time.
  • A block header is 80 bytes (version, previous hash, Merkle root, time, bits, nonce) and the block hash is its double SHA-256; "bits" encodes the target.
  • Block space is measured in weight and vbytes (at most 4,000,000 weight units), which creates a fee market ranked by sat/vB.
  • Outputs are locked with Script, a small stack language without loops; P2PKH requires a matching public key and signature.
  • Fees equal inputs minus outputs, and confirmations make reversal exponentially less likely.

Next: Ethereum in Practice.