How do Bitcoin transactions work?

A Bitcoin transaction is a transfer of a certain amount of bitcoins from one address to another address that is recorded on the blockchain.

But how does this “transfer” process actually work?

In this lesson, I’m going to show you how a Bitcoin transaction works from start to finish.

First, we’ll look at how a Bitcoin transaction works from a user’s perspective. And afterward, we’ll look at how a Bitcoin transaction works from a bird’s eye view.

This will help you remember all the new concepts you’ve learned in the previous lessons.

Are you ready?!

Start Bitcoin Transaction

Let’s say that Ironman has 1 bitcoin that she wants to send to Batman.

Ironman sends 1 BTC to Batman

From Ironman’s Perspective

The first thing that Ironman would do is open his Bitcoin wallet.

This could be any type of wallet but in this example, he’s using a software wallet that he’s installed on his laptop.

Ironman initiates Bitcoin transaction

The next thing he does is ask Batman for his Bitcoin address.

This is where Batman wants to receive his bitcoin. Batman emails him a Bitcoin address and Ironman copies and pastes it.

Ironman asks for Batman's address

Ironman then enters the amount of bitcoins he wants to send Batman.

Batman enters 1 BTC

Since his huge gold-titanium alloy fingers are prone to typos, he double-checks he’s entered the correct number.

And hits Send.

Batman sends 1 BTC

The wallet software then asks for the password to confirm the transaction.

To send bitcoin, Ironman needs to prove to the Bitcoin network that it’s actually him sending the money and that he has ownership of the bitcoin.

That’s where his private key comes in (which is stored in the wallet).

After Ironman enters the correct password, the wallet software “signs” the transaction using Batman’s private key, creating a separate piece of data known as a “digital signature“. (This is all done behind the scenes.)

Bitcoin wallet signs transaction

Bitcoin Transaction Behind the Scenes

From here on out, Batman’s involvement is done.

The wallet software connects to a Bitcoin node and sends the transaction message, along with the “digital signature” and public key.

The node checks to see if the transaction is valid:

  • Does the sender have enough BTC tied to their address to do the transaction?
  • Is the sender authorized to send the BTC?

For example, it checks to make sure that Batman actually has 1 BTC to send. If the transaction passes all checks, the node passes the transaction on to other nodes.

By default, nodes don’t trust each other, so they will validate the transaction again for themselves.

And only if it deems the transaction valid, will they share the transaction to nodes that they’re connected to.

Bitcoin transaction sent to nodes

If a transaction is deemed valid, it is then stored in a temporary storage area known as the “memory pool” or “mempool“.

At this point, a transaction is considered “unconfirmed” or “pending“.

Bitconi transaction stored in mempool

Special nodes known as “miners” will package this transaction along with other valid transactions from their mempool into a “block“.

Bitcoin miners bundle transactions into a block

Miners will then compete to be the first to “mine” their block. This involves trying to find a number that begins with a specific number of zeros.

The only way to find this number is by trial and error. In other words, making as many guesses as possible.

Bitcoin miners compete

The first miner to guess a correct number means it’s the first to “mine” its block.

The moment the miner guesses correctly, it shares its block along with the “winning number” to other nodes in the Bitcoin network.

First Bitcoin miner to guess correct nonce wins

Nodes on the Bitcoin network verify that the miner has guessed the correct number and if it is correct, it adds the winning miner’s block to their copy of the blockchain. And they also send this block to other nodes.

Since the block (that holds the transaction) has now been added to the “official” version of the blockchain, the transaction is now considered “confirmed

Once that block is created and the new transaction is verified and included in that block, the transaction is said to have “one confirmation“.

Bitcoin nodes validate new block

From Batman’s Perspective

Batman sees that the transaction has been confirmed and checks his Bitcoin wallet to see if the bitcoin has been transferred.

Bitcoin transaction confirmed

The more blocks that have been built on top of the block with Ironman’s transaction, the more “confirmed” the transaction is on the blockchain.

Basically, each block added is considered an “additional confirmation“. Waiting for six confirmations is the current standard for most transactions to be considered secure.

And three you have it!

One bitcoin has now been transferred from an address owned by Ironman to a new address that’s owned by Batman.

And unless Ironman or Batman shares their Bitcoin wallet address publicly, nobody will know two famous superheroes were involved in a Bitcoin transaction.

