दुर्गा बेरागी Durga Beragi, homeEnter the study →

Library › Cryptography, blockchain and crypto

Mastering Bitcoin

Andreas M. Antonopoulos · 2014 · O'Reilly

More by Andreas M. Antonopoulos on this shelf · 2 books →

How Bitcoin works underneath: keys, transactions, the chain.

Read the full text free · 112,005 words · 17 parts

About the book

Andreas Antonopoulos, a technologist and educator, published Mastering Bitcoin in 2014 through O'Reilly. A second edition followed in 2017 and a third, with David Harding, in 2023. The book explains Bitcoin's internal workings for developers and technical readers. Chapters cover how Bitcoin works at a high level, the Bitcoin Core software, keys and addresses, wallets, transactions, advanced transactions and scripting, the peer-to-peer network, the blockchain, mining and consensus, and security. Later editions added material on segregated witness, payment channels and the Lightning Network. The text includes command-line examples and code samples. The book was later released under an open licence and can be read free on GitHub.

Key ideas

  • Bitcoin ownership is control of private keys. Addresses are derived from public keys, and spending requires a digital signature made with the matching private key.
  • Bitcoin tracks unspent transaction outputs rather than account balances. Each transaction consumes previous outputs and creates new ones, and wallets add these up to show a balance.
  • Spending conditions are written in a simple, deliberately limited script language. Standard scripts check signatures, while more complex ones support multisignature, escrow and time-locked payments.
  • Hierarchical deterministic wallets generate many keys from one seed, which can be backed up as a short list of words. This makes key management practical.
  • Mining secures the chain through proof of work. Miners compete to find a block hash below a target, and the difficulty adjusts so blocks arrive about every ten minutes.
  • Consensus emerges from independent verification. Every full node checks every block and transaction against the rules, and the chain with the most accumulated work is accepted.

Why it is on this shelf

It is the standard technical explanation of Bitcoin, written for people who build software. Anyone working in crypto should understand keys, UTXOs, scripts and mining at this level. It is precise, current in later editions and free to read online.

How to start reading it

Read the introduction and the chapter on how Bitcoin works. Then read keys and addresses, wallets and transactions carefully, running the examples if you can. Read the mining and consensus chapter next.

About this book

Mastering Bitcoin is a technical book about how Bitcoin works beneath its surface. Andreas M. Antonopoulos wrote it, and O'Reilly Media published the first edition in 2014. A second edition appeared in 2017, and a third, written with the Bitcoin developer and writer David A. Harding, in 2023. Each edition updated the material to follow changes in the protocol and in the software people use to run it.

The book was written for developers and technically minded readers. By 2014 Bitcoin had been running for five years, had passed through its first large price boom, and had attracted a crowd of programmers who wanted to build on it. What they lacked was a single, careful explanation of the system as it actually worked: not the white paper's sketch, not scattered forum posts and code comments, but an organised account from keys to blocks. Antonopoulos set out to provide one.

The question the book answers is concrete. What exactly happens when someone holds, sends and receives bitcoin, and how do thousands of computers that do not trust each other agree on who owns what? The answer is built up from parts: a kind of cryptography, a way of recording ownership, a small programming language for spending conditions, a network for passing messages, a data structure for storing history, and a competitive process for adding to that history. The book explains each part and then how they fit.

Its method suits its readers. It shows real data structures, real command-line interactions with Bitcoin software, and short programs in common languages. It uses a small cast of example users buying coffee or paying for services to anchor abstract ideas in familiar transactions. It moves between explanation and demonstration so that a reader can check claims against a running system.

An unusual fact about the book shapes how it is read. After its first publication, it was released under a Creative Commons licence, and its source text is maintained publicly on GitHub, where readers have contributed corrections. This makes it partly a community document, and it is one reason the book became the standard technical reference for a generation of Bitcoin developers. The printed editions are still sold, and are worth owning, but the open text means that anyone who wants to check this companion against the original can do so freely.

This companion does not reproduce the book's code, diagrams or worked examples. It explains, in our own words and with our own examples, the ideas a reader must understand to get the most from it, and places the book in the wider history and literature of the field.

The author

Andreas M. Antonopoulos is a technologist, speaker and writer who became one of the best-known public educators about Bitcoin. He grew up in Greece and studied computer science in the United Kingdom, at University College London. Before Bitcoin he worked in networking, information security and technology consulting, and wrote about those subjects for trade publications. That background shows in the book: it treats Bitcoin first as a distributed network and a security system, and only second as money.

He came to Bitcoin around 2012 and quickly became known for talks that explained the technology to non-specialists and argued for its social importance. Collections of these talks were later published as a series of books under the title The Internet of Money. He co-hosted a long-running Bitcoin podcast and appeared before parliamentary committees in Canada and Australia to explain digital currencies to legislators.

Mastering Bitcoin led to two companion technical books. Mastering Ethereum, written with Gavin Wood, a co-founder of Ethereum, appeared in 2018 and is also on this shelf. Mastering the Lightning Network, written with Olaoluwa Osuntokun and Rene Pickhardt, appeared in 2021 and covers the payment-channel system built on top of Bitcoin. Together the three books form a technical library on the main public blockchains.

Two traits of his work matter for reading this book. First, he is a teacher before he is an engineer: he is willing to repeat an idea in several forms until it is clear, and he uses analogies freely. Second, he is an advocate. He believes that open, permissionless networks are socially important, and this belief colours his choice of emphasis. The technical content is careful and widely trusted, but the framing around it is not neutral, and a reader should notice where description ends and advocacy begins.

