<p>In order to prevent double spending, signed transactions need to be time-stamped in a well defined order (so that clients can determine the validity of each transaction; i.e. is the source of funds sufficient to support the transaction).</p>

<p>Rather than have a single centralized trusted authority, Bitcoin distributes this function across the network.  But how to decide who to trust to do this?  The answer is to give the authority to whomever demonstrates the most computing power.</p>

<p>Since a demonstration of computing power cannot be reliably faked, (unlike other measures of individual identity), people can pool their resources to earn the right to timestamp transactions.  As long as more computing power is in the hands of non-malicious users, than malicious ones, no malicious user (or collection of users) will be able to subvert the timestamping function.</p>

CC BY-SA 3.0
2013-04-28T22:47:55.677Z
2013-04-28T22:47:55.677Z
mckoss
<p>The short answer is this: Lacking any central authority, the simple scheme you mentioned wouldn't work for Bitcoin.</p>

<p>Consider if you transferred the same 10 bitcoins to two different accounts with two different transactions. What would stop some people from recognizing the first transaction and some from recognizing the second?</p>

<p>Bitcoin uses proof of work (mining) to solve this "double spend problem".</p>

CC BY-SA 3.0
2013-04-28T22:40:44.047Z
2013-04-28T22:40:44.047Z
David Schwartz
<p>Where would the DB be?</p>

<p>If the DB is stored in some centralized location, then Bitcoin is no longer decentralised.</p>

<p>Basically, the DB <em>must</em> be stored by a distributed network of honest nodes, and shared in the P2P network. However, we need a way for single nodes to be able to verify if a block isn't forged. Enter the nonce/hash: It is something hard to generate (forge), but easy to verify. One needs to pick the correct nonce for the block hash to follow the criteria, and it takes time to find a working nonce. (On the other hand, verifying a hash is a quick job)</p>

<p>Now, of course, we need a way to "legitimately" generate the nonce -- there's no central authority handing out nonces. Enter miners: As long as the almost all of the mining population is working towards generating nonces for "good" blocks (blocks containing all broadcasted transactions with not tampering), we can guarantee that all the generated blocks have come from these miners, and thus these blocks are "legitimate".</p>

<p>While the transactions do get broadcast, there's no way of knowing if a transaction has reached the rest of the world. I can direct a transaction at you and make it <em>look</em> like I've given you money, when I haven't. However, baking a transaction into a block is something nearly impossible for any individual to do as he has to race against the majority of miners.</p>

<p>See also: <a href="http://codinginmysleep.com/bitcoin-mining-in-plain-english/" rel="nofollow">http://codinginmysleep.com/bitcoin-mining-in-plain-english/</a></p>

CC BY-SA 3.0
2013-04-28T18:52:53.900Z
The nonce is actually just a counter. What's hard to generate is the hash over the block contents, the previous block hash and the nonce.
Michael Borgwardt
CC BY-SA 3.0
2013-04-28T19:08:10.027Z
@MichaelBorgwardt: updated. Both really mean the same "generating the nonce" and "generating the hash" in this context, though.
Manishearth
CC BY-SA 3.0
2013-04-28T17:02:52.067Z
2013-04-28T19:07:16.647Z
2013-04-28T19:07:16.647Z
Manishearth
<p>You should start here: <a href="http://www.youtube.com/watch?v=GmOzih6I1zs" rel="nofollow noreferrer">http://www.youtube.com/watch?v=GmOzih6I1zs</a></p>

<p>As the video mentions, mining is needed to ensure fairness and for keeping th network stable, safe and secure.</p>

<p>Now, let's see what that means. But first a very brief explanation of the principle of mining.</p>

<h2>Mining</h2>

<p>The Bitcoin network consists of nodes that all store a database with all transactions, called the block chain. This database consists of a long chain of blocks, each holding one or more transactions. What miners basically do is bundling all unconfirmed transaction into a block. The form of the block must satisfy certain conditions before the block is considered valid. This condition is called <a href="https://en.bitcoin.it/wiki/Proof_of_work" rel="nofollow noreferrer">proof of work</a> and is not trivial to understand. When a miner finds a block that is valid, it can send its block to the network and others will verify it. When it is indeed valid, all clients will add it to their block chain. Every time a miner finds a valid block, it has the right to assign a certain amount of bitcoins to himself, called the <a href="https://en.bitcoin.it/wiki/Mining#Reward" rel="nofollow noreferrer">block reward</a>. They also get all transaction fees of all transactions included in his block. This way, new bitcoins are added to the network and it can be ensured that transactions can be confirmed.</p>

<h2>Fairness</h2>