All anybody would see is 1 BTC being sent from one address to another, but they wouldn’t know who is behind the addresses.

As you can see, a lot of the steps in a Bitcoin transaction were done behind the scenes.

Once Batman shared his address with Ironman, and Ironman initiated the transaction using his Bitcoin wallet, the rest was handled by computers and software code.

Bird’s Eye View of a Bitcoin Transaction

Now let’s take a bird’s eye view of how a Bitcoin transaction works.

Let’s assume that Ironman has already entered Batman’s address and the amount of bitcoin to send.

Bitcoin has been sent

Ironman’s wallet connects to a node that broadcasts a message to all the computers (“the Bitcoin network”) that run a copy of the up-to-date database (“Bitcoin’s blockchain”) that says, effectively, “I want to send 1 bitcoin to Batman.”

Ironman has a unique string of letters and numbers called a “private key”. With this private key, Batman’s wallet software generates a “digital signature” that ensures that the message is coming from him and not from anyone else.

Computers (“full nodes”) in the Bitcoin network can easily confirm if Ironman is the one who actually sent the message by using a different string of letters and number that Ironman provides, called a “public key” to verify this “digital signature”.

They can also easily confirm that Ironman has 1 bitcoin to send because they all have a copy of the current database.

All of the nodes are constantly updating each other with the latest information (“transactions”) that is added to the Bitcoin network.

A transaction exists as a record of the transfer of bitcoin from one address to another. Transactions are not individually recorded on the blockchain, but are first grouped into blocks.

Importantly, at this point, the transaction has only been proposed. No computer has updated its copy of the ledger (“blockchain”) yet.

Transactions are initially placed into what amounts to a waiting room (“mempool”), where they sit waiting for confirmation.

The mempool (memory pool) is a smaller database of unconfirmed (pending) transactions which every node keeps. All transactions in the mempool are pending, and should not be trusted until they are included in a block.

Because the transaction is only being proposed and not settled, the system can rapidly relay the message to ensure every participant is aware of it.

In the diagram below, Ironman and Batman are represented as purple wallets.

The gray circles represent the computers (“full nodes”) that are part of the peer-to-peer (P2P) Bitcoin network.

The black squares represent the “blockchain”, sequentially updated copies of the ledger, at the time Ironman proposes his transaction to the network.

As you can see, identical copies of the blockchain are stored on computers around the world (“full nodes”) that run the Bitcoin software. This design ensures that no single entity is in control of the ledger and makes Bitcoin resistant to being controlled (or shut down) by any government or central authority.

All nodes that maintain a complete copy of the blockchain known as “full nodes” would need to be destroyed in order to erase the ledger. As long as the entire ledger exists on at least one full node, there will be a record of all Bitcoin transactions throughout history.

Ironman and Batman as purple wallets

Of course, Ironman is not the only one creating a transaction. There are other members of the Avengers sending their bitcoins to other recipients. For example, Captain America could be sending some bitcoins to the Winter Soldier.

This is where a special participant in the network enters: “miners.”

Miners are computers that are scattered around the world and form a critical part of the Bitcoin network. Their job is to bundle or group together new valid transactions, such as Ironman’s, and propose them for settlement.

These groups of transactions are called “blocks,” which is where the “block” in “blockchain” comes from.

A block is a collection of transactions. Blocks are linked together chronologically to form a “chain of blocks” or blockchain.

At any given time, thousands of these computers are competing with each other for the right to create the next block. The competition involves solving a”puzzle”, and miners can propose a new block only if they solve the current puzzle.

This “puzzle” basically boils down to trying to guess a correct number. The odds of guessing a correct number is about 1 in 6 trillion.

So the trick to being the first to find a “winning” number is to guess as many numbers as possible. This requires a lot of computing power which uses huge amounts of energy.

Whoever finds the solution first is entitled to a reward, known as the “block reward”.

The block reward was designed to incentivize nodes to participate in mining. Otherwise, there would be no miners since they would not be able to recoup the high cost of the computers and the electricity cost of running them.

The block reward is made of TWO components:

  1. Newly minted bitcoins
  2. Transactions fees (which are paid by the person initiating the transaction like Ironman)

The newly minted bitcoins “won” by the miner are known as the “block subsidy” and represent the biggest part of the reward. Currently, each new block currently comes with a reward of 6.25 newly minted bitcoins.

