Block 9

Hashing, Mining & Proof of Work

Practical: hash race, nonce guessing, mining difficulty demo.

Curriculum source adapted from My First Bitcoin Bitcoin Diploma, licensed CC BY-SA 4.0.

Lesson contents

Content plan

Block 9 — Hashing, Mining & Proof of Work Content Plan

Goal

Turn the relevant My First Bitcoin curriculum content in this block into a practical, interactive learning app.

Canonical practical direction

hash race, nonce guessing, mining difficulty demo.

Source curriculum copied into this block

  • curriculum-content/8-how-bitcoin-works/0-introduction.md
  • curriculum-content/8-how-bitcoin-works/1-security-through-cryptography.md
  • curriculum-content/9-how-does-bitcoin-mining-work/0-introduction.md
  • curriculum-content/9-how-does-bitcoin-mining-work/1-bitcoin-nodes-and-miners.md
  • curriculum-content/9-how-does-bitcoin-mining-work/2-what-is-the-mempool.md
  • curriculum-content/9-how-does-bitcoin-mining-work/3-how-transactions-work.md

Key concepts to preserve

  • Hashing
  • Cryptographic security
  • Nodes and miners
  • Mempool
  • Transactions in blocks
  • Proof of work and difficulty

Practical app thesis

Hash race where learners adjust nonce and difficulty, build blocks from mempool transactions, and see proof-of-work cost.

Build-ready structure

Each block app should use this structure:

  1. Learn — short explanation adapted from the copied curriculum content.
  2. Try — the practical game/simulator for the block.
  3. Discuss — prompts for facilitators or groups.
  4. Apply — real-world scenario or decision.
  5. Build — printable/classroom extension.

Attribution requirement

Curriculum source adapted from My First Bitcoin Bitcoin Diploma, licensed CC BY-SA 4.0.

Practical app brief

Block 9 — Hashing, Mining & Proof of Work Practical App Brief

Working title

Hashing, Mining & Proof of Work

User outcome

Learners should be able to explain the concept by doing something practical, not by memorizing a definition.

Practical game/app

Hash race where learners adjust nonce and difficulty, build blocks from mempool transactions, and see proof-of-work cost.

Core interactions

  • Read a short setup scenario.
  • Make a decision, classification, tradeoff, or transaction.
  • See immediate feedback linked to the curriculum concept.
  • Replay with changed conditions.
  • End with a real-world application prompt.

Curriculum content to use

See CONTENT-PLAN.md and the copied curriculum-content/ folder inside this block.

Minimum viable app

  • One static HTML/CSS/JS page.
  • No backend required.
  • Mobile-first.
  • Works as a standalone GitHub Pages path.
  • Includes attribution to My First Bitcoin.

Curriculum lesson content

The source markdown has been rendered below as learner-readable HTML so the practical app can be built directly from the block page.

curriculum-content/8-how-bitcoin-works/0-introduction.md

8.0 Introduction

Bitcoin is not "unregulated;" it is regulated by algorithm instead of being regulated by government bureaucracies. Uncorrupted.

_Andreas M. Antonopoulos_

In this module, we take a closer look at the technical side of Bitcoin. We explain in simple terms the cryptography that secures the protocol and how transactions work. Some concepts may seem technical, but don’t worry. Many people use the internet every day without fully understanding how it works.

Learning Bitcoin’s technical side is a long journey that not everyone needs to take. While we encourage continued learning, this module focuses on the key basics.

The Bitcoin network is a shared record of transactions stored across many computers called nodes. This record, known as the Bitcoin ledger, is pseudonymous. It does not include personal details like names or ages, only transaction data and Bitcoin addresses. The ledger tracks every transaction since the blockchain began.

Note – Mechanics of the Bitcoin Protocol

* Proof-of-Work

* Cryptographic Time-Stamps

* Difficulty Adjustment

* Peer-to-Peer Network Architecture

* Hash Functions & Merkle Trees

* Public Key Cryptography

* Block Subsidy Halving

curriculum-content/8-how-bitcoin-works/1-security-through-cryptography.md

8.1 Security through Cryptography

What Bitcoin gives us is a hard promise: the program will execute exactly as specified.

_Andreas M. Antonopoulos_

Public/Private Key Cryptography

Definition – Definition of Cryptography