David A. Harding, co-author of the third edition, is known for detailed technical writing on Bitcoin, including developer documentation and a long-running weekly newsletter on Bitcoin development. His contribution brought the book up to date with changes such as Taproot and modernised its treatment of wallets and transactions.

The shape of the argument

Mastering Bitcoin is not an argument in the way a work of economics is. It is an explanation, and its structure follows a principle familiar from good engineering teaching: start with what the user sees, then descend layer by layer into how it is achieved, then rise again to the whole system and its guarantees.

The opening part gives a high-level picture. It introduces Bitcoin as a system with no central authority, shows a simple payment from the user's side, and gives the reader enough of a mental model to make sense of the details. It also introduces the software that runs the network and invites the reader to interact with it.

The central part of the book concerns ownership and transfer. This is where most of its pages and most of its value lie. It explains the cryptographic keys that define ownership, the ways those keys are encoded and stored, the structure of a transaction, and the small scripting language that decides who may spend what. Later editions spend a good deal of space here on improvements made to transactions and scripts over the years.

The third part concerns agreement. It describes the network that carries transactions and blocks between computers, the structure of the chain itself, and the mining process that orders transactions and makes history hard to rewrite. This is where the book explains why the system works at all without a central party.

The final part turns outward: to security for users and developers, to applications that can be built on the system, and to layered systems such as payment channels. These chapters are more varied and change most between editions.

Two features of the book's presentation deserve mention. First, it returns again and again to the same small set of example users and payments, so that each new layer of detail attaches to something already familiar. Second, it alternates freely between conceptual explanation and hands-on demonstration. A reader who prefers ideas can skim the demonstrations; a reader who learns by doing can run them. Both kinds of reader are served, but each should know which parts are written primarily for the other.

A reader should hold on to one organising idea throughout. Bitcoin solves two problems: proving who may spend a coin, and agreeing on which spends actually happened and in what order. The first problem is solved by cryptography and scripts. The second is solved by the network, the chain and mining. Almost every chapter belongs to one of these two problems, and knowing which helps the reader keep the whole in view.

Idea one: ownership is control of a key

The first idea is the foundation of everything else. In Bitcoin there is no register of names. Nobody owns bitcoin in the way someone owns a bank account. Instead, the system records conditions under which amounts can be spent, and the usual condition is the ability to produce a valid digital signature with a particular private key. Whoever controls the key controls the coins. This is the precise meaning of ownership in Bitcoin.

A private key is simply a very large random number, chosen from a range so vast that two people picking at random will in practice never pick the same one. From the private key, a public key is computed using elliptic curve cryptography. Bitcoin uses a specific curve called secp256k1. The computation runs easily in one direction and is, as far as anyone knows, infeasible to reverse. Anyone can derive the public key from the private key, but nobody can derive the private key from the public key.

An analogy helps, though like all analogies it is imperfect. Think of mixing paint. Starting from a secret colour and a standard base, you can quickly mix a resulting shade that you show to the world. But given only the shade and the base, nobody can work out your secret colour. Elliptic curve operations play the role of mixing: easy forward, hard backward. A signature is a way of proving you know the secret colour without revealing it.

From the public key, a shorter identifier is usually derived by hashing, and this is what people call an address. Addresses are encoded in formats designed to be typed or scanned with low risk of error, with built-in checksums that catch most mistakes. Over Bitcoin's history several address formats have been used, and later editions of the book explain the newer ones, which are more efficient and more resistant to errors.

The consequence of this design is stark. Lose the key and the coins are lost, with no one to appeal to. Reveal the key and anyone can take the coins, with no way to reverse it. This is why the phrase not your keys, not your coins became a slogan. It is not a figure of speech. It is a literal description of how the system works.

Everything depends on the randomness of the private key. If a key is chosen from a small or predictable range, such as a number derived from a short phrase a person remembers, attackers can simply try likely candidates. This has happened. Early tools that turned memorable sentences into keys led to coins being taken within moments of being received. Weak random number generators in some software produced repeated values that let attackers compute private keys from public signatures. The book's insistence on proper randomness is not pedantry; it is a lesson learned from real losses.

A common confusion is to think that coins are stored in a wallet or on a device. They are not. What is stored is the key. The coins, in the sense of recorded spendable amounts, exist only on the shared ledger that every full node keeps. A wallet is better thought of as a keyring.

This idea leads to the whole subject of custody: how keys are generated, stored, backed up, split and protected. Much of the rest of the book, and much of the industry's history of losses, follows from it.

Idea two: outputs, not accounts

The second idea is the one most newcomers find strange. Bitcoin does not keep account balances. It keeps a set of unspent transaction outputs, usually shortened to UTXOs. Each output is an amount of bitcoin locked by a condition, usually tied to a key. A transaction consumes some existing outputs in full and creates new ones. Your balance is not stored anywhere; your wallet calculates it by adding up all the unspent outputs it can unlock.

Cash in a pocket is the best analogy. Suppose you have a twenty-rupee note and a fifty-rupee note, and you want to pay sixty. You cannot tear off part of a note. You hand over both notes, seventy in total, and receive ten back in change. Bitcoin works the same way. To pay an amount, a wallet selects outputs whose total is at least that amount, spends them completely, creates one output for the recipient and usually another, the change, back to itself.