<p>Since Bitcoin is peer-to-peer and there is no central authority to control it, every one can send any kind of transaction to the network, whether or not it is valid. You could simply send a transaction that sends someone else's coins to yourself.</p>

<p>Luckily no one in the network will accept your transaction. When you want to spend bitcoins from a certain address, you will need to sign the transaction with the private key of that address. Other clients in the network can verify that you own that private key because they have the public key. This method is based on <a href="http://en.wikipedia.org/wiki/Public-key_cryptography" rel="nofollow noreferrer">public-key cryptography</a>.</p>

<p>So when miners try to bundle unconfirmed transactions into a block, they first need to confirm every transaction to make sure that all transactions in its block are valid. When they are not, other clients will not accept the block they mined when they send it to the network.</p>

<p>This way, miners ensure that people can only spend bitcoins they own.</p>

<h2>Stability</h2>

<p>This is the least difficult one to understand. The Bitcoin protocol sets the <a href="https://en.bitcoin.it/wiki/Difficulty" rel="nofollow noreferrer">difficulty</a> of the mining problem so that averagely every 10 minutes a new block can be found by some miner. This way, a transaction takes 10 minutes to be confirmed on average.</p>

<p>However, after a transaction has been included in a block, it still is not irreversible. This is not easy to understand, but when a miners try to mine a new block, they include in that block the number and the ID of the previous one. So let's say someone mined block 100, which follows number 99. It can happen that someone else didn't notice that someone found a valid block to follow on 99 and makes a valid number 100 itself as well, let's call it 100'. In this case, most clients will only accept the first block they received. But it can happen that another miner received 100' first and will find a block following on 100' and not on 100. Then we have following situation:</p>

<pre><code>98 - 99 - 100
      \ _ 100' - 101'
</code></pre>

<p>When clients notice such a situation, they will always choose the longest existing chain (that only consists of block they think are valid). This means that block 100 will be discarded and that 100' and 101' or now the two last block of the main chain. This means that a transaction that was confirmed by block 100 is now possibly no longer confirmed. Luckily, the miners who found block 100' or 101' probably also knew of the transaction and most probably they also included it in one of those blocks. But it can happen that they did not and so a transaction can be undone.</p>

<p>For this reason, most clients and merchants require a transaction to be <a href="https://en.bitcoin.it/wiki/Confirmation" rel="nofollow noreferrer">confirmed by at least 6 blocks</a>. This means it must be included in a block that has at least 5 blocks after it.</p>

<p>The fact that a transaction will be able to be considered confirmed after averagely 1 hour, makes it a stable situation. It happens rarely that transactions confirmed for more than 1 hour will ever be reversed again.</p>

<h2>Safety and security</h2>

<p>The previous part about stability already included some security aspects of mining. It is clear that miners make the Bitcoin block chain trustworthy. When a transaction is included in a block and 5 or more other blocks have passed, you can be sure it is irreversible and safe to accept it as a payment.</p>

<p>It is also clear that the safety and security of Bitcoin as a payment system is in the hands of the miners and that every time one of them solves a block, he has the power to decide what transactions he accepted to the block chain.</p>

<p>Mostly, all miners are fair and they will include as much valid transactions as possible. Whenever a miner is not fair and it selectively excludes some transactions, some other miner will likely include it in the next block.</p>

<p>There is however one flaw. When a miner has <a href="https://en.bitcoin.it/wiki/Weaknesses#Attacker_has_a_lot_of_computing_power" rel="nofollow noreferrer">more computation power than all other miners combined</a>, it can always create new blocks at a faster rate than the others. This gives him much power over the block chain, and that is to be avoided at all cost. This flaw is named a 51% attack. <a href="https://bitcoin.stackexchange.com/a/662/1307">This answer</a> sums up the consequences of what could happen if someone would have 51% of the network computation power.</p>

<p>But this is a security flaw, what has this to do with why miners should mine? Well, as more people mine, the total computation power rises and it will be much much harder for someone to perform such a 51% attack. Currently, to own hardware capable of performing such an attack would be so enormously expensive that it is economically unfeasible to do, if not completely impossible. So, every miner who contributes his power to the network ensures that only fair miners will find blocks and that the network will be safe for people to trust upon.</p>