Cryptography is the practice of turning information into a secret that only the right people can read.

In traditional cryptography, two people who want to communicate privately must first share the same secret key, similar to a shared password. One person uses this key to encrypt the message before sending it, and the other person uses the same key to decrypt and read it.

The problem with this system is that both people must already share the secret key. If someone else gets access to that key, they can read any intercepted messages.

Bitcoin solves this problem using a different approach called public-key cryptography, where users do not need to share secret keys in advance.

Public/private key cryptography solves the problem of sharing secrets. Instead of sharing a password, each person has two keys: a public key and a private key.

If John wants to send something to Arel, he can use Arel’s public key. Only Arel can unlock it using his private key. Even if someone intercepts the message, they cannot read or use it without the private key.

In Bitcoin, this system is used to create digital signatures. A digital signature proves that the owner of a private key approved a transaction, similar to signing your name on a document. This is what allows Bitcoin transactions to be secure and verifiable without trusting a third party.

Info

Each user has two keys: a private key, which is kept secret, and a public key that can be shared with others.

The private key serves as a form of identification and proof of ownership, confirming: “This address belongs to me and I have control over it.”

Digital signatures are created to identify unique transactions.

Bitcoin transactions involve transferring the ownership of a certain amount of bitcoin from one address to another.

Encryption is used to ensure that only the real holder of the bitcoin has the authority to send their money to someone else. It ensures their property is guarded against malicious actors.

As an additional measure of protection, each Bitcoin transaction automatically gets a UNIQUE digital signature. This unique digital signature is powered by tamper-proof technology that helps the network verify that the real owner of the bitcoin, and not someone else, has sent them.

How a Bitcoin Transaction Works
  1. Creating the Transaction: A user initiates a Bitcoin transaction by specifying details such as the recipient's address and the amount of bitcoin to be sent.
  2. Digital Signature Generation: The sender generates a unique digital signature using their private key. This signature is a unique cryptographic code that verifies the transaction's authenticity.
  3. Broadcasting the Transaction: The signed transaction is broadcast to the Bitcoin network, indicating the intent to transfer ownership of bitcoin from the sender to the recipient.
  4. Verification on the Network: Nodes on the Bitcoin network receive the transaction and use the recipient's public key to verify the authenticity of the signature. of the transaction. Simultaneously, they use the sender's public key to verify the digital signature.
  5. Confirmation on the Bitcoin network: If the verification is successful, the transaction will be added to the ledger, which serves as a secure, transparent record of all transactions. Once confirmed, the ownership of the bitcoin is officially transferred from the sender to the recipient.

Callout – Summary

The digital signature, created with the sender’s private key, proves that the transaction was authorized by the owner of the bitcoin.

The Bitcoin network can then verify this proof and record the transaction.

Hashing Explanation

Please don’t be intimidated by the technical terms and mathematical concepts ahead. We understand that not everyone is crazy about math, but you might surprise yourself and see that even the most complex ideas can be grasped with a little bit of effort.

Definition – Definition of a function

A function is like a machine that takes some information and turns it into something new. The information you give the function is called the input. The new information the function creates is called the output. Functions help computers do tasks and solve problems.

What is a function?

A function is a set of instructions that takes an input and produces an output. You can think of it like a recipe: you follow the steps with certain ingredients, and you always end up with a predictable result.

In Bitcoin, functions are used to process and verify transactions. When someone sends bitcoin, cryptographic functions help check that the transaction is valid, confirm that the sender has enough funds, and update the balances on the Bitcoin ledger. Once verified and added to a block, the transaction becomes part of the permanent record on the blockchain.

What is a one-way function?

A one-way function is a special type of function that is easy to compute in one direction but extremely difficult to reverse.

For example, blending ingredients into a smoothie is easy, but you cannot separate the smoothie back into the original ingredients.

Bitcoin security relies on one-way functions. They are used in public and private key cryptography, allowing people to share a public key while keeping their private key secret. Even though the public key is visible, it is nearly impossible to derive the private key from it. This is what makes Bitcoin transactions secure.

What is a hash function?

Definition – Definition of a hash function

A hash function is like a secret code machine.

It takes in a message and turns it into a code.

How Hashing Works in Bitcoin Transactions