A worked example in our own numbers may help. Suppose Meera's wallet controls three unspent outputs: 0.2, 0.05 and 0.4 bitcoin. She wants to pay Ravi 0.3. Her wallet could choose the 0.4 output alone. It builds a transaction with that one input, an output of 0.3 locked to Ravi's address, and an output of slightly under 0.1 locked to a fresh address of her own. The small amount missing from the change is the fee. After the transaction confirms, the 0.4 output no longer exists. In its place are two new outputs. Meera's wallet now sees 0.2, 0.05 and her change, and shows a balance that is their sum. Nothing called a balance was ever written to the chain.

Fees work differently from what most people expect. There is no fee field in a Bitcoin transaction. The fee is whatever is left over: the total of the inputs minus the total of the outputs. If a wallet forgets to create a change output, the entire difference goes to the miner as a fee. This has happened in practice, which is one reason careful wallet software matters.

Why design it this way? Several reasons emerge from the book. Outputs make it simple to check that no coin is spent twice: each output can be spent exactly once, and nodes only need to track which ones are still unspent. Outputs allow many independent conditions to coexist, since each carries its own lock. And they allow transactions to be checked in parallel, because each depends only on the specific outputs it spends rather than on a global account state.

The design has costs. Every payment tends to create a change output, so the number of outputs grows. Linking change outputs to their owners is one of the main ways observers track people's coins, which affects privacy. And building transactions requires choosing which outputs to spend, a problem called coin selection that wallets solve in different ways with different trade-offs between fees and privacy.

This model is often contrasted with the account model used by Ethereum, in which each address has a balance that transactions increase or decrease. Neither is simply better. Accounts are easier to reason about for complex programs; outputs are easier to verify and to keep private. A reader who later turns to Mastering Ethereum on this shelf will understand both more deeply for having seen the contrast.

Idea three: a deliberately small language for spending

Every output carries a lock, and every input that spends it must supply a key that fits. In Bitcoin both lock and key are written in a small programming language called Script. Script is stack-based: it works by pushing values onto a pile and applying operations to the top items. It has no loops and is intentionally limited. A script either succeeds, allowing the spend, or fails.

The most common lock says, in effect: to spend this, provide a public key whose hash matches this value, and a valid signature made with the corresponding private key. The spender supplies the public key and signature; the network runs the combined script and checks the result. This simple pattern accounts for a large share of ordinary payments.

Because the language is general within its limits, other locks are possible. A multisignature lock can require two of three named keys to sign, useful for joint accounts, escrow, or protecting a company's funds from a single dishonest employee. A time lock can prevent spending until a certain block height or time has passed, useful for inheritance plans or delayed payments. Locks can combine these: for example, two of three keys now, or any one key after a year.

Why limit the language? The book explains the reasoning. Every full node must run every script to check every transaction. If scripts could loop forever or consume unbounded resources, an attacker could stall the network with a single transaction. Keeping the language small makes the cost of verification predictable and the attack surface narrow. It also makes the behaviour of scripts easier to reason about, which matters when money depends on them.

Over time, Bitcoin added mechanisms to make scripts more practical. One innovation allowed a payment to be sent to the hash of a script rather than to the script itself, so that the sender need not know the details of a complex lock; the recipient reveals the full script only when spending. Later upgrades extended this idea, so that complex conditions could be hidden unless actually used, saving space and improving privacy. The third edition of the book covers these developments.

There is also a narrow way to write data into the chain without creating a spendable output, using an operation that marks an output as provably unspendable and allows a small amount of arbitrary data to follow. It was introduced partly to discourage people from stuffing data into fake addresses, which burdened every node with outputs that could never be spent. Whether and how much non-payment data the chain should carry has been a recurring argument, and the book's treatment of this feature gives the reader the background to follow that argument.

A frequent confusion is to call Bitcoin scripts smart contracts in the sense used by Ethereum. They are related but different. Bitcoin's scripts are conditions on spending, checked once; they do not hold ongoing state or run as independent programs. That difference is a design choice, not a failure, and it reflects Bitcoin's priority on security and simplicity over flexibility.

This idea leads directly to layered systems. Payment channels and the Lightning Network, discussed later in this edition, are built entirely from these modest scripting tools, combined cleverly. The limits of the language turned out to be a foundation rather than a ceiling.

Idea four: one seed, many keys

Early Bitcoin wallets generated a fresh random key for each address and stored them all in a file. Backing up such a wallet was difficult, since every new key required a new backup, and lost backups meant lost coins. The fourth idea solves this: hierarchical deterministic wallets, which derive an entire tree of keys from a single random starting value called the seed.

The method is a chain of one-way calculations. From the seed, a master key is computed. From the master key, child keys are computed in a numbered sequence, and from each child, grandchildren, and so on. Because each step is deterministic, the same seed always produces the same tree. Because each step is one-way, knowing a child key does not reveal its parent. A wallet can therefore generate as many addresses as it needs while the user backs up only the seed, once.

The seed is usually presented to the user as a list of twelve or twenty-four ordinary words drawn from a fixed list. Words are easier than long numbers to write down accurately and to check. This standard became so common that the phrase seed words, or recovery phrase, is now familiar to anyone who has used a self-custody wallet.

A further feature is the ability to separate public and private branches. From a parent public key and some extra data, it is possible to derive child public keys without any private key. This lets a shop's web server generate fresh receiving addresses for each customer while the private keys stay offline. A thief who breaks into the server gets no ability to spend.

