What is Double Spending?

Last updated: 8/24/19

One of the main issues any digital currency faces is double spending. This post explains exactly what the double spend problem is, and how to prevent it.

What is Double Spending Summary

Double spending is the act of trying to spend the same digital currency twice by creating duplicate transactions. This issue is one of the main obstacles a digital currency needs to solve in order to make sure it is not being abused, and that it maintains its value and trust.

Bitcoin solves the double spend problem through the use of a public ledger that is constantly monitored by network participants, and through the Proof of Work consensus mechanism.

That’s double spending in a nutshell. For a more detailed explanation keep on reading, here’s what I’ll cover:

  1. Double Spending Explained
  2. How to Prevent Double Spending
  3. RBF – “Legit” Double Spending
  4. Conclusion

1. Double Spending Explained

Since Bitcoin transactions are a digital file, it’s actually possible to duplicate transactions and spend the same Bitcoin twice. This issue of “copying and pasting” is a weakness any digital currency faces (even fiat currencies in their digital form).

Here are some examples of how you can double spend a digital currency:

  1. You can “copy” a coin and send it to someone while still retaining the original.
  2. You can simultaneously send the same coin to two different people.
  3. You can reverse a transaction that’s already been made after receiving the goods paid by it, hence keeping the goods and the money.

The double spend problem is a serious issue for any digital currency since it can create an inflated money supply which quickly erodes the value of the currency and the trust in it.


2. How to Prevent Double Spending?

There are two ways to stop double spending – a centralized way and a decentralized way.

The Centralized Solution

The centralized solution to prevent double spending is pretty simple. It usually involves a trusted authority that holds a record of everyone’s balance in the system.

For example, when Alice sends money to Bob, the transaction goes through the central authority (e.g. bank) that checks its ledger to makes sure Alice has the money she wants to spend. If everything is in order, the central authority authorizes the transaction and the money is transferred.

The Decentralized Solution

When you’re dealing with a decentralized currency like Bitcoin, you don’t have a central authority to validate transactions. Therefore, Bitcoin uses a mix of elements to solve the double spend problem.

Preventing Fraudulent Transactions

First of all, the Bitcoin ledger of transactions, known as the Blockchain, is public and visible to all. Every Bitcoin transaction ever made and every balance of every address can be inspected by anyone.

This means that if Alice sends one Bitcoin to Bob, every computer that holds a copy of the blockchain (also known as a full node) will verify the history of Alice’s transactions to make sure she indeed has that one Bitcoin to spend.

If Alice tries to cheat and creates a Bitcoin from thin air, she will quickly be exposed by one of the many nodes validating transactions.

Preventing Simultaneous Transactions

But what if Alice sends the same coin simultaneously to two people?

Assuming 50% of the nodes received transaction A first, and the other 50% received transaction B first. How do we know which transaction is valid, and which to discard? The answer is simple, the transaction that enters the ledger first will be the valid one.

That’s why it’s always recommended to wait for at least 1 confirmation before considering a Bitcoin transaction as complete.

In order to decide the order of transactions, Bitcoin uses a consensus mechanism called Proof of Work (POW). This mechanism describes the rules of who gets to update the ledger of Bitcoin transactions.

This is important since when there’s no central authority, you need to have a consensus about who gets to make changes in the transaction ledger. The whole process of updating the ledger of transactions is known as Bitcoin mining.

However, what happens if the mining process somehow happened simultaneously for both transaction A and transaction B?

Let’s assume that two unrelated miners managed to update the ledger at exactly the same time, each one with a different transaction that uses the same source of funds.

In this case, we will have 2 branches of the blockchain (also known as a fork) and the next block of transactions to be mined will determine which previous block was valid.

If the next block, in some magical way, is also mined simultaneously, we will have to wait until the next block, and so on.

If you want to be completely sure your Bitcoin transaction won’t be reversed in such a rare case of coincidences, you should wait until 6 confirmation arrives for your transaction.

It’s highly unlikely (like super highly unlikely) that this fork will happen more than 6 times. So, in the end, we will have a clear winner and only one transaction will be confirmed.

Preventing transaction reversal

There’s a special kind of double spend attack that is called a 51% attack. This happens when a single entity gains over 50% of the network’s mining power and can effectively control which version of the ledger is the legitimate one.