In Bitcoin, every transaction is turned into a hash before it is added to the blockchain. A hash is a unique digital fingerprint of the transaction. If anyone tries to change even a small part of the transaction, the hash will change completely. This makes it easy for the network to detect tampering.

The Role of Hashing in Bitcoin Security

Hashing helps protect the Bitcoin network by making transactions easy to verify and impossible to quietly modify. Because each transaction has its own unique hash, the network can quickly detect if something has been altered.

A hash function takes data and converts it into a fixed string of numbers and letters called a hash. The same input will always produce the same hash, but even a tiny change in the input will create a completely different result. This property allows computers to check that data has not been changed.

Definition – Definition of Hashing

Hashing is like creating a fingerprint for digital data. It is the process of taking a digital message and turning it into a fixed length code, which serves as a unique identifier. Just like a fingerprint can identify a person, a hash can identify a digital message. Hashes are used in many applications, including Bitcoin transactions.

The output, or hash, is always the same length, no matter how long the original information was. Bitcoin uses a few specific types of hash function called SHA-256 and RIPEMD160.

A few examples are below:

You can also think of hashing as a musical score that captures the essence of a piece of music. Just as a musical score is a unique representation of a tune, a hash value is a unique representation of a piece of data.

By comparing the score of a piece of music with the actual performance, a musician can determine if the performance is accurate. Similarly, by comparing the hash value of received data with the original hash value, one can determine if the data has been altered during transmission.

Just as a slight deviation in a musical performance can cause it to sound different, even the slightest change to the original data will result in a different hash value. This makes hashing a powerful tool for ensuring the integrity and authenticity of a Bitcoin transaction.

The process of encoding the public key through hashing is used to improve the security of information by converting it into a fixed-length, unreadable format. Bitcoin uses the SHA-256 and RIPEMD160 algorithms to produce public addresses. The resulting output serves as a unique identifier for the public key and helps to ensure the integrity and security of transactions stored in the ledger. By encrypting the information in this way, it becomes more difficult for unauthorized individuals to access and manipulate the data.

Properties of a hashing function
Activity: Generate SHA 256 Hash

https://tools.keycdn.com/sha256-online-generator

Curious about how hashing works?

Scan the QR code to instantly generate a SHA256 hash from any word, sentence, or input you choose.

Hash functions are like digital fingerprints: they're one-way, meaning once something is hashed, it can't be reversed.

Try it out and see for yourself!

curriculum-content/9-how-does-bitcoin-mining-work/0-introduction.md

9.0 Introduction

In this section, we’ll take a closer look at two very important parts (and participants) of the Bitcoin network that were first introduced in Module 5:

Together, Bitcoin nodes and miners work as a team to maintain a decentralized, secure, and strong system — a truly novel monetary system that people all around the world can rely on. Let's explore these roles in more detail to understand how they contribute to the Bitcoin protocol.

curriculum-content/9-how-does-bitcoin-mining-work/1-bitcoin-nodes-and-miners.md

9.1 Bitcoin Nodes and Miners

Bitcoin nodes may sound technical, but they are simply software that keeps a copy of the Bitcoin blockchain on a computer. The blockchain is a shared record of all Bitcoin transactions.

When you run your own node, you verify Bitcoin transactions yourself instead of trusting someone else. This gives you more independence and helps keep the Bitcoin network decentralized.

You can think of a Bitcoin node as a digital traffic officer with a few important jobs.

First, it keeps a copy of the blockchain, which is the history of all Bitcoin transactions.

Second, nodes connect with other nodes around the world and share information. One example is the list of new transactions waiting to be confirmed, which is called the mempool.

Third, nodes check that every transaction follows Bitcoin’s rules. If a transaction is invalid, the node rejects it.

Nodes also help new nodes join the network by sharing the blockchain with them. However, every new node still checks all the rules independently.

Anyone can run a node by installing software such as Bitcoin Core and downloading the blockchain. Once it is set up, the node continues to receive new blocks roughly every 10 minutes and verifies them before adding them to its copy of the blockchain.

Running a node helps make the Bitcoin network more secure and decentralized, because more people are independently verifying the system.

What Is a Bitcoin Node?

The purpose of mining is not the creation of new bitcoin; that’s the incentive system. Mining is the mechanism by which Bitcoin’s security is decentralized.

_Andreas M. Antonopoulos_