An analogy: think of a master locksmith who can cut any key in a building from a single pattern, and who can give the building manager a device that produces new locks, but not keys. The manager can install fresh locks on every door without ever being able to open them.

Because the tree can be very large, wallet makers agreed on conventions for which branch holds which kind of key: one branch for each account, within it one branch for receiving addresses and another for change, each numbered in sequence. These conventions, called derivation paths, let a seed created in one wallet be restored in another. When conventions differ, a restored wallet may appear empty even though the coins are safe on the chain, simply because the software is looking in the wrong branch. The book's discussion of these standards explains a problem many users meet without understanding.

The common confusion here is to treat the seed as a password. It is not. A password can be reset by a service. A seed is the ownership itself. Anyone who reads it has everything. This is why the book's guidance on storing seeds is serious and why the design of seed backups, including splitting them and storing them on durable materials, is a whole field of practice.

Idea five: the chain as a tamper-evident record

Transactions are grouped into blocks, and blocks are linked into a chain. The fifth idea is how this linking makes history difficult to change. Each block has a header containing, among other things, a hash of the previous block's header and a summary of all the block's transactions. Change any transaction in an old block and its summary changes, which changes that block's hash, which breaks the link from the next block, and so on to the present.

The summary is built with a Merkle tree. Transactions are hashed in pairs, then the pairs' hashes are hashed in pairs, and so on until one hash remains, called the Merkle root. This root goes in the block header. The structure has a useful property: one can prove that a particular transaction is in a block by providing only a small number of hashes along the path from the transaction to the root, rather than the whole block. This allows lightweight clients to check that a payment was included without downloading everything.

An analogy: imagine a ledger book where every page ends with a fingerprint of all the writing on that page, and the next page begins by copying that fingerprint. To alter an entry on an early page, a forger must recompute the fingerprint of that page and every page after it. In an ordinary book this is tedious but possible. In Bitcoin, mining makes each recomputation very expensive, as the next idea explains.

It is important to see what the chain does and does not guarantee. It guarantees that anyone holding the chain can detect tampering. It does not by itself guarantee that everyone holds the same chain. Two valid chains might compete. Choosing between them is the job of consensus, which depends on mining.

The confusion to avoid is thinking that hashing alone makes the chain secure. Anyone can build a perfectly linked chain of fake blocks. What makes Bitcoin's chain authoritative is the cost embedded in it through proof of work, and the rule that nodes follow the valid chain with the most accumulated work.

There is a practical side to this structure that the book makes clear. Because the header is small and contains the Merkle root and the link to the previous block, the entire history of headers since 2009 is modest in size even though the full chain of transactions is very large. A device can keep all headers, verify the work in them, and request proofs for only the transactions it cares about. The split between small header and large body is one of the quiet design decisions that keeps the system usable on ordinary hardware.

Idea six: proof of work turns electricity into history

Mining is the process by which new blocks are added. The sixth idea is how mining makes the chain costly to rewrite and how it ties the system's security to real-world resources. To produce a valid block, a miner must find a header whose hash, a fixed-length number produced by the SHA-256 function applied twice, is below a target value. There is no shortcut. The only method is to try header after header, changing a small field each time, until one happens to produce a low enough hash.

A lottery analogy works well. Each attempt is a ticket. Each ticket has a tiny chance of winning. Miners buy tickets with electricity and computing hardware. Whoever holds a winning ticket publishes the block and collects the reward. Anyone can check a winning ticket instantly, because checking a hash takes one calculation. Finding it takes, on average, an enormous number.

The target is adjusted so that, across the whole network, a block is found about every ten minutes on average. Every 2,016 blocks, roughly two weeks, each node compares how long those blocks actually took with how long they should have taken and adjusts the target. If miners have added hardware and blocks came quickly, the target falls and the puzzle becomes harder. If miners have left, it eases. This feedback loop keeps the issuance schedule steady regardless of how much computing power joins or leaves.

The reward for a block has two parts. The first is a block subsidy of newly created bitcoin, which began at fifty and halves every 210,000 blocks, roughly every four years. The second is the total of fees from the transactions included in the block. Because the subsidy keeps halving, the total supply approaches a limit just under twenty-one million coins. Over time, fees are expected to become the main reward for miners, and whether they will be enough to secure the network is an open question that later editions discuss.

Why does this protect history? To change a transaction in a past block, an attacker must redo the work for that block and every block after it, and then overtake the honest chain, which keeps growing. Unless the attacker controls more computing power than all honest miners combined, the chance of catching up shrinks rapidly with each additional block. This is why recipients of large payments wait for several confirmations: each block added on top makes reversal less likely.

Mining has changed greatly since the early years. At first, people mined with ordinary computer processors. Then they moved to graphics cards, then to programmable chips, and finally to specialised chips designed only to compute this one hash function as fast and efficiently as possible. Because each miner's chance of finding a block is small and irregular, miners usually join pools, which combine their work and share rewards in proportion to effort. This smooths income but concentrates the choice of which transactions go into blocks in the hands of pool operators. The book explains how pools work and why their concentration is a concern.

The common confusion is that miners decide the rules. They do not. Miners decide the order of valid transactions and which ones to include. Whether a block is valid is checked independently by every full node. A miner who produces a block that breaks the rules, for example by paying itself too much, simply wastes its work, because nodes reject the block.

