---
title: "Proof of Work"
url: "https://radix-wiki.miow.me/contents/resources/python-scripts/proof-of-work"
updated: 2026-10-03
description: "A basic implementation of the Proof of Work (PoW) algorithm used as Sybil prevention by Bitcoin and other PoW networks. A deeper comparison between PoW and…"
---

# Proof of Work

| Proof of Work |  |
| --- | --- |
| Type | Python script · worked example |
| Demonstrates | SHA-256 hash mining as Sybil prevention |
| Language | Python 3 |
| Dependencies | None – [hashlib](https://docs.python.org/3/library/hashlib.html) and [datetime](https://docs.python.org/3/library/datetime.html) ship with Python |
| Difficulty | Tunable via leading-zero count (5 ≈ 1 second) |
| Related | [PoW vs PoS](/blog/pow-vs-pos-the-next-industrial-revolution) · [Delegated Proof of Stake](/contents/tech/core-concepts/delegated-proof-of-stake-dpos) · [DLT Efficiency Metric](/contents/resources/python-scripts/dlt-efficiency-metric) |

# Proof of Work

A basic implementation of the Proof of Work (PoW) algorithm used as Sybil prevention by [Bitcoin](https://bitcoin.org) and other PoW networks. A deeper comparison between PoW and Proof of Stake (PoS) can be found in our article [**PoW vs PoS: The Next Industrial Revolution**](/blog/pow-vs-pos-the-next-industrial-revolution).

## **Method & Python Script**

1. Install VS Code: [**https://code.visualstudio.com**](https://code.visualstudio.com) or similar application.
2. In VS Code open a new terminal window by navigating to Terminal > New Terminal.
3. Install [**Homebrew**](https://brew.sh/) by pasting the following code into the terminal and pressing Enter:`/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"`
4. Install Python in the same way:`brew install python`
5. There are no dependencies to install. The script uses only [**hashlib**](https://docs.python.org/3/library/hashlib.html) and [**datetime**](https://docs.python.org/3/library/datetime.html), both of which are part of the Python standard library and are already available once Python is installed. Do not try to `pip install` them: the packages published on PyPI under those names are an obsolete Python 2 backport of `hashlib` and an unrelated [Zope date type](https://pypi.org/project/DateTime/), so the command will either fail to build or shadow the standard library.
6. Now, create a project folder and navigate to it in VS Code via File > Open Folder.
7. Create a new Python file in VS Code via File > New File. Name it something like pow.py
8. This script calculates the hash for the text “hello” with five leading zeros. Copy and paste it into pow.py and save it.

```
# v.0.1

from hashlib import sha256
from datetime import datetime

def pow(data, zeros, nonce):
    data = str(data).encode("utf-8")
    zeros = zeros * "0"

    t1 = datetime.now()
    while True:
        combo = data + f"{nonce}".encode("utf-8")
        hash_ = sha256(combo).hexdigest()
        if hash_.startswith(zeros):
            t2 = datetime.now()
            return nonce, hash_, t2-t1
        else:
            nonce += 1

output = pow("hello", 5, 0) # 5 = ~ 1 second
print(output)
```

1. Run the script from the terminal with:

```
python3 pow.py
```

## **How long it takes**

Each additional leading zero multiplies the expected work by sixteen. A hexadecimal digit carries four bits, so a hash with _z_ leading zeros turns up once in 16_z_ attempts on average – about 1.05 million at five zeros, 16.8 million at six, 268 million at seven. This loop sustains roughly 1.8 million hashes per second on a single core of a 2026 laptop under CPython 3.13, which puts five zeros at about 0.6 seconds, six at about ten seconds and seven at two and a half minutes. Slower hardware, an older interpreter or a longer input shift those numbers but not the factor of sixteen between them.

Individual runs scatter much further than the averages suggest, because the search is memoryless: every nonce is an independent trial with probability 16−_z_ of succeeding, so the number of attempts is geometrically distributed and its standard deviation is essentially equal to its mean. Two runs of the script above make the point – five zeros finished at nonce 156,056, a seventh of the expected work, while six zeros needed 33,290,382, about twice it. A single fast or slow run says nothing about the difficulty.

That spread is why proof of work is a rate limiter rather than a clock, and why [Bitcoin](https://bitcoin.org) only averages it out at network scale: the protocol [recalculates the target every 2,016 blocks](https://developer.bitcoin.org/devguide/block_chain.html) from the time those blocks actually took, against an ideal of 1,209,600 seconds – two weeks, or ten minutes a block – so the difficulty tracks whatever hash rate the network is currently pointing at it. The same arithmetic sits behind the energy comparison in [PoW vs PoS](/blog/pow-vs-pos-the-next-industrial-revolution): raising the zero count costs nothing to verify and everything to produce.

## Cost and hardware

Daniel Krawisz's 2013 essay [The Proof-of-Work Concept](https://nakamotoinstitute.org/mempool/the-proof-of-work-concept/) argues that the cost is what makes the scheme work. Miners who each prefer a block that suits them can still agree, because a block that takes difficult, random work to find arrives as the only candidate, and a miner who holds out for a better one has to persuade the rest to follow. Krawisz compares it to the handicap principle in biology, under which a signal is believable only when it is costly to send.

The script uses SHA-256, the function Bitcoin mines with. The CryptoNote paper, published in 2013 under the name Nicolas van Saberhagen, points out that SHA-256 depends only on processor speed and suits multicore and pipelined hardware, which favours the minority of miners with graphics cards, programmable chips (FPGAs) and application-specific chips (ASICs) over the majority mining on ordinary CPUs. Under the heading egalitarian proof of work, it proposed a [memory-bound function](https://web.archive.org/web/20191231054446/https://cryptonote.org/whitepaper.pdf) instead, whose running time is dominated by reads from a large block of memory, so that specialised hardware gains less.

Claims that such functions make mining fairer stayed informal until Dimitris Karakostas, Aggelos Kiayias, Christos Nasikas and Dionysis Zindros [defined egalitarianism](https://drops.dagstuhl.de/entities/document/10.4230/OASIcs.Tokenomics.2019.7) as how evenly a network's rewards pay per unit of capital invested, whatever its size. Their simulations rank Bitcoin the least egalitarian of four large proof-of-work coins, and Litecoin and Monero, which then mined with the memory-hard functions scrypt and CryptoNight, the most. Proof of stake without delegation came out ahead of all of them.

## References

1. Karakostas, Dimitris; Kiayias, Aggelos; Nasikas, Christos and Zindros, Dionysis (2019). [Cryptocurrency Egalitarianism: A Quantitative Approach](https://drops.dagstuhl.de/entities/document/10.4230/OASIcs.Tokenomics.2019.7). Tokenomics 2019, OASIcs vol. 71.
2. Krawisz, Daniel (2013). [The Proof-of-Work Concept](https://nakamotoinstitute.org/mempool/the-proof-of-work-concept/). Satoshi Nakamoto Institute.
3. van Saberhagen, Nicolas (2013). [CryptoNote v 2.0](https://web.archive.org/web/20191231054446/https://cryptonote.org/whitepaper.pdf). cryptonote.org (archived via the Internet Archive).
