# The Hash Puzzle

The final **4 bytes** of the **block header** represent the **nonce** — short for “number used once.”

This value plays a central role in **Proof-of-work**, the process that secures the Bitcoin network.

When miners perform Proof-of-work:

1. They insert a **nonce** into the block header.
2. The entire 80-byte header is hashed using **HASH256** (a double SHA-256).
3. If the resulting hash is **lower than the target value** specified in the **nBits** field, the block is valid.
4. If it’s higher, the nonce is incremented, and the hashing process repeats.

This trial-and-error process continues until a valid block header is found.

***

#### **Finding a Valid Block**

Once a valid hash is discovered:

* The miner **submits the block** to the network for **peer validation**.
* Other nodes verify the result, and if accepted, the **block’s transactions** — represented by its **Merkle Root** — are permanently added to the **public ledger**.
* Valid block hashes often begin with **multiple leading zeroes**, a sign of the difficulty involved in finding them.

***

#### **Understanding the Difficulty Target**

The **difficulty target** determines how hard it is to find a valid block.\
It’s recalculated based on how long it takes to produce a set number of blocks compared to the **ideal 10-minute average**.

Here’s how it works:

1. Measure the **elapsed time** (in seconds) for the last set of blocks.
2. Compare it to the **ideal time** for that many blocks.
3. The ratio of these two values becomes a **coefficient** used in the **difficulty adjustment algorithm**.

If blocks were found **too quickly**, the target value is **lowered**, making it **harder** to find new ones.

If blocks were found **too slowly**, the target is **raised**, making it **easier** to find a valid hash.

***

#### **Difficulty Range and Probability**

The SHA-256 hash function can output any value between:

* **0** (lowest possible)
* and **FFFF...FFFF** (the highest 256-bit value)

The **difficulty target** lies somewhere between these extremes — for example, around `3.5 × 10⁵⁵` within a total range of `1.17 × 10⁷⁷`.\
That means the probability of finding a valid block hash can be as small as:

> **1 in 10²⁰**, or 0.00000000000000000001%

Each attempt to find a valid hash is **independent** — much like flipping a coin. Even after millions of failed attempts, the probability of success on the next try remains the same.

***

#### **Scaling with the Network**

As **BSV scales** and handles **tens of thousands of transactions per second**, each node continually:

* Recalculates a **new Merkle Root** as transactions are added, and
* Creates updated **mining candidates** that are relayed to hashing machines.

These machines then perform countless hashing iterations on each candidate block header until one meets the **difficulty target**.

This enormous computation effort is what defines **Proof-of-work** — the backbone of Bitcoin’s security model.

***

#### **Measuring the Network’s Power**

The combined computational effort of all miners is expressed as the **hash rate**, measured in **hashes per second**.\
For example:

* **1 Exahash (EH/s)** = 1,000,000,000,000,000 hashes per second.

The network automatically **adjusts the difficulty** so that, regardless of total hash power, **a new block is discovered roughly every 10 minutes**.

***

#### **Difficulty Adjustment Over Time**

Originally, Bitcoin adjusted difficulty every **2016 blocks** (\~two weeks).

This system was later modified to recalculate after **every block**, allowing the network to respond to changes in mining power more quickly.

***

#### **Key Takeaway**

The **Hash Puzzle** is what ensures fairness and stability in the Bitcoin network.

By requiring miners to find a **hash below a moving target**, it keeps block creation steady, prevents manipulation, and rewards genuine computational work — forming the **heartbeat** of the blockchain.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hub.bsvblockchain.org/higher-learning/bsv-academy/bitcoin-primitives-merkle-trees/merkle-trees-and-the-block-header/the-hash-puzzle.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
