Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Bitcoin from Scratch cover

Eighteen chapters. No libraries. From a single byte to a network running across several machines.

Everything uses only the Python standard library. No Bitcoin libraries, no black-box APIs, no “just copy this for now, you’ll understand later.” Every term you’ve heard (hash, public key, signature, block, mining, consensus, UTXO, Merkle tree, Script) becomes code you wrote yourself before it is allowed to carry that name.

This book argues one thing

The genuinely original part of Bitcoin is not the cryptography. It is everything else.

Satoshi’s building blocks were almost all borrowed: digital signatures (Diffie–Hellman / RSA, 1976–77), proof-of-work (Adam Back, 1997), hash time-stamp chains (Haber–Stornetta, 1991), the idea of a decentralized ledger (Wei Dai / Nick Szabo, 1998), and the first serious attempt at digital cash (David Chaum, 1982).

What he invented was how to build a bank with no manager out of those bricks.

That claim is easy to say and hard to prove, so this book counts it. Every chapter ends with a ledger: of the code you just wrote, which lines are cryptography, and which are systems design, consensus, game theory, or economics. By chapter 18 the tally speaks for itself.

The bricks are borrowed. The house is original.

Start here: Prologue: Borrowed Bricks, an Original House

Contents

Part I · Bricks: the cryptographic floor

ChTitleWhat you build by hand
1Bytes, Hashes, Commitmentssha256(), and commit() / verify(): a guessing game nobody can cheat
2Finite Fields, Elliptic Curves, Public KeysHop around a curve mod 97, derive a public key, then brute-force it back
3Digital SignaturesReal ECDSA, then count how many times priv appears inside verify

Part II · Retracing the ancestors

ChTitleWhat you build by hand
4The Hash Time-Stamp ChainHaber–Stornetta’s chain; edit one old block and watch everything after it break
5Proof-of-WorkHashcash-style mining, and a lesson about luck that most books skip

Part III · The house: building a chain

ChTitleWhat you build by hand
6Transactions and Double-SpendingA UTXO ledger, and your first problem cryptography cannot solve
7Blocks and Longest-Chain ConsensusThe rule that settles double-spends: this chapter contains zero cryptography
8Incentives and IssuanceBlock rewards, halving, 21 million: making the machine run itself
9Forks and UpgradesChanging the rules with nobody in charge

Part IV · Surviving the long run

ChTitleWhat you build by hand
10Fees and Difficulty AdjustmentTwo negative-feedback loops that keep the system steady
11Merkle Trees and Efficient VerificationProve a transaction is in a block without downloading the block
12Mempool, Fee Market, ConfirmationsRBF, CPFP, reorgs: why your transaction is stuck
13Switching to the Real CurveSwap the toy curve for the one Bitcoin actually uses

Part V · Toward real engineering

ChTitleWhat you build by hand
14The Script VMSpending conditions are not a database field; they are a running program
15Wallets and HD Key TreesHow twelve words grow a thousand addresses
16Hardware SigningWhy the private key lives in a room with no network cable
17A Multi-Node NetworkRun your chain across several machines and watch them converge
18Why Script Is Deliberately WeakHow loops, global state, and one bad opcode could kill every node

Appendices

AThe cryptography map: roads this book does not take (encryption, zero-knowledge proofs, MPC)
BWhy a quantum computer breaks public keys but not hashes
CCHECKSIG vs CSFS: same lamp, different piece of paper

One thread

bytes → hash → commitment → finite field → elliptic curve → public key → signature → chain → mining → transactions → consensus → incentives → upgrade coordination → efficient verification → the real curve → mempool and confirmations → Script → wallets → hardware signing → a real network → the limits of the script engine

Later chapters reuse functions you wrote in earlier ones. Read in order.

Other ways to read it