How Bitcoin Works – from Mining to Hashing and Security

how does bitcoin work

If you haven’t read our primer on Bitcoin and why it matters to you, read that first:

saving-bitcoin

Why Bitcoin Matters To Us All

Sidd15 min read
Why does Bitcoin matter? As the most robust supply-constrained digital currency, Bitcoin brings saving money back in style. With that, it brings civilization back to sanity.

The capital ‘B’ Bitcoin refers to a network of computers that maintain a ledger of account balances of the digital currency bitcoin, much like a bank maintains a ledger of account balances of dollars or euros or another currency. The Bitcoin software, or protocol, also allows users to send bitcoins from their account to another account over the internet, similar to PayPal or Venmo but without a company providing the transmission service. The Bitcoin software is open source, so anyone can run it on their own computer and join the network. 

The best way to understand Bitcoin’s inner workings is to imagine it like a financial system. Our current financial system, which uses mainly dollars, euros, yen and other currencies as ‘money,’ looks something like this: 

The central bank and government produce and distribute money by lending to people and spending on weapons, roads, and social programs. This system is called debt-based because every time a bank makes a loan they create new currency that never existed before. This currency has value because the debt that created it has value: the borrower promises to repay their debt to the bank, plus interest.

Whenever a bank extends a loan, they create new currency. This applies when you take out a mortgage or a car loan. It also applies when the Federal Reserve buys Treasury bonds from the United States government. In each of these cases, the bank sends newly created currency to a borrower. The borrower makes a promise to the bank to repay that currency, plus interest, in the future. However, new currency entering the system means the value of all existing currency in circulation drops. This happens through a process commonly called inflation

In order to benefit from convenient services banks offer, like credit cards and digital money transfers, normal people and businesses usually keep their money in bank accounts. Each bank has its own ledger with the accounts of all its customers. 

Banks are necessary to enable the digital payments we make every day because we need trusted parties verifying that all the accounting adds up. Otherwise, it would be easy for someone to “copy-paste” a piece of digital money and spend it twice, or add a couple of zeros to their account balance. 

Now we understand a few key points about the current debt-based system: banks produce new currency every time they lend money, and most people keep their money stored at banks that offer them convenience.

Bitcoin is a bit different. Let’s start diving in with a question.

What if everyone held a ledger of account balances, just like a bank?

Instead of banks each holding a ledger of the deposits of their customers, what if everyone held the same ledger, detailing all the account balances of everyone in the economy? Don’t worry about privacy for a moment – we will explain that later.

Let’s look at how a transaction could be made using this banking system. Let’s say Alice wants to pay Drew 10 digital “coins.” She writes the transaction in an email, signs it digitally so everyone can be sure the email is coming from the real Alice, and sends it to everyone else. When the others receive it, they update their ledgers to subtract 10 coins from Alice’s account and add 10 coins to Drews.

Why would anyone bother to record a transaction on their ledger?

Let’s say the first person to complete the following steps will get 5 coins:

  1. Check that the real Alice signed the transaction
  2. Check that Alice has enough balance in her account to pay Drew the 10 coins
  3. Record the transaction if it passes #1 and #2

You’ll notice that this is a lot different than the current monetary system. In the new system, you must have coins in order to give them to someone else. There are no banks with special privileges that can create currency by making a loan.

Instead of only allowing a small group of bankers to make new currency, the new system allows anyone to create new currency if they provide a useful service to the network: verifying and recording transactions between people. We will refer to this as the validation reward.

How does everyone agree on the rules of the system? They are encoded in an open-source software protocol. This means anyone can download the rules of the system for free from the internet and begin using them to earn currency in the system. If everyone uses the same set of rules, their ledgers will end up in sync, because they will accept and reject the exact same transactions.

  • Open source = anyone can download the code and read it for themselves
  • Software protocol = a set of rules written in code

How do we stop people from gaming the system to earn the “validation reward”?

Say Bob and Charlie want to get rich – they could pay each other 1 coin back and forth, making sure that one of them records the transaction first so they can claim the validation reward. With this scheme, they could essentially print new currency in to existence any time they want!