This idea leads to Bitcoin's most debated feature: its energy use. The security of proof of work comes precisely from the cost of the work. Critics regard that cost as waste. Supporters regard it as the price of a system that needs no trusted party. The book explains the mechanism; the reader must weigh the trade-off.

Idea seven: consensus without a coordinator

The seventh idea is the one that makes Bitcoin novel. Thousands of independent computers, run by people who do not know or trust each other, end up agreeing on a single history of transactions. There is no vote, no leader and no central server. Agreement emerges because every participant applies the same rules independently and follows the same simple choice rule.

Each full node receives transactions and blocks from its peers. It checks each one against the full set of rules: signatures valid, scripts succeed, no output spent twice, block reward correct, proof of work sufficient, and many more. It discards anything invalid. Among the valid chains it knows, it adopts the one with the greatest total proof of work. Because all honest nodes apply the same rules and the same choice, they converge on the same chain.

Sometimes two miners find blocks at nearly the same time, and the network briefly holds two competing tips. Nodes keep both and work on whichever they saw first. When the next block is found on one of them, that branch has more work and every node switches to it. The other block is abandoned and its transactions return to the pool of waiting transactions. Such short reorganisations are normal and are why one confirmation is weaker than six.

An analogy: imagine many scribes in different towns copying a shared chronicle, each receiving new pages by post. Each scribe checks every page for forgery before adding it. When two different pages arrive for the same place, each scribe keeps both and waits. Whichever version receives the next valid page first is the one everyone keeps. No archbishop is needed to rule on the dispute. The rules and the arrival of more work settle it.

The limits of this system are worth stating precisely. If one party controlled a majority of the network's mining power, it could not steal coins it does not hold keys for, and it could not create blocks that break the rules, since nodes would reject them. What it could do is reverse its own recent payments by building a longer private chain and releasing it, and it could refuse to include particular transactions. This is often called a majority attack. Its power is real but narrower than many popular accounts suggest, and understanding exactly what it can and cannot do is one of the clearest tests of whether a reader has grasped how consensus works.

This is where the distinction between full nodes and miners matters. Miners propose; nodes verify. A person who runs a full node does not need to trust any miner, exchange or developer to know that their coins are real and that the rules have been followed. The book stresses this, because it is the source of Bitcoin's claim to be trustless. Without independent verification, the system would reduce to trusting whoever runs the servers.

The common confusion is to imagine that Bitcoin's rules are fixed by some authority. They are maintained in software, but nobody can force anyone to run a particular version. Rules change only when enough of the network's users, node operators and miners adopt a change. This makes Bitcoin's governance slow and contested, which its supporters regard as a strength and its critics as a weakness.

This leads naturally to forks. A soft fork tightens the rules, so that blocks valid under the new rules remain valid under the old; old nodes continue to follow the chain. A hard fork loosens or changes rules so that old nodes reject new blocks; if not everyone upgrades, the network splits into two chains. In 2017 a disagreement over block size led to such a split, producing a separate currency. The book discusses the mechanics of both kinds of fork and why Bitcoin's developers strongly prefer soft forks.

Idea eight: a network that gossips

Underneath the chain is a peer-to-peer network. The eighth idea is how this network spreads transactions and blocks quickly and robustly without central servers. Each node connects to a handful of others. When it learns of a new transaction or block, it tells its peers, who tell theirs. Within seconds, information reaches most of the network.

This design is resilient. There is no single server to switch off. A node that joins needs only to find a few peers, which it does through a mix of built-in seed addresses and addresses learned from others. If some peers lie or vanish, it connects to different ones. As long as it is connected to at least one honest peer, it will eventually learn the valid chain with the most work.

The network serves different kinds of participants. Full nodes download and check everything. Lightweight clients, common on phones, download only block headers and ask full nodes for the transactions that concern them, along with proofs that those transactions are in blocks. This saves space and bandwidth but means trusting that the full nodes they talk to are not hiding transactions. The book explains these trade-offs carefully, and later editions describe improved methods for lightweight clients that leak less about which addresses they care about.

Speed matters for mining fairness. If a new block takes a long time to reach other miners, the miner who found it gains a head start on the next one, which favours large, well-connected miners. Developers have introduced techniques to send new blocks compactly, relying on the fact that most nodes already have most of the block's transactions in memory. This reduces the time to spread a block across the world.

An analogy: the network behaves like news in a village with no newspaper. Anyone who hears something important tells their neighbours, who tell theirs. Rumours that fail a basic check are not repeated. No one needs to own the village square for news to travel.

The confusion to avoid is thinking that the network is anonymous. Nodes see the internet addresses of their peers, and an observer who controls many nodes can sometimes guess where a transaction first appeared. Users who care about privacy route their connections through anonymity networks such as Tor, which Bitcoin software supports.

Idea nine: upgrading a system no one controls

The ninth idea is how a protocol with no owner changes over time. Bitcoin has been upgraded many times, usually through soft forks, after long public discussion and careful testing. Changes are proposed in public documents called Bitcoin Improvement Proposals, debated on mailing lists and forums, implemented in software, and activated only after a sufficient share of miners or users signal support.

The most significant upgrade covered in the second edition is Segregated Witness, activated in 2017. It moved signature data into a separate structure within each transaction. This fixed a long-standing problem called transaction malleability, in which a third party could alter a transaction's identifier without invalidating it, which complicated building transactions that depend on unconfirmed ones. Fixing this was essential for payment channels. Segregated Witness also changed how block size is measured, allowing more transactions per block while remaining compatible with old nodes.