In this case, the attacker can spend coins on one version, obtaining good or services for this payment. Later on, the attacker creates a different version of the ledger where the original transaction doesn’t exist and retrieves the payment to his possession.

The only way to prevent a 51% attack is to make sure the network is decentralized enough and has enough computational power to make it basically impossible to amass more than 50% of its hashrate.

In Bitcoin’s case, a 51% is highly unlikely, but with smaller coins, this type of attack has happened.


3. RBF – “Legit” Double Spending

One form of “legit” double spending is Replace By Fee or RBF for short.

RBF is a function embedded in certain Bitcoin wallets (e.g. Electrum) that allows you to rebroadcast a transaction that is still unconfirmed, in order to get it confirmed faster.

In some cases, Bitcoin transactions are sent with a network fee that is too small to incentivize miners to pick them up. This can get your transaction stuck inside the mempool, waiting to be confirmed for a very long time.

RBF allows you to rebroadcast the transaction with a higher fee, effectively trying to double spend your money, so the miners will pick up the new transaction and the old one will get canceled.


4. Conclusion

Double spending is a major issue that needs to be addressed when dealing with digital currencies. Fortunately, it seems that Satoshi Nakamoto, the inventor of Bitcoin, managed to build a mechanism to prevent it from happening even in a decentralized network.

You may still have some comments or questions. If so, make sure to leave them in the comment section below.

Bitcoin Video Crash Course 

Dummy-proof explainer videos enjoyed by over 100,000 students. One email a day for 7 days, short and educational, guaranteed.

We hate spam as much as you do. You can unsubscribe with one click.

13
Leave a Reply

avatar
7 Comment threads
6 Thread replies
1 Followers
 
Most reacted comment
Hottest comment thread
9 Comment authors
KeyyZsofia Elekneeraj guptaZsofia - 99Bitcoins supportRomil Jain Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Keyy
Guest
Keyy

Thank you for the easy, concise explanation!

neeraj gupta
Guest
neeraj gupta

HI, My transaction is not yet confirmed since 5 days.
Please suggest what can i do to reverse it or cancel it.

https://blockchain.info/tx/ebbff7df40c4db1ff5ee5cb0d335c57ce109b33915a2d914d8578d31cd84a166

Romil Jain
Guest
Romil Jain

I got an idea of double spending in Bitcoin-Blockchain but i have a scenario Scenario – Let say Alice has only 10 BTC to spend and buys a merchandise of 10 BTC from Bob and initiate the payment in Bitcoin. Merchandise doesn’t wait for the payment to confirm and send the merchandise to Alice. But At the same time Alice initiate the same 10 BTC payment to her own account (having different BTC address) and tricked the network. This is the same case as of double spending. I know only one transaction would be confirmed by the network but if… Read more »

OkwaIfugo
Guest
OkwaIfugo

Hello, tnx i have a problem. someone sent me $2679 and it did not confirm then i sent it out $2794 to my client lbc wallet. i had $110 sent to me which did not confirm. then later i sent out $135 to a bitpie wallet. after some hrs someone sent me $6 it confirmed well. then also someone sent me $1000 which confirmed as well. but the issue here is this, the $2679 after two days of no confirmation vanished from my wallet history, the $2794 i sent to my client lb wallet also vanished. then the $135 i… Read more »

Fabiano
Guest
Fabiano

Hi, I had an issue two days ago sending BTC from green address wallet to another wallet. The transacition was doubled in the receiving wallet, one was confirmed and the another is pending. I’m just starting with cryptocoins and after readind this article I understand that it was my fault for not waiting fot all confirmation. And what can I do about that pending transaction in the another wallet, will it be eventually cancelled and how long does it takes? Thanks you very much for your help.

Saagt
Guest
Saagt

Hello for my first payment (usin Electrum wallet) I set a very low fee because I didn’t know better (like 1 satoshi/B), after a few hours of waiting and reading I eventually modified it on Electrum (upped it to 40 sat/B) and after doing that it tells me on Blockexplorer that I made it a double spending. Did I do something wrong while modifying the fee? Or is that normal process with Electrum? Thank you

Rodolfo
Guest
Rodolfo

Hi, this is a nice explanation about double spending. You can try a simulator of double spending problem here:

Maybe is a little more technical visualization for a beginner, but it let you play with the simulation to try different approach of the problem.