How does Bitcoin work?
Bitcoin is an electronic payment system created in 2009. It allows you to send money to anyone in the world, and you don’t need to ask anyone’s permission to create an account.
It was created as a solution to the modern financial system, where we have a small number of large banks that control who gets an account and which transactions get processed. This means the control of money is centralized, and we have to trust the banks to act responsibly.
Banks must be trusted to hold our money and transfer it electronically, but they lend it out in waves of credit bubbles with barely a fraction in reserve. – Satoshi Nakamoto
The centralization of banking and the resulting financial crisis of 2007 inspired the development of Bitcoin. It’s a payment system, and it runs without a central point of control. It was designed anonymously by Satoshi Nakamoto, and was released in January 2009.
Anyone can run the program or use the system.
The following is a simple explanation of how it works.
What is Bitcoin?
Bitcoin is just a computer program. You can download it and run it on your computer.
When you run the program, it will connect to other computers who are also running this program, and they will start sharing a file with you. This file is called the blockchain, and it is basically a big list of transactions.
When a new transaction enters the network, it gets relayed from computer to computer until everyone has a copy of the transaction. At roughly 10 minute intervals, a random computer (node) on the network will add the latest transactions they have received on to the blockchain, and share the updates with everyone else on the network.
As a result, the Bitcoin program creates a large network of computers that communicate with each other to share a file and update it with new transactions.
What problem does Bitcoin solve?
It was possible to relay transactions across a network of computers before Bitcoin. However, the problem is that you can insert conflicting transactions in to a network of computers. For example, you could create two separate transactions that spend the same digital coin, and send both of these transactions in to the network at the same time.
This is known as a “double-spend”.
So if you’re creating an electronic payment system without a central point of control, you have the problem of figuring out which of these transactions came “first”, and this is a difficult thing to do when you have a network of computers all acting independently. Some computers will receive the green transaction first, and some computers will receive the red transaction first.
Who’s to decide which one came “first” and should be the only one written to the file?
Bitcoin solves this problem by forcing nodes to keep all the transactions they receive in memory before writing them to a file. Then, at 10-minute intervals, a random node on the network will add the transactions from their memory on to the file.
This updated file is then shared with the network, and nodes will accept the transactions in the updated file as “correct”, removing any conflicting transactions from their memory. As a result, no double-spend transactions will ever be written to the file, and all nodes can update their files in agreement with one another.
The process of adding transactions on to the file is called mining, and it is basically a network-wide competition that cannot be controlled by a single node on the network.
How does mining work?
To start with, each node stores the latest transactions they have received in their memory pool, which is just temporary memory on their computer. Any node can then try and mine the transactions from their memory pool on to the file (the blockchain).
To do this, a node will gather the transactions from its memory pool in to a container called a block, and then use processing power to try and add this block of transactions on to the blockchain.
So where does this processing power come in? Well, to add this block to the blockchain, you must feed your block of transactions in to something called a hash function. A hash function is basically a mini computer program that will take in any amount of data, scramble it, and spit out a completely random (yet unique) number.
If your resulting block hash is not below the target, you can make a small adjustment to the data inside the block and put it through the hash function again. This will produce a completely different number that will hopefully be below the target. If not, you adjust the block and try again.
So in summary, the process of mining uses processing power to perform hash calculations as fast as you can to try and be the first computer on the network to get a block hash below the target. If you’re successful, you can add your block of transactions on to the blockchain and share it with the rest of the network.
NOTE: Although it is still possible for anyone to try and mine blocks, it is no longer competitive to do so on a home computer. There is now specialized hardware that has been designed to perform hash calculations as fast (and as efficiently) as possible, which means that mining is now mostly performed by those with access to specialized hardware and cheap electricity.
Where do bitcoins come from?
As an incentive to use processing power to try and add new blocks of transactions on to the blockchain, each new block makes available a fixed amount of bitcoins that did not previously exist. Therefore, if you are able to successfully mine a block, you are able to “send” yourself these new bitcoins as a reward for your effort.
This reward of new bitcoins is called the block reward, and is the reason why the process is called “mining”.
Why is the file called the “blockchain”?
As we have seen, transactions are not added to the file individually – they are collected together and added in blocks. Each of these new blocks builds on top of an existing one, and so the file is made up of a chain of blocks; hence, blockchain.
Furthermore, every node on the network will always adopt the longest chain of blocks they receive as the “official” version of the blockchain. This means that miners will always try to build on top of the “tip” of the longest known chain of blocks, as any blocks that are not part of the longest chain will not be considered valid by other nodes.
Therefore, if someone wanted to rewrite the history of transactions, they would need to rebuild a longer chain of blocks to create a new longest chain for other nodes to adopt. However, to achieve this, a single miner would need to have more computer processing power than the rest of the network combined.
As a result, the combined effort of the network makes it difficult for any individual to “outrun” the network and rewrite the blockchain.
How do transactions work?
You can think of the blockchain as being a storage facility for safe deposit boxes, which we call outputs. These outputs are just containers that hold various amounts of bitcoin.
So when you “send” someone bitcoins, you are actually placing an amount of bitcoins in to a new safe deposit box, and putting a lock on it that only the person you are “sending” the bitcoins to can unlock.
For example, if I wanted to send you some bitcoins, I would select some outputs from the blockchain that I can unlock, and create a new output from them that only you can unlock. Also, if I didn’t want to send you all of the bitcoins that I had unlocked, I would create an extra output as my “change” and lock it to myself.
Moving forward, if you want to send your bitcoins to someone else, you would repeat the process of selecting existing outputs (that you can unlock) and creating new outputs from them. As a result, bitcoin transactions form a graph-like structure, where the movement of bitcoins is connected by a series of transactions.
Lastly, when a transaction gets mined on to the blockchain, the outputs that were used up (spent) in the transaction cannot be used in another transaction, and the newly created outputs will be available to be moved on in a future transaction.
How do you own bitcoins?
To be able to “receive” bitcoins, you need to have your own set of keys. This set of keys is like your account number and password, except in Bitcoin they’re called your public key and your private key.
For example, if I wanted to send you some bitcoins, you would first need to give me your public key. When I create the transaction, I would place your public key inside the lock on the output (the safe deposit box). You would then use your private key to unlock this output when you want to send the bitcoins on to someone else.
So where can you get a public and private key? Well, with the help of cryptography you can actually generate them yourself.
In short, your private key is just a large random number, and your public key is a number calculated from this private key. But the clever part is; you can give your public key to someone else, but they cannot work out the private key from it.
Now, when you want to unlock bitcoins that are assigned to your public key, you use your private key to create what’s called a digital signature. This digital signature proves that you are the owner of the public key (and therefore can unlock the bitcoins), without having to reveal your private key. This digital signature is also only valid for the transaction it was created for, so it cannot be used to unlock other bitcoins locked to the same public key.
This system is known as “Public Key Cryptography”, and has been available since 19781. Bitcoin makes use of this system to allow anyone to create keys for sending and receiving bitcoins securely, without the need of a central authority to issue accounts and passwords.
Putting it all together.
To get started with bitcoin, you generate your own private key and public key. Your private key is just a very large random number, and your public key is calculated from it. These keys can be easily generated on your computer, or even on something as simple as a calculator. Most people use a bitcoin wallet to help generate and manage their keys.
To receive bitcoins, you would need to give your public key to someone who wants to send you some. This person would create a transaction where they unlock bitcoins that they own, and create a new “safe deposit box” of bitcoins and put your public key inside the lock.
This transaction is then sent to any node on the bitcoin network, where it gets relayed from computer to computer until every node on the network has a copy of the transaction. From here, each node has the opportunity to try and mine the latest transactions they have received on to the blockchain.
This process of mining involves a node collecting transactions from its memory pool in to a block, and repeatedly putting that block data through a hash function (with a minor adjustment each time) to try and get a block hash below the target value.
The first miner to find a block hash below the target will add the block to their blockchain, and broadcast this block to the other nodes on the network. Each node will also add this block to their blockchain (removing any conflicting transactions from their memory pool), and restart the mining process to try and build on top of this new block in the chain.
Lastly, the miner who mined this block will have placed their own special transaction inside the block, which allows them to collect a set amount of bitcoins that did not already exist. This block reward acts as an incentive for nodes to continue to build the blockchain, whilst simultaneously distributing new coins across the bitcoin network.
Bitcoin is a computer program that shares a secure file with other computers around the world. This secure file is made up of transactions, and these transactions use cryptography to allow people to send and receive digital safe deposit boxes. As a result, this creates an electronic payment system that can be used by anyone, and runs without a central point of control.
The Bitcoin network has been running uninterrupted since its release in January 2009. In 2019, the Bitcoin network processed over 112 million transactions, moving a total of $15,577,763,114,629.34 (15.58 trillion)2.
The Bitcoin program itself is also under active development, with over 600 individuals contributing to the code since it’s release3. This is due to the fact that the software is “open source”, which means that anyone can view the code and contribute to improving it.
https://github.com/bitcoin/bitcoin/ (source code)
Want to learn more?
Good stuff. You’re in the right place.
This website is full of simple explanations of how bitcoin works.
- Beginners Guide - Sometimes you just need a complete walkthrough of the basics. This is the shortest and simplest guide I could write; I wrote it in 2015 as I was learning how Bitcoin works for the first time.
- Technical Guide - A more complete and in-depth guide to how Bitcoin works. Good for programmers.
- Blockchain Explorer - You can get a feel for how bitcoin works by just browsing the data and seeing how it all connects together. It’s like opening the bonnet of a car and looking inside.
- Videos (YouTube) - These are deep explanations of the mechanics of bitcoin from the perspective of a programmer. These video lessons will get you going if you want to code stuff with bitcoin.
- Code (GitHub) - Example code snippets for common bitcoin stuff.
Why should I trust you?
Also, I am cool.
Why is all this information free?
- Bitcoin is an open-source program that you can run for free.
- I’ve learnt everything I know about Bitcoin, programming, and writing for free.
- This website is built entirely with open-source tools that are free.
So why not free education?
Nonetheless, donations are much appreciated:
Why did you make this website?
Because I want other people to understand how bitcoin works too.
Bitcoin allows you to transfer value to anyone else in the world, and I think this is important. If you understand how bitcoin works, you can create your own cool software that makes a difference.
536,916,338 bitcoins were moved in 2020. The exchange rate on 31 December 2020 was $29,013.39/BTC.↩︎