The most significant upgrade covered in the third edition is Taproot, activated in 2021. It introduced a different signature scheme, Schnorr signatures, which allows several signers to combine their keys and signatures so that a multi-party spend can look like an ordinary single-party one. It also allowed complex spending conditions to be committed to without revealing them, so that only the condition actually used appears on the chain. The results are smaller transactions, better privacy and more flexible contracts.

An analogy for soft forks: imagine a club that has always allowed members to wear any shoes. A new rule says only black shoes. Old members who never heard of the rule still accept everyone in black shoes, since those are within the old rule too. New members enforce the stricter rule. The club never splits, because everything the new members accept, the old ones accept as well. Soft forks in Bitcoin work by this principle, which is why they are preferred.

The confusion to avoid is thinking that developers can change Bitcoin at will. They can write code, but users must choose to run it. Several proposed changes have failed for lack of support, and the 2017 split showed that a determined minority can leave rather than accept a change it opposes. The governance of Bitcoin is a social process wrapped around a technical one.

This idea leads to a theme that runs through the third edition: the protocol is not finished. Upgrades are slow, but they continue, and a reader of any edition should check which features have since changed.

Idea ten: security is mostly about people and keys

The tenth idea concerns what can go wrong. The book's treatment of security makes a point that many readers do not expect. The Bitcoin protocol itself has been remarkably robust. Most losses have come from the edges: stolen keys, hacked exchanges, malware on personal computers, phishing, mistakes in wallet software, and simple loss of backups.

The principle that follows is decentralise custody, minimise trust, and reduce the attack surface. Keep only small amounts on devices connected to the internet. Use dedicated hardware wallets that sign transactions without exposing keys to the computer. Use multisignature arrangements so that no single compromised key or person can move funds. Keep backups in more than one place, and protect them from fire, water and curious eyes.

An analogy from older forms of wealth helps. A household that keeps all its gold in one box under the bed is exposed to one burglar. A household that keeps a little cash in a wallet, savings in a safe, and the rest in a locked vault requiring two signatures is much harder to rob. Bitcoin gives individuals the ability to build such arrangements for themselves, without a bank, but it also gives them the full responsibility of doing so.

The book also discusses the security of systems built on Bitcoin. Services that hold customers' coins concentrate risk, and the history of exchange failures shows the cost. The design of a secure service includes keeping most funds in cold storage, requiring several people to approve large movements, and auditing reserves. These are organisational as well as technical matters.

The confusion to avoid is believing that because the protocol is secure, any use of it is safe. A strong lock does not help if the key is left under the doormat. The book's emphasis here is one of its most practical contributions.

Idea eleven: layers on top of the chain

The last key idea concerns scaling. Bitcoin's base chain processes a limited number of transactions per second, by design, so that ordinary computers can verify everything. The question is how to support many more payments without giving up that property. The answer the book describes is layering: perform most transactions off the chain, using the chain only to open, close and settle disputes.

A payment channel is the basic building block. Two parties lock funds into a shared output that needs both their signatures. They then exchange signed but unpublished transactions that redistribute those funds, updating the split each time one pays the other. Only the final state needs to be published to the chain. Mechanisms built from time locks and penalty conditions ensure that if one party tries to publish an outdated state, the other can claim all the funds.

The Lightning Network links many such channels into a network. A payment can travel from one person to another through intermediaries, each forwarding it along a channel, without any of them being able to steal it. This is made possible by a construction that ties each hop's payment to the same secret value, so that either all hops complete or none do.

An analogy: imagine a bar tab. Instead of paying for each drink, you open a tab, run it up over an evening, and settle once at the end. A payment channel is a tab with cryptographic guarantees, so neither side has to trust the other to keep honest records. The Lightning Network is a system in which tabs can be chained between strangers through mutual acquaintances.

Layering is not limited to payment channels. The general pattern, in which the base chain acts as a court of final appeal while ordinary business happens elsewhere, appears in many proposals. Some move assets to separate chains with their own rules; others let groups share control of a single on-chain output. Each design trades some of the base chain's independence for speed or flexibility. The book's treatment gives the reader the tools to ask of any such design the one question that matters most: if things go wrong, what does a user need to do, and by when, to get their money back through the base chain?

The confusion to avoid is thinking that layers make the base chain unnecessary. Every channel depends on the chain to enforce its rules in case of dispute, and the security of the layer is no better than that of the chain beneath. Layers also bring their own costs: funds must be locked in channels, nodes must stay online or delegate watching, and routing payments across a network brings practical difficulties. The book treats Lightning as a promising development with real limits, and Antonopoulos's later book on it goes much further.

The tradition around it

Mastering Bitcoin stands on a long line of cryptographic and economic work, much of which is represented on this shelf. The mathematics of public-key cryptography, hash functions and digital signatures is covered rigorously in Introduction to Modern Cryptography by Katz and Lindell and in Koblitz's A Course in Number Theory and Cryptography, which also explains elliptic curves. The Handbook of Applied Cryptography by Menezes, van Oorschot and Vanstone is the classic reference for the underlying algorithms. Serious Cryptography by Aumasson and Cryptography Engineering by Ferguson, Schneier and Kohno show how such primitives are used safely in practice, which is the same engineering spirit that runs through Antonopoulos's chapters on security.