Each block contains multiple transactions, And all transactions include a fee, which miners collect.

In summary:

Block reward = block subsidy + transaction fees

The block reward is what incentivizes miners to perform the work necessary to verify transactions and maintain the database.

Every 210,000 blocks, or roughly every four years, the block subsidy is cut in half in an event known as the “halving”. This process will continue until the block subsidy is zero. At that point, miners will only collect transaction fees

New blocks are settled on the Bitcoin network roughly every 10 minutes, though the exact time depends on how quickly the “puzzle” is solved.

Today, most mining is done by “mining pools,” groups of miners who combine their processing power and share the block reward among themselves.

This process is shown in the diagram below.

Bitcoin Network with Miners

The miners are now represented as orange circles.

The blue square shows the updated ledger that includes a number of new transactions, including Ironman’s

For now, only one network participant (the miner who proposed the new block of transactions) can see the fully updated ledger.

All other participants still only see the older blocks, which are depicted in black.

Because the reward is significant, many miners compete to settle each block of transactions.

By design, solving the “puzzle” is an expensive endeavor since it takes significant computing power and requires a lot of electricity. And knowing which of the thousands of miners will solve the “puzzle” first is impossible.

Once a miner does solve the “puzzle”(guess a correct number), it can post the solution and propose its block of transactions to the network.

What’s neat about this approach is that although solving the puzzle is difficult and expensive to solve, checking the result is very easy. And when a miner posts a solution and its block of transactions, other members of the network check the work.

If the transactions are valid and the solution to the “puzzle”  is correct, network participants update their copy of the database to reflect the new transactions.

At that point, Ironman’s transaction is considered settled or “confirmed“. The 1 bitcoin has moved from Ironman’s address to Batman’s address and has officially been recorded on the blockchain.

This “consensus mechanism” of determining what transactions get permanently recorded and “confirmed” is the heart of Bitcoin’s blockchain design.

This process is shown below.

Bitcoin Network syncs blockchain

All network participants have now accepted the new block of transactions proposed (blue square). As a result, their ledgers are updated and synchronized.

Importantly, the competition to settle the next block of transactions depends on including the information from the previous block, which causes the miners to rapidly update their copy of the database and ensures that tampering with a settled block is very difficult.

This “chaining together of blocks” is why this database architecture is called a “blockchain.”

The Bitcoin blockchain contains every block since its inception, going all the way back to the first block known as the “Genesis Block.”

What if the unknown Bitcoin miner submitting a block is a bad actor and proposes an invalid block of transactions that somehow benefits it?

Or what if Ironman is malicious, and he’s trying to send the same 1 bitcoin to both Spider-Man and Wonder Woman at the same time without anyone noticing?

Network participants examine each transaction in each proposed block and reject blocks with invalid transactions. Today, more than 100,000 nodes are independently verifying every single Bitcoin transaction!

Because the work of validating transactions and ensuring that only valid transactions are settled is trivially easy for network participants but attempting to settle transactions is costly, the incentive to even try to defraud the system is minimal.

Summary

Let’s summarize all the interactions on the Bitcoin network:

  • If you want to send bitcoins to another person, you provide the recipient’s Bitcoin address, and your wallet will connect to a node to initiate a transaction.
  • The node will verify the transaction, validate it and then broadcast and relay the valid transaction to other nodes and miners. If a transaction violates one of Bitcoin’s rules, nodes will automatically reject it.
  • Miners batch these transactions into a “candidate block” (temporary block) and compete to be the one who gets to publish their block on the blockchain by being the first to guess correctly a solution to a math “puzzle”.
  • The “winning” miner gets to publish this temporary block as a permanent block to the blockchain, confirming the transaction (and other transactions in the batch).
  • Nodes receive this block and verify that the miner is following the rules of the network. (If the block violates one of Bitcoin’s rules, nodes will automatically reject it.)
  • Whenever a node receives a new block and deems it valid, it relays it to other nodes, so that all nodes (including miners) can remain in sync and maintain identical blockchains.
  • All other miners delete the temporary block they were working on and start on a new “candidate block” with a new math “puzzle”.
  • Once the node that the recipient’s wallet connects to has received the new block, the recipient’s wallet will show an updated balance with the newly received bitcoins.