The software protocol stops this by requiring that the person validating the transaction does some “work” with a computer in order to record it. This ensures that computers must spend energy to record transactions, so cheating the system would be very expensive. Bob and Charlie’s scheme to cheat the system no longer makes financial sense.

To demonstrate this process, let’s take a look at Charlie and his computer C-Bot. Charlie has installed the Bitcoin protocol on his computer, which is Bitcoin’s open-source software protocol containing the rules of the Bitcoin system. 

How C-Bot Verifies Transactions

Step 1: Listen for Transactions

First, C-Bot listens for transactions (“txn” for short) that Alice, Bob, Charlie and Drew broadcast through the internet. 

Step 2: Create a “Hash”

Second, C-Bot will collect the following pieces of data:

  • All the Bitcoin transactions people are sending
  • A mystery number (we will explain in a later step)
  • A nonce – just a random number

C-Bot puts all of these in a hash machine. The hash machine takes all this data and produces 256 bits (bits are 1s and 0s) that uniquely fit that data, called a ‘hash.’ This hash is like a fingerprint of the data. You will always get the same hash with the same input data. The hash machine is also one-way: it is easy to create a hash from some data, but you cannot put the hash into the machine and receive the input data back. 

The hashing machine!

C-Bot will try its hash machine with a different nonce (random number) over and over again. Each time, it will check to see if the machine produced a hash that the Bitcoin software protocol says is correct.

This process of finding a hash consumes a lot of time and energy. The hash machine is one-way, so C-Bot cannot just put a ‘correct’ hash into the machine and discover the input data. Every computer on the Bitcoin network is also going through this process to try to find a ‘correct’ hash.

If these computers were able to find the ‘correct’ hash without using very much energy, they could cheat the system. Two computers could pass transactions back and forth, earning bitcoin every time they validated transactions.

Step 3: Finding a Correct Hash

C-Bot finally finds a hash that satisfies the rules of the Bitcoin protocol using all the recent transactions. Now, it sends this block of data to other computers. The block consists of the recent transactions, nonce, and mystery number. Those other computers put all this data through the same hash machine for themselves to verify that C-Bot’s hash is correct. Since we know computers cannot cheat at this game, we know C-Bot had to do some computations with its hashing machine to find a correct hash.

The hash of the block C-Bot sent around now becomes the mystery number that goes into computing the next block. Since the hash of each block in the Bitcoin ‘blockchain’ uses the hash of the last block as an input, it would take an absurd amount of energy to rewrite the history of transactions (aka ‘the blockchain’)

Since everyone’s bitcoin balances are based on transactions in and out of their account, this also makes it impossible to alter anyone’s bitcoin balances.

This whole process is known as bitcoin mining. Each computer on the network tries new data through the hash machine billions of times per second

What is the blockchain?

The blockchain is just a history of Bitcoin transactions, which allows anyone to determine their Bitcoin balance.

  • ‘Block’ = A group of Bitcoin transactions, a nonce, and the hash of the previous block
  • ‘Chain’ = Every block’s hash also uses the previous block’s hash as an input. This connects the data of each block to every other block, forming a chain.

On the blockchain, real names are not associated with bitcoins. Bitcoins are only associated to a random string of numbers and letters known as a ‘public key’. This keeps Bitcoin users and their balances fairly anonymous to everyone who maintains the ledger.

When you hold bitcoins, you have a password to unlock your bitcoin bank accounts. These accounts exist on thousands of computers around the world that run the Bitcoin protocol. 

How can I learn more about Bitcoin? 

This article gave you an understanding for how the Bitcoin protocol operates and ensures its incredible properties.

If you want to learn more, I recommend these resources:

If you’re ready to start playing with Bitcoin yourself, check out our guides to buying Bitcoin and storing it securely.

If you like my work, please share it with your friends and family. My goal is to provide everyone a window into economics and how it affects their lives.

Subscribe to email updates when new posts are published.

All content on WhatIsMoney.info is published in accordance with our Editorial Policy.

Sidd

An independent researcher interested in how economics, finance, and markets affect normal people. I write about economics and money so that anyone can come to understand how monetary policy affects our daily lives. If you can't understand my writing over a beer on a Friday night, I haven't done my job. Studied the history and sociology of technology at the University of Pennsylvania. Spent 10 years working in technology and 5 years in finance.

Recent Posts