The historical background is in Levy's Crypto, Singh's The Code Book and Kahn's The Codebreakers, which together tell the story of secret writing up to the age of public-key methods. Greenberg's This Machine Kills Secrets covers the cypherpunk culture from which Bitcoin emerged. These books explain why someone would want to build Bitcoin; Mastering Bitcoin explains what was built.

The most direct companion is Bitcoin and Cryptocurrency Technologies by Narayanan, Bonneau, Felten, Miller and Goldfeder, an academic textbook that covers the same mechanisms with more formal attention to incentives, attacks and alternative designs. Readers who find Antonopoulos's account too practical will find more theory there; readers who find the textbook abstract will find Antonopoulos more concrete. Reading both is the best preparation for serious work.

On the narrative side, Popper's Digital Gold and Vigna and Casey's The Age of Cryptocurrency describe the people and events of Bitcoin's early years, which gives context to the design choices Antonopoulos explains. On the economic side, Hayek's Denationalisation of Money and Ammous's The Bitcoin Standard argue about what money should be, and Mastering Bitcoin provides the technical basis for judging their claims.

After Mastering Bitcoin, the natural next technical book is Mastering Ethereum, by Antonopoulos and Gavin Wood, which explains a system built on different choices: accounts instead of outputs, a general-purpose programming environment instead of a limited script. Camila Russo's The Infinite Machine tells Ethereum's history. Werbach's The Blockchain and the New Architecture of Trust examines the legal and institutional questions that arise when such systems meet the wider world. Dixon's Read Write Own makes the case for building internet services on these foundations, while Shin's The Cryptopians, Faux's Number Go Up and Lewis's Going Infinite show where speculation and fraud led parts of the industry, often far from the careful engineering this book describes.

Questions and criticisms

The first criticism is about change. A technical book on a live protocol ages. The first edition predates Segregated Witness; the second predates Taproot. Some commands, software interfaces and recommended practices described in earlier editions are now outdated. The authors have answered this with new editions and the open text, but a reader with an older copy should check what has changed before relying on details.

The second criticism is about advocacy. Antonopoulos is a committed proponent of Bitcoin and of open networks in general. The book is careful on mechanisms, but its framing tends to emphasise strengths and treat weaknesses as problems to be solved. Readers looking for a balanced assessment of Bitcoin's economic role, environmental cost or social effects should look to other sources. The book is a manual, not a judgement.

The third concerns the depth of the cryptography. The book explains keys, hashes and signatures at the level a developer needs to use them correctly. It does not prove anything, and its analogies, like the ones in this edition, are approximations. A reader who wants to understand why elliptic curve discrete logarithms are believed to be hard, or what exactly a hash function guarantees, must turn to the mathematical books on this shelf.

The fourth concerns scaling and fees. Earlier editions were written when fees were low and blocks often partly empty. Since then, periods of high demand have pushed fees up sharply, and debates over how to scale, including the 2017 split, have been bitter. Whether layered systems like Lightning will carry the bulk of payments remains unsettled. The book's account of scaling should be read as describing a direction, not a solved problem.

A fifth concerns privacy. Bitcoin is often described in the book as pseudonymous, which is accurate, but practical experience has shown that tracing coins through the public ledger is easier than early users hoped. Companies now specialise in this analysis, and law enforcement relies on it. The book's later editions acknowledge privacy weaknesses and describe improvements, but a reader should not come away thinking that ordinary Bitcoin use is private.

What has held up is the core explanation. Keys, outputs, scripts, blocks, proof of work and consensus work today as the book describes them, because the protocol's foundations have been deliberately conserved. The book's clarity on these foundations is why it remains the standard reference more than a decade after its first appearance.

Why it is on this shelf

This shelf holds the history, mathematics and economics of cryptography and digital money. Mastering Bitcoin is the bridge between the mathematics and the money. It shows exactly how abstract tools such as hash functions and elliptic curve signatures become a working monetary system that has run continuously since 2009.

For a reader whose interests span Vedanta, Jyotish, science, economics and technology, the book offers something particular. It is an example of order emerging without a central authority, from many independent participants each following the same rules. Whatever one thinks of Bitcoin as an investment or a currency, that is a remarkable thing to study, and this book lets one study it at the level of mechanism rather than slogan.

It is also a lesson in exactness. Every claim in the book can be checked against the running system. A reader who works through it learns not only about Bitcoin but about how to read a complex system: identify the problems it must solve, the parts that solve each, and the assumptions on which those parts depend. That habit is useful far beyond this subject.

There is a further reason, closer to the shelf's other interests. Traditions of knowledge in many cultures stress that understanding must be tested against reality, not taken on authority. Bitcoin, at its best, applies this principle to money: do not trust, verify. A person running a full node checks for themselves that the rules have been kept. Whether or not one finds Bitcoin persuasive, the habit of verifying rather than trusting is a discipline worth practising, and this book is the most direct training in it that the subject offers.

We keep it because it is accurate, maintained, and open. It has taught a large share of the people who build on Bitcoin, and it remains the clearest single account of how the system works.

How to read it

Do not try to read it like a novel. Plan on several weeks at a slower pace, perhaps one major section every few days, with time between sessions to let the ideas settle. Have a computer nearby.

Begin with the high-level overview at the start. Read it twice if necessary, until you can explain to someone else, without notes, what happens when a payment is made from one wallet to another. Everything else depends on this picture.