CC BY-SA 3.0
2013-04-28T20:57:46.973Z
Thanks @Steven Roose (+1) - awesome answer. So, to sum, mining is the act of actually reconciling/verifying transactions across the distributed network (instead of a central server doing the reconciliation). And, as a reward for providing the reconciliation, miners get awarded in newly-created bitcoins. Is that a fair assessment? Thanks again!
TicketMonster
CC BY-SA 3.0
2013-04-29T00:54:27.643Z
Yes, that sums it up. A question that some people have is whether the transaction fees per block are going to be enough to stimulate miners when the block reward is gone. The block reward halves every 4 years and in December 2012 it changed from 50 to 25 BTC. Some day it will be zero and from then on miners have to make their money of transaction fees.
Steven Roose
CC BY-SA 3.0
2015-12-02T22:04:19.210Z
@StevenRoose So miners do the actual signature checking as well? Not "the network", but the miners specifically? So that mining is basically this: "Check signatures in transactions. When done, concatenate a bunch of stuff and append i; increment i until hash(bunchOfStuff+i) < chosenDifficulty"?
Erik Vesterlund
CC BY-SA 3.0
2015-12-07T14:56:48.927Z
@ErikVesterlund Something like that, indeed. But keep in mind that non-mining nodes also do signature verification. When a miner broadcasts a block with invalid signatures, a non-mining node will reject the block and block the miner and just stick to the chain it knows of that does only include valid blocks.
Steven Roose
CC BY-SA 3.0
2017-12-08T06:33:13.593Z
If the difficulty level was to remain at 1 like it was when the blockchain started, with today's miners insane hashrates they could rewrite the entire blockchain from scratch within less than a second.   Let's say some miner recreates the entire blockchain AND has access to alot of full nodes so he can just copy this "new blockchain" over it.   Is there any protection against this kind of an attack?   Because if not, then that means mining is completely pointless in defending the system.
Miki Berkovich
CC BY-SA 3.0
2018-01-14T18:11:50.610Z
So what will happen when all coins are mined, will it all go down? Also how do non-minable coins maintain this fairness?
LifeH2O
CC BY-SA 3.0
2018-01-15T11:37:01.547Z
@LifeH2O When all coins are mined, blocks will reward the transaction fees to the miner. So miners will (and already do) prefer transactions with higher fees. That's why it's important to pay transaction fees for your transcations: the fee system replaces the bounty system to keep miners honest.
Steven Roose
CC BY-SA 3.0
2013-04-28T20:20:14.627Z
2015-11-04T03:06:42.250Z
2017-04-13T12:47:36.707Z
Steven Roose
<p>I understand that a <em>transaction</em> is a record of 1+ Bitcoins being given from one party to another.</p>

<p>I understand that a <em>block</em> is a collection of unverified (pending) transactions that gets verified every ~10 mins or so.</p>

<p>I understand that <em>mining</em> is the act of running specialized software that will solve some cryptographic problem, and as a result, allows a block of pending transactions to be added to the <em>block chain</em> (history of all transactions, ever).</p>

<p>So first off, if anything I have said so far is not true or misleading, please begin by correcting me!</p>

<p>Assuming I'm more or less correct, I'm still not seeing why mining is crucial to the system, and am (obviously) not seeing the forest through the trees here.</p>

<p>If I send 10 BTC to someone, why does someone else (a "miner") need to verify this? Shouldn't this transaction be stored in a DB somewhere, and verifiable by querying that DB?</p>

CC BY-SA 3.0
2013-04-28T20:22:27.417Z
I don't think it is a duplicate of that question, @StephenGornick. This is more than solely about what the mining problem is about but also about how miners contribute to the security and fairness of the network.
Steven Roose
<mining-theory><transaction-verification>
Why is mining necessary for the Bitcoin network/system?
TicketMonster
# Why is mining necessary for the Bitcoin network/system?

(Asked by: username_0 on 2013-04-28)

I understand that a *transaction* is a record of 1+ Bitcoins being given from one party to another.

I understand that a *block* is a collection of unverified (pending) transactions that gets verified every ~10 mins or so.

I understand that *mining* is the act of running specialized software that will solve some cryptographic problem, and as a result, allows a block of pending transactions to be added to the *block chain* (history of all transactions, ever).

So first off, if anything I have said so far is not true or misleading, please begin by correcting me!

Assuming I'm more or less correct, I'm still not seeing why mining is crucial to the system, and am (obviously) not seeing the forest through the trees here.

If I send 10 BTC to someone, why does someone else (a "miner") need to verify this? Shouldn't this transaction be stored in a DB somewhere, and verifiable by querying that DB?

**Tags:** mining-theory, transaction-verification

> **Comments:**
> **username_1**: I don't think it is a duplicate of that question, @StephenGornick. This is more than solely about what the mining problem is about but also about how miners contribute to the security and fairness of the network.  

---

## 4 answers

### Answer by username_1 on 2013-04-28. Score: 7 | Accepted answer

You should start here: <http://www.youtube.com/watch?v=GmOzih6I1zs>