Callout

Miners collect unconfirmed transactions, form a block, and use energy to find a key that adds and secures the block.

Miners compete to add the next block of transactions to the blockchain. To do this, they must find a special number that creates a valid block hash. You can imagine it like searching for the right key among billions of possibilities. The first miner to find the correct hash wins the race and earns the right to add their block to the blockchain.

When a miner finds a valid hash, they share their block with the network. Other miners quickly verify that the solution is correct. If it is, the block is added to the blockchain, helping keep Bitcoin’s public ledger secure.

Miners earn bitcoin in two ways:

Bitcoin Halvings
20092012201620202024
50 BTC25 BTC12.5 BTC6.25 BTC3.125 BTC

Callout

Miners’ rewards for completing one block halve every 210,000 blocks, about every four years.

Bitcoin has a fixed maximum supply of 21,000,000 bitcoin, but all of them were not created when Bitcoin started. Instead, new bitcoin are gradually introduced into circulation through mining.

When miners successfully add a new block of transactions to the Bitcoin network, they receive a block reward in bitcoin. In the early days of Bitcoin, this reward was 50 bitcoin per block. This reward encouraged people to use computing power and electricity to help secure the network.

About every 210,000 blocks (roughly every 4 years), the block reward is cut in half. This event is called the halving. The halving slows down the creation of new bitcoin and helps ensure that the total supply will never exceed 21 million. Over time, this makes bitcoin increasingly scarce.

Definition – Circulating supply

Circulating supply refers to the total available amount of a currency. With Bitcoin, the total circulating supply is the number of coins that have been mined and are incirculation at any given time.

Definition – Bitcoin supply schedule

The Bitcoin supply schedule is the predetermined and public plan for the release of new bitcoin into circulation, designed to maintain Bitcoin’s scarcity over time.

 Bitcoin Supply Schedule

After each halving event, the bitcoin reward that miners receive for adding a block is cut in half. This reduces the rate at which new bitcoins are created.

Miners still earn transaction fees from the transactions included in the block they mine. Over time, these fees are expected to become a larger part of miners’ income.

Halvings are built into the Bitcoin protocol and happen automatically about every four years. Because of this, Bitcoin’s supply schedule is predictable and transparent.

The table below shows upcoming halvings, including the approximate date, the block number when they occur, the new block reward, and the percentage of the total bitcoin supply that will have been mined.

EventDateBlockRewardMined
5th Halving20281,050,0001.5625 BTC98.44 %
6th Halving20321,260,0000.78125 BTC99.22 %
7th Halving20361,470,0000.390625 BTC99.61 %

As more bitcoin are mined, the circulating supply keeps increasing until the maximum supply of 21,000,000 bitcoins is reached, which is expected around the year 2140. Because fewer new bitcoins are created over time, if demand increases, the price of Bitcoin can rise. This also encourages miners to keep securing the network by contributing their computing power.


What is a valid block hash in Bitcoin?

In Bitcoin, miners compete to find a special code called a block hash. This code identifies a block of transactions and allows it to be added to the blockchain.

Each block contains information about recent transactions and also includes the hash of the previous block. This links every block together, forming a chain from the very first block (the Genesis Block) to the most recent one.

A hash works like a digital fingerprint for the data in the block. If any information in the block were changed, the fingerprint would change as well. This makes it easy for anyone to verify that the blockchain’s transaction history has not been altered and helps keep the network secure.

Callout

Satoshi Nakamoto, the creator of Bitcoin, mined the Genesis Block, which unlocked a total of 50 bitcoin.

The Race to Mine a Block

Miners compete to find a valid block hash. The first miner to find one gets to add the new block to the blockchain and receive a bitcoin reward.

To be valid, the block’s hash must be lower than a number set by the network called the difficulty target. Because hashes are random, miners must keep trying different inputs until they find one that works.

If too many miners are competing, blocks would be found too quickly. If too few miners are participating, blocks would take too long to find. To keep the system running smoothly, Bitcoin automatically adjusts the difficulty every 2,016 blocks (about every two weeks).

This adjustment ensures that, on average, a new block is added to the blockchain about every 10 minutes.

Definition – Definition of difficulty level