Then read the material on keys, addresses and wallets with care. This is where a pencil helps most. Draw for yourself the path from a random number to a private key, to a public key, to an address, and from a seed to a tree of keys. Do not copy the book's diagrams; make your own, in your own notation. If you can reconstruct the path from memory a day later, you have understood it.

Next, read the material on transactions and scripts. Here it helps to work through a few transactions by hand: choose some imaginary outputs, decide on a payment, and write out the inputs, outputs, change and fee. Then trace a simple script on paper, pushing and popping values on an imaginary stack, until you see why it succeeds or fails.

On a first pass, skim the detailed byte-level layouts and encoding formats. They matter for developers, but they can bury the ideas. Return to them later if you plan to write software. Likewise, skim the command-line sessions on a first reading unless you have a node running; on a second reading, run them yourself if you can, on a test network where mistakes cost nothing.

Then read the sections on the network, the blockchain, and mining and consensus together, as one unit. They answer the second great problem, agreement, and they make most sense side by side. Pay particular attention to the explanation of why the chain with the most work wins and why confirmations matter.

Leave the chapters on security, applications and layered systems until last. They assume everything before them. When you reach them, read actively: for each application or layer described, write down which earlier mechanism it relies on, whether keys, scripts, time locks or confirmations. If you cannot name it, go back and find it. This turns the last part of the book into a review of the whole.

For further reading from this shelf, pair it with Bitcoin and Cryptocurrency Technologies for a more academic treatment, then move to Mastering Ethereum for the contrasting design. For mathematical foundations, use Koblitz or Katz and Lindell. For the human story, read Popper's Digital Gold. For the economic debate, read Hayek and Ammous, and test their claims against what you now know of how the system works.

Questions to carry

  • What exactly does it mean to own bitcoin, and what does not count as ownership?
  • Why does Bitcoin track unspent outputs rather than balances, and what does that choice cost?
  • Why is Bitcoin's scripting language deliberately limited, and what has been built from it anyway?
  • What does a seed phrase protect, and what single mistake would make it worthless?
  • Why is it hard to rewrite an old block, and how much harder does each new block make it?
  • What do miners decide, and what do full nodes decide?
  • How do independent nodes converge on one history without a coordinator?
  • Why do developers prefer soft forks to hard forks?
  • What changed with Segregated Witness, and why was it needed for payment channels?
  • What did Taproot add for privacy and efficiency?
  • Why have most losses of bitcoin happened at the edges rather than in the protocol?
  • Can fees alone pay for the network's security once the subsidy becomes small?
  • How private is ordinary Bitcoin use, and what makes tracing possible?
  • What does a payment channel depend on the base chain for?

Words to know

  • Private key: a large secret random number that allows its holder to sign transactions and so spend bitcoin.
  • Public key: a value derived from the private key, shared openly, used to check signatures.
  • Elliptic curve cryptography: the family of methods Bitcoin uses to derive public keys and make signatures; easy to compute forward, believed infeasible to reverse.
  • Address: a short, checksummed identifier derived from a public key or script, used to receive payments.
  • Digital signature: proof, made with a private key, that the holder authorised a specific transaction.
  • UTXO: unspent transaction output; an amount of bitcoin locked by a condition and not yet spent.
  • Change output: an output a wallet creates to send leftover value back to itself.
  • Transaction fee: the difference between the total inputs and total outputs of a transaction, collected by the miner.
  • Script: Bitcoin's small, stack-based language for writing spending conditions.
  • Multisignature: a spending condition requiring signatures from several keys, such as two of three.
  • Time lock: a condition preventing spending until a certain time or block height.
  • HD wallet: a hierarchical deterministic wallet that derives many keys from one seed.
  • Seed phrase: a list of words encoding the seed from which a wallet's keys are derived.
  • Block header: the small summary of a block, including the previous block's hash and the Merkle root.
  • Merkle tree: a structure of paired hashes that summarises many transactions in one hash and allows short proofs of inclusion.
  • Proof of work: evidence that much computation was spent, shown by a block hash below a target.
  • Difficulty adjustment: the change in target every 2,016 blocks that keeps the average block time near ten minutes.
  • Block subsidy: newly created bitcoin awarded to the miner of a block, halving roughly every four years.
  • Full node: software that downloads and independently verifies every block and transaction.
  • Lightweight client: software that checks headers and proofs without verifying the full chain.
  • Confirmation: the inclusion of a transaction in a block, with each later block adding one more.
  • Soft fork: a rule change that tightens the rules so that older nodes still accept new blocks.
  • Hard fork: a rule change that older nodes reject, which can split the network.
  • Segregated Witness: the 2017 upgrade that separated signature data and fixed transaction malleability.
  • Taproot: the 2021 upgrade that introduced Schnorr signatures and hidden spending conditions.

A note on this edition

This is a study edition written for this shelf in our own words. It explains the ideas a reader needs to work through Mastering Bitcoin, with our own examples and analogies, but it reproduces none of the book's text, code, diagrams or exercises, and it is no substitute for them.

The book itself is in copyright, though its authors have released its text under an open licence and maintain it publicly. The printed editions are worth getting from a library or bookshop, and the latest edition is the one to read. Where this companion mentions developments, it does so for context; for exact details of any protocol feature, the book and the protocol's own documentation are the authorities.

Terms from this book with their own page: Proof of work, Digital signature, Hard fork

More from “Cryptography, blockchain and crypto”

The whole section →