As the video mentions, mining is needed to ensure fairness and for keeping th network stable, safe and secure.

Now, let's see what that means. But first a very brief explanation of the principle of mining.

## Mining

The Bitcoin network consists of nodes that all store a database with all transactions, called the block chain. This database consists of a long chain of blocks, each holding one or more transactions. What miners basically do is bundling all unconfirmed transaction into a block. The form of the block must satisfy certain conditions before the block is considered valid. This condition is called [proof of work](https://en.bitcoin.it/wiki/Proof_of_work) and is not trivial to understand. When a miner finds a block that is valid, it can send its block to the network and others will verify it. When it is indeed valid, all clients will add it to their block chain. Every time a miner finds a valid block, it has the right to assign a certain amount of bitcoins to himself, called the [block reward](https://en.bitcoin.it/wiki/Mining#Reward). They also get all transaction fees of all transactions included in his block. This way, new bitcoins are added to the network and it can be ensured that transactions can be confirmed.

## Fairness

Since Bitcoin is peer-to-peer and there is no central authority to control it, every one can send any kind of transaction to the network, whether or not it is valid. You could simply send a transaction that sends someone else's coins to yourself.

Luckily no one in the network will accept your transaction. When you want to spend bitcoins from a certain address, you will need to sign the transaction with the private key of that address. Other clients in the network can verify that you own that private key because they have the public key. This method is based on [public-key cryptography](http://en.wikipedia.org/wiki/Public-key_cryptography).

So when miners try to bundle unconfirmed transactions into a block, they first need to confirm every transaction to make sure that all transactions in its block are valid. When they are not, other clients will not accept the block they mined when they send it to the network.

This way, miners ensure that people can only spend bitcoins they own.

## Stability

This is the least difficult one to understand. The Bitcoin protocol sets the [difficulty](https://en.bitcoin.it/wiki/Difficulty) of the mining problem so that averagely every 10 minutes a new block can be found by some miner. This way, a transaction takes 10 minutes to be confirmed on average.

However, after a transaction has been included in a block, it still is not irreversible. This is not easy to understand, but when a miners try to mine a new block, they include in that block the number and the ID of the previous one. So let's say someone mined block 100, which follows number 99. It can happen that someone else didn't notice that someone found a valid block to follow on 99 and makes a valid number 100 itself as well, let's call it 100'. In this case, most clients will only accept the first block they received. But it can happen that another miner received 100' first and will find a block following on 100' and not on 100. Then we have following situation:

```
98 - 99 - 100
      \ _ 100' - 101'

```

When clients notice such a situation, they will always choose the longest existing chain (that only consists of block they think are valid). This means that block 100 will be discarded and that 100' and 101' or now the two last block of the main chain. This means that a transaction that was confirmed by block 100 is now possibly no longer confirmed. Luckily, the miners who found block 100' or 101' probably also knew of the transaction and most probably they also included it in one of those blocks. But it can happen that they did not and so a transaction can be undone.

For this reason, most clients and merchants require a transaction to be [confirmed by at least 6 blocks](https://en.bitcoin.it/wiki/Confirmation). This means it must be included in a block that has at least 5 blocks after it.

The fact that a transaction will be able to be considered confirmed after averagely 1 hour, makes it a stable situation. It happens rarely that transactions confirmed for more than 1 hour will ever be reversed again.

## Safety and security

The previous part about stability already included some security aspects of mining. It is clear that miners make the Bitcoin block chain trustworthy. When a transaction is included in a block and 5 or more other blocks have passed, you can be sure it is irreversible and safe to accept it as a payment.

It is also clear that the safety and security of Bitcoin as a payment system is in the hands of the miners and that every time one of them solves a block, he has the power to decide what transactions he accepted to the block chain.

Mostly, all miners are fair and they will include as much valid transactions as possible. Whenever a miner is not fair and it selectively excludes some transactions, some other miner will likely include it in the next block.

There is however one flaw. When a miner has [more computation power than all other miners combined](https://en.bitcoin.it/wiki/Weaknesses#Attacker_has_a_lot_of_computing_power), it can always create new blocks at a faster rate than the others. This gives him much power over the block chain, and that is to be avoided at all cost. This flaw is named a 51% attack. [This answer](https://bitcoin.stackexchange.com/a/662/1307) sums up the consequences of what could happen if someone would have 51% of the network computation power.

But this is a security flaw, what has this to do with why miners should mine? Well, as more people mine, the total computation power rises and it will be much much harder for someone to perform such a 51% attack. Currently, to own hardware capable of performing such an attack would be so enormously expensive that it is economically unfeasible to do, if not completely impossible. So, every miner who contributes his power to the network ensures that only fair miners will find blocks and that the network will be safe for people to trust upon.

> **Comments:**
> **username_0**: Thanks @username_1 (+1) - awesome answer. So, to sum, mining is the act of actually reconciling/verifying transactions across the distributed network (instead of a central server doing the reconciliation). And, as a reward for providing the reconciliation, miners get awarded in newly-created bitcoins. Is that a fair assessment? Thanks again!  
> **username_1**: Yes, that sums it up. A question that some people have is whether the transaction fees per block are going to be enough to stimulate miners when the block reward is gone. The block reward halves every 4 years and in December 2012 it changed from 50 to 25 BTC. Some day it will be zero and from then on miners have to make their money of transaction fees.  
> **username_6**: @username_1 So miners do the actual signature checking as well? Not "the network", but the miners specifically? So that mining is basically this: "Check signatures in transactions. When done, concatenate a bunch of stuff and append i; increment i until hash(bunchOfStuff+i) < chosenDifficulty"?  
> **username_1**: @username_6 Something like that, indeed. But keep in mind that non-mining nodes also do signature verification. When a miner broadcasts a block with invalid signatures, a non-mining node will reject the block and block the miner and just stick to the chain it knows of that does only include valid blocks.  
> **username_7**: If the difficulty level was to remain at 1 like it was when the blockchain started, with today's miners insane hashrates they could rewrite the entire blockchain from scratch within less than a second.   Let's say some miner recreates the entire blockchain AND has access to alot of full nodes so he can just copy this "new blockchain" over it.   Is there any protection against this kind of an attack?   Because if not, then that means mining is completely pointless in defending the system.  
> **username_8**: So what will happen when all coins are mined, will it all go down? Also how do non-minable coins maintain this fairness?  
> **username_1**: @username_8 When all coins are mined, blocks will reward the transaction fees to the miner. So miners will (and already do) prefer transactions with higher fees. That's why it's important to pay transaction fees for your transcations: the fee system replaces the bounty system to keep miners honest.  

---

### Answer by username_2 on 2013-04-28. Score: 2

In order to prevent double spending, signed transactions need to be time-stamped in a well defined order (so that clients can determine the validity of each transaction; i.e. is the source of funds sufficient to support the transaction).

Rather than have a single centralized trusted authority, Bitcoin distributes this function across the network. But how to decide who to trust to do this? The answer is to give the authority to whomever demonstrates the most computing power.

Since a demonstration of computing power cannot be reliably faked, (unlike other measures of individual identity), people can pool their resources to earn the right to timestamp transactions. As long as more computing power is in the hands of non-malicious users, than malicious ones, no malicious user (or collection of users) will be able to subvert the timestamping function.


---

### Answer by username_3 on 2013-04-28. Score: 1

The short answer is this: Lacking any central authority, the simple scheme you mentioned wouldn't work for Bitcoin.

Consider if you transferred the same 10 bitcoins to two different accounts with two different transactions. What would stop some people from recognizing the first transaction and some from recognizing the second?

Bitcoin uses proof of work (mining) to solve this "double spend problem".


---

### Answer by username_4 on 2013-04-28. Score: 1

Where would the DB be?

If the DB is stored in some centralized location, then Bitcoin is no longer decentralised.

Basically, the DB *must* be stored by a distributed network of honest nodes, and shared in the P2P network. However, we need a way for single nodes to be able to verify if a block isn't forged. Enter the nonce/hash: It is something hard to generate (forge), but easy to verify. One needs to pick the correct nonce for the block hash to follow the criteria, and it takes time to find a working nonce. (On the other hand, verifying a hash is a quick job)

Now, of course, we need a way to "legitimately" generate the nonce -- there's no central authority handing out nonces. Enter miners: As long as the almost all of the mining population is working towards generating nonces for "good" blocks (blocks containing all broadcasted transactions with not tampering), we can guarantee that all the generated blocks have come from these miners, and thus these blocks are "legitimate".

While the transactions do get broadcast, there's no way of knowing if a transaction has reached the rest of the world. I can direct a transaction at you and make it *look* like I've given you money, when I haven't. However, baking a transaction into a block is something nearly impossible for any individual to do as he has to race against the majority of miners.

See also: <http://codinginmysleep.com/bitcoin-mining-in-plain-english/>

> **Comments:**
> **username_5**: The nonce is actually just a counter. What's hard to generate is the hash over the block contents, the previous block hash and the nonce.  
> **username_4**: @username_5: updated. Both really mean the same "generating the nonce" and "generating the hash" in this context, though.  

---