The difficulty level in Bitcoin mining measures how hard it is to find a valid block hash. The network adjusts this difficulty every 2,016 blocks (about every two weeks) so that new blocks are added to the blockchain about every 10 minutes. The higher the difficulty, the harder it is for miners to find a valid block.

Info

By finding a valid block hash, a miner proves they have done the work required to add a new block to the blockchain. This process is called Proof of Work (PoW). It is the security mechanism that allows Bitcoin to confirm transactions and add new blocks to the blockchain. The miner who finds the valid hash first earns a reward in bitcoin, which includes the block reward and the transaction fees from the transactions included in that block.

Proof of Work (PoW) helps keep Bitcoin secure by making it extremely expensive for anyone to try to cheat or take control of the network. Instead, it is far more profitable to follow the rules.

Miners play four main roles:

  1. Collect transactions: Miners choose transactions that have been sent to the network and place them into a candidate block.
  2. Perform Proof of Work: Miners compete to solve a difficult mathematical puzzle by finding a valid block hash.
  3. Broadcast the block: The first miner to find a valid solution shares the new block with the network.
  4. Earn rewards: If the block is valid, it is added to the blockchain and the miner receives newly created bitcoin plus transaction fees.

Many miners around the world try to create the next block at the same time. When one miner finds a valid solution, the network checks the block. If everything is correct, it is added to the blockchain. Other competing blocks are discarded. This process keeps the network in agreement and prevents double-spending.

curriculum-content/9-how-does-bitcoin-mining-work/2-what-is-the-mempool.md

9.2 What Is the Mempool?

The mempool, short for “memory pool,” is like a waiting room for Bitcoin transactions. When you send bitcoin, your transaction is first broadcast to the network and placed in the mempool.

You can think of it like waiting in line at a restaurant. Your name goes on a list, and you wait until a table is available. In the same way, your transaction waits in the mempool until a miner includes it in a block.

Bitcoin nodes check each new transaction to make sure it is valid and that the bitcoin being spent has not already been used. If the transaction is valid, it stays in the mempool until it is confirmed.

Miners choose transactions from the mempool and include them in new blocks. Usually, transactions with higher fees are chosen first.

Once a transaction is included in a block, it becomes confirmed and is permanently recorded on the Bitcoin blockchain.


Activity: Exploring the Mempool

https://qr.myfirstbitcoin.org/mempool.pdf

This activity exposes students to a free and open-source tool that does not require technical skills to use. It is useful for Bitcoiners at all levels, from beginner to experienced.

Key Points
  1. Mempool refers to the list of unconfirmed transactions maintained by each Bitcoin node, not a specific service or platform.
  2. This is no single, universal mempool. Mempool.space is one of many.
  3. Mempool.space is open-sourced and well known for being an easy-to-use visual block explorer. It provides real time data on unconfirmed transactions, fee rates, and other network activity.
Student Tip

Mempool.space does much more than visualize blocks. Explore other parts of the Bitcoin ecosystem: e.g., Lightning, mining, the hash rate, pools, and block space "goggles".

curriculum-content/9-how-does-bitcoin-mining-work/3-how-transactions-work.md

9.3 How Transactions Work

Now that you understand public and private keys, as well as the roles of nodes and miners, here’s how a Bitcoin transaction works from start to finish.

  1. Adam wants to send bitcoin to Gerardo. He creates a transaction with Gerardo’s address, the amount to send, and a fee.
  2. Adam signs the transaction with his private key to prove ownership.
  3. He broadcasts the transaction to the Bitcoin network.
  4. Nodes receive it and check that it follows the rules, including verifying the signature and that Adam has enough bitcoin.
  5. If valid, the transaction is shared across the network and added to the mempool, where pending transactions wait.
  6. Miners pick transactions from the mempool and include them in a block they try to mine.
  7. When a miner successfully mines a block, it is shared with the network and checked by other nodes.
  8. If valid, the block is added to the blockchain. Gerardo receives the bitcoin.
  9. As more blocks are added, the transaction gains confirmations, making it more secure.

Once included in a block, the transaction is confirmed. Adam cannot spend that bitcoin again, and Gerardo can spend what he received in a new transaction.

Note

Transaction & fee selected → Signed by wallet and sent → Distributed by nodes → Miner adds transaction to block template → Miner wins Proof-of-Work contest → New block is validated → New block is distributed by nodes

Resources

▶ YouTube