<p>Mining provides a way to reach consensus on what the transaction ledger should look like and know that nobody is cheating.</p>

<p>That's the non-technical definition of mining.</p>

<ul>
<li><a href="https://bitcoin.stackexchange.com/q/148/153">What exactly is Mining?</a></li>
</ul>

<p>The "authority" for double spending is the blockchain.  The blockchain consists of the history of all blocks in the blockchain plus the next block of transactions.  The reward subsidy currently is 25 BTC to the party that submits the next block.  But hey ...you would like that 25 BTC (worth currently about $825) as would I as would everyone else.  So how do you make it so that I can't cheat and claim the block myself?  </p>

<p>Well, you put in a system that you and I have to compete.  That's what the proof of work does -- it makes it so that when I claim the reward it is easy to prove that I really did the work involved.  So for me to have a 2% chance of solving a block I need to put in 2% of of the mining work.  There's no way for me to put in less than 2% of all the work and still solve blocks at least 2% of the time (on average).</p>

<p>Thus as a result, when a transaction block is submitted, all the peers verify that there were no double spends, that the right amount of subsidy was claimed, and that the submitter truly expended the work necessary for that solution.  With those three rules, then there doesn't not need to be a central authority managing the process or able to control the outcome.</p>

CC BY-SA 3.0
2013-02-28T23:59:26.327Z
2013-03-01T08:14:29.287Z
2017-04-13T12:47:33.283Z
Stephen Gornick
<p>Here is an <em>extremely</em> simplified sketch of the problem, but it should give a pretty good idea of what the problem is.</p>

<p><strong>The data:</strong></p>

<p>This is the hash of the lastest block (shortened to 30 characters): </p>

<pre><code>00000000000001adf44c7d69767585
</code></pre>

<p>These are the hashes of a few valid transactions waiting for inclusion (shortened).</p>

<pre><code>5572eca4dd4
db7d0c0b845
</code></pre>

<p>And this the hash of one special transaction that you just crafted, which gives 25BTC (the current reward) to yourself:</p>

<pre><code>916d849af76
</code></pre>

<p><strong>Building the next block:</strong></p>

<p>Now, let's use a gross approximation of what a new block might look like (the real one uses binary format). It contains the hash of the previous block and the hashes of those 3 transactions:</p>

<pre><code>00000000000001adf44c7d69767585--5572eca4dd4-db7d0c0b845-916d849af76--
</code></pre>

<p>Now let's do mining by hand! Our goal is to complete this block with a nonce (a piece of garbage) such that the hash of the new block starts with 13 zeros (considering the previous hash, it seems that 13 zeroes is the current difficulty!).</p>

<p><strong>Mining (trying to finalize this block):</strong></p>

<p>Let's try with nonce=1, and compute the hash of the block (I'm using the md5 hash algorithm, but Bitcoin uses double sha256):</p>

<pre><code>&gt; echo "00000000000001adf44c7d69767585--5572eca4dd4-db7d0c0b845-916d849af76--1" | md5sum 
8b9b994dcf57f8f90194d82e234b72ac
</code></pre>

<p>No luck, the hash does not start with a 0… Let's try with nonce=2</p>

<pre><code>&gt; echo "00000000000001adf44c7d69767585--5572eca4dd4-db7d0c0b845-916d849af76--2" | md5sum 
5b7ce5bcc07a2822f227fcae7792fd90
</code></pre>

<p>No luck…</p>

<p>…</p>

<p>If we pursue until nonce=16, we get our first leading zero.</p>

<pre><code>&gt; echo "00000000000001adf44c7d69767585--5572eca4dd4-db7d0c0b845-916d849af76--16" | md5sum 
03b80c7a34b060b33dd8fbbece79cee3
</code></pre>

<p>For nonce=208, we get two leading zeroes!</p>

<pre><code>&gt; echo "00000000000001adf44c7d69767585--5572eca4dd4-db7d0c0b845-916d849af76--208" | md5sum 
0055e55df5758517c9bed0981b52ce4a
</code></pre>

<p>Continue like this… If you finally find a hash that has 13 leading zeroes… you're a winner! Other miners will now build upon your block, you've just got 25BTC.</p>

<p>But you'll have to be fast!</p>

<p><strong>Back to step 1…</strong></p>

<p>If someone manages to build a block before you do, you'll have to start again from the beginning with the new block's hash (the one of the winner).</p>

CC BY-SA 3.0
2013-12-02T09:13:02.080Z
This basically sounds like a nice (simplified) summary, but at what point does the bitcoin network accept this as _the_ next valid block, and what happens in the (unlikely) event that two different miners managed to submit a valid block almost simultaneously?
Tobias Kienzler
CC BY-SA 3.0
2014-04-28T17:24:18.810Z
Wow, great answer! There're a couple of things I still couldn't get my head around though: Let's say you've been searching for a solution for 6 minutes and there comes a new transaction. 1) what happens now? if I have to start over, then that sounds like everyone has to start over. Then how can blockchain guarantee to find a block in ~10 minutes? 2) How does that transaction come to me anyway? 3) What if I find a solution for this block and then a new transaction comes to me from some other node who accepted it for the block I just closed?
keremispirli
CC BY-SA 3.0
2014-04-30T10:47:50.153Z
1) Yes everyone starts over, if you build on top of an old block there's little chance your blocks will be part of the longer chain and they will be disregarded by the rest of the network. There is no guaranty that a block is find within 10 minutes, it's just an average statistical outcome. 2) What transaction? Blocks are broadcast by whoever mined them and relayed by other nodes. 3) Nothing forces you to include all pending transactions, but the more transactions you include the more fees you can collect.
Stéphane Gimenez
CC BY-SA 3.0
2014-05-01T12:39:53.640Z
2) The transaction to be added to current block, the one that caused me and all(?) others to restart the calculation. How does it come to me? And also, 3) Why would I accept it for 0.001 btc if I am to find a new block and get 25 btc?
Thanks Stephane!
keremispirli
CC BY-SA 3.0
2013-03-01T18:50:18.043Z
Note that you're not actually "counting zeroes". In reality approximately the first four non zero numbers are being compared with something called a "target".  This is stored in compact form in each block in a field called "bits".
makerofthings7
CC BY-SA 3.0
2013-03-01T18:54:20.690Z
Also your example is conceptually heading in the right direction, but the real success is when the sha256 hash of the header is less than the target. Example target: `00000000000001ae00000000000000` is greater than `00000000000001adf44c7d69767585`     <-- this would be a valid hash.
makerofthings7
CC BY-SA 3.0
2013-07-01T17:05:07.803Z
"And this the hash of one special transaction that you just crafted and which gives 25BTC (the current reward) to yourself: 916d849af76" How is this transaction crafted?
Leonardo Marques
CC BY-SA 3.0
2013-07-01T20:33:13.513Z
@Reonarudo: the simplest is to use one of your addresses to produce a single standard output to be spent, but you can forge any kind of custom transaction with custom scripts as well if it pleases you (you are allowed a +25 BTC total balance for this transaction, additionnal inputs were not allowed some time ago, but maybe they are now).
Stéphane Gimenez
CC BY-SA 3.0
2013-07-01T20:35:40.780Z
So normally I would just append my wallet address in the end between - and --?
Leonardo Marques
CC BY-SA 3.0
2013-07-01T20:39:13.757Z
@Reonarudo, not exactly, this is a very simplified sketch of what is actally done. Transactions are made with scripts which are often made from adresses, you can find more info on the Bitcoin wiki.
Stéphane Gimenez
CC BY-SA 3.0
2013-02-28T18:46:45.740Z
2016-04-21T15:31:18.173Z
2016-04-21T15:31:18.173Z
Stéphane Gimenez
<p>The following is a description of the global, statistical gamble which is played every 10 or so minutes.  The interval of the game is controlled by the <a href="https://bitcoinwisdom.com/bitcoin/difficulty" rel="noreferrer">difficulty</a> which says how many "hashes" are needed per interval. </p>

<p>In other words, the <code>difficulty</code> and <code>target</code> define the "odds of the house" against your chance of getting a winning SHA hash.  The <code>nonce</code> is the "scratch off" area.  </p>

<p>Each hash consumes electricity, and emits heat, which requires additional cooling. </p>

<p>This is what is done with each hash:</p>

<p><strong>Step 1</strong></p>

<p>At a high level, the miner software takes a list of active transactions, and then groups them together in something called a "block". </p>

<p><em>Or more accurately stated:</em> The miner software coverts all the transactions into a summary view called a  "merkle root", and hashes it, which is representative of the transactions.</p>

<p><strong>Step 2</strong></p>

<p>Then mining software converts this to into a binary format called a <a href="https://en.bitcoin.it/wiki/Block_hashing_algorithm" rel="noreferrer">Block Header</a>, which also references the previous blocks (also called a chain).</p>

<pre><code>Field           Purpose                          Updated when...               Size (Bytes)
Version         Block version number             You upgrade the software and   4
                                                 it specifies a new version 

hashPrevBlock   256-bit hash of the previous     A new block comes in          32
                block header    
hashMerkleRoot  256-bit hash based on all        A transaction is accepted     32
                the transactions in the block       

Time            Current timestamp as seconds     Every few seconds              4
                since 1970-01-01T00:00 UTC  

Bits            Current target in compact format   The difficulty is adjusted   4

Nonce           32-bit number (starts at 0)       A hash is tried (increments)  4
</code></pre>

<p><strong>Step 3:</strong></p>

<p>The miner hardware changes a small portion of this block called a "nonce".</p>

<p><strong>Step 4:</strong></p>

<p>The block header <a href="https://www.youtube.com/watch?v=S9JGmA5_unY" rel="noreferrer">is hashed</a> and <a href="https://en.bitcoin.it/wiki/Target" rel="noreferrer">compared to the Target</a> as if it were simply a large number like 10,000,000 > 7,000,000  (the real numbers are much bigger, and in hex).  The target is compressed and stored in each block in a field called bits.</p>

<p>An expanded target looks like this:</p>

<pre><code>  Target   0000000000000083ef00000000000000000000000000000000000000000000000
</code></pre>

<p>And the goal is to make sure the <a href="https://www.youtube.com/watch?v=S9JGmA5_unY" rel="noreferrer">SHA256 hash</a> of the block is <em>less than</em> this value.  In the example below "<code>83ee</code>" is smaller than "<code>83ef</code>"</p>

<p>To simplify this concept, you can ballpark the target by counting the leading zeros (as the other answer here explains).  Here is an example:</p>

<p><a href="http://blockchain.info/block-index/353394/0000000000000083ee9371ddff055eed7f02348e4eda36c741a2fc62c85bc5cf" rel="noreferrer">Here is a sample block with transactions you can view on BlockChain.info.</a> Look in the upper right hand corner of the webpage for this hash:</p>

<pre><code>   Hash 0000000000000083ee9371ddff055eed7f02348e4eda36c741a2fc62c85bc5cf
</code></pre>

<p>That previous hash was from today and has 14 leading zeroes.  Let's compare that to what was needed 3 years ago with <a href="http://blockchain.info/block-index/100" rel="noreferrer">block 100</a> which has 8 leading zeros.  </p>

<pre><code>   Hash 00000000a8ed5e960dccdf309f2ee2132badcc9247755c32a4b7081422d51899
</code></pre>

<p><strong>Summary</strong></p>

<p>So at the end of the day, all a miner does is:</p>

<ol>
<li>Take a block header as input</li>
<li>Change the Nonce</li>
<li>Test if the Block Header <a href="https://www.youtube.com/watch?v=S9JGmA5_unY" rel="noreferrer">hash</a> is less than the Target.  If it is, you win.</li>
<li>Go to step 2  (or go to step 1 if someone else won the block)</li>
</ol>

<p>Want to see what Bitcoin-QT does when it finds a block?... <a href="https://bitcoin.stackexchange.com/a/5782/1878">I posted it here.</a>. The information in this post will help you understand what happened.</p>

CC BY-SA 3.0
2017-09-06T21:09:14.910Z
Isn't the nonce (32 bits) far too small to be able to find a hash that must start with 14 leading zeroes (14x4 = 56 bits) ?  Finding such a hash would require on average 2^56 / 2 attempts and with a 32 bit nonce only 2^32 attempts are possible before all possible nonce values are exhausted.  Edit: with the time changing every second, I guess this only applies if hash rate exceeds 4 GH/sec (which I think it does...)
john16384
CC BY-SA 3.0
2017-09-06T22:54:39.623Z
Yup, you're right, ...from the URL on the Block header: `Whenever Nonce overflows (which it does frequently), the extraNonce portion of the generation transaction is incremented, which changes the Merkle root.`
makerofthings7
CC BY-SA 4.0
2021-12-05T19:31:14.543Z
Best answer I've been able to grok so far. I still don't get how a target is established nor do I fully understand the significance of generating a hash lesser than the target. So a hash is generated closest but lesser that the target, why is that important? Is it because it is theoretically the most complex hash so it's the most (or really close to being the most) difficult hash to crack?
Vance McCorkle
CC BY-SA 4.0
2021-12-06T04:01:37.823Z
@VanceMcCorkle Among bitcoin mining equipment, it's a race among who can press the gas pedal the furthest without blowing up the engine. Every piston movement creates a hashcode ( so to speak). The significance is only a >>RACE TO BURN OIL<<. Bitcoin should be sponsored by Big Oil and Coal.
makerofthings7
CC BY-SA 4.0
2021-12-15T00:43:37.920Z
@ChristopherJonMankowski Except that where I live here in Washington state is literally powered by rain water (Grand Coulee Dam). Plus I rent green hosting space for miners. Nevertheless, still I have found no clear explanation on the block validation process that makes sense to me yet. Although I have yet to read the Bitcoin Standard.
Vance McCorkle
CC BY-SA 4.0
2022-01-02T00:25:40.030Z
@VanceMcCorkle try calculating the cost per Gigahash or Terrahash per energy FOREX cost. That is the industrial cost of capitalism, but not the TCO equivalent of other debts and tradeoffs of ecology not considered as they are hidden by governance and politics to get somewhere.
makerofthings7
CC BY-SA 3.0
2013-02-28T18:50:16.907Z
2017-12-09T22:08:29.260Z
2017-12-09T22:08:29.260Z
makerofthings7
<p>Bitcoin miners are solving complex mathematical puzzles in a process called proof-of-work, which helps secure the Bitcoin network and create new bitcoins. These puzzles are based on cryptographic hash functions, and the main goal is to find a specific input called a nonce that, when combined with the transaction data and previous block's hash, produces an output (a hash) that meets certain requirements, such as having a specific number of leading zeros.</p>
<p>The puzzles are designed to be hard to solve, requiring a lot of computational power, but easy to verify once the solution is found. Miners are essentially searching for a needle in a haystack by trying different nonces until they find the one that meets the required conditions.</p>
<p>The process of solving these puzzles serves two main purposes:</p>
<p>Securing the network: The proof-of-work process makes it difficult for anyone to attack the network or manipulate transaction data. To do so, an attacker would need to control more than 50% of the total mining power, which is highly unlikely given the distributed nature of the network and the vast amount of computational resources required.</p>
<p>Creating new bitcoins: Miners who successfully solve the puzzle and add a new block to the blockchain are rewarded with newly created bitcoins (the block reward) and transaction fees from the transactions included in the block. This serves as an incentive for miners to contribute their computational resources and helps maintain a controlled and predictable supply of new bitcoins.</p>
<p>As more miners join the network and the total computational power increases, the difficulty of the puzzles automatically adjusts to ensure that a new block is added to the blockchain approximately every 10 minutes. This self-adjusting mechanism helps maintain the security and stability of the Bitcoin network.</p>
<p>Bitcoin miners solve a complex mathematical puzzle, called proof-of-work, to generate new bitcoins and secure the network. This puzzle is based on a cryptographic hash function called SHA-256, and the goal is to find a specific input (called a nonce) that results in a hash value that meets certain requirements. Here's a detailed explanation of the process:</p>
<p>Preparing the block: Miners gather recent, unconfirmed Bitcoin transactions and organize them into a data structure called a block. Each transaction is checked to ensure it's valid and not a double-spend attempt. The block also contains a reference to the previous block in the blockchain (by including its hash) and a timestamp.</p>
<p>Calculating the target: The Bitcoin network adjusts the puzzle's difficulty based on the total mining power to maintain an average block generation time of 10 minutes. The difficulty determines the target value for the hash. The target is a 256-bit number, and miners must find a hash that is equal to or lower than this target.</p>
<p>Finding the nonce: Miners generate the hash by combining the block's data, the previous block's hash, and a nonce (a random number). They repeatedly change the nonce and recompute the hash until they find a hash that meets the target requirement. Since hash functions are unpredictable, miners must try many different nonces before finding a valid one. This process is computationally intensive and requires a lot of trial and error.</p>
<p>Proof-of-work: Once a miner finds a valid nonce, they have effectively solved the puzzle and completed the proof-of-work. The valid nonce proves that the miner has expended a significant amount of computational effort to find the solution, thus securing the network.</p>
<p>Broadcasting the block: The miner broadcasts the solved block, along with the valid nonce, to the entire network. Other nodes in the network verify the block and its proof-of-work. If it's valid, they add the block to their local copy of the blockchain.</p>
<p>Block reward: As a reward for solving the puzzle and adding a new block to the blockchain, the miner receives newly created bitcoins (the block reward) and the transaction fees from the transactions in the block. The block reward serves as an incentive for miners to contribute computational resources and secures the network.</p>
<p>This entire process ensures that the Bitcoin network remains secure, transactions are confirmed, and new bitcoins are generated in a controlled and predictable manner. As more miners join the network and the total computational power increases, the difficulty of the puzzle automatically adjusts to maintain the 10-minute block interval, keeping the system stable and secure.</p>

CC BY-SA 4.0
2023-04-26T12:00:53.533Z
2023-04-26T12:00:53.533Z
BBCD Satoshi
<p>They try to find a random nonce (a little random data) that goes into a block and makes the block have a (SHA256) hash that (in binary) starts with a certain amount of 0's. The more zeroes the more rare hash is. A good hash' outcome is not predictable, and so you have to try a lot of times to find a good nonce.</p>

<p>The amount of zeroes are based on how difficult it is supposed to be to find a block. In Bitcoin it adjusts to have a new block every 10 minutes (on average, given the rate at which previous blocks are found).</p>

<p>Interesting: because the hashes are unpredictable it doesn't matter how the nonce changes! Most of the time it's just a number counting upwards from 0!</p>

CC BY-SA 3.0
2014-01-21T15:33:58.673Z
2014-01-21T15:33:58.673Z
Lodewijk
<p>As with mining, what are the bitcoin miners really solving? I read they are solving hashes, but what does that really mean. Can we see what they are solving? Can someone give an example of what a bitcoin mining machine sees to solve?</p>

CC BY-SA 3.0
2013-02-28T23:52:30.587Z
Related: http://bitcoin.stackexchange.com/q/148/153
Stephen Gornick
CC BY-SA 4.0
2022-05-05T19:47:15.600Z
Here is a visual, gamified version of the problem that bitcoin miners are typing to solve. It is literally a bincoin miner, and if you solve the problem then you win a bitcoin. 
http://hashhunt.josh.com/
bigjosh
<mining-theory><hash><mining-reward><proof-of-work>
What are bitcoin miners really solving?
Patoshi パトシ
# What are bitcoin miners really solving?

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

As with mining, what are the bitcoin miners really solving? I read they are solving hashes, but what does that really mean. Can we see what they are solving? Can someone give an example of what a bitcoin mining machine sees to solve?

**Tags:** mining-theory, hash, mining-reward, proof-of-work

> **Comments:**
> **username_1**: Related: http://bitcoin.stackexchange.com/q/148/153  
> **username_2**: Here is a visual, gamified version of the problem that bitcoin miners are typing to solve. It is literally a bincoin miner, and if you solve the problem then you win a bitcoin.  http://hashhunt.josh.com/  

---

## 5 answers

### Answer by username_11 on 2014-01-21. Score: 49 | Accepted answer

They try to find a random nonce (a little random data) that goes into a block and makes the block have a (SHA256) hash that (in binary) starts with a certain amount of 0's. The more zeroes the more rare hash is. A good hash' outcome is not predictable, and so you have to try a lot of times to find a good nonce.

The amount of zeroes are based on how difficult it is supposed to be to find a block. In Bitcoin it adjusts to have a new block every 10 minutes (on average, given the rate at which previous blocks are found).

Interesting: because the hashes are unpredictable it doesn't matter how the nonce changes! Most of the time it's just a number counting upwards from 0!


---

### Answer by username_3 on 2013-02-28. Score: 162

Here is an *extremely* simplified sketch of the problem, but it should give a pretty good idea of what the problem is.

**The data:**

This is the hash of the lastest block (shortened to 30 characters):

```
00000000000001adf44c7d69767585

```

These are the hashes of a few valid transactions waiting for inclusion (shortened).

```
5572eca4dd4
db7d0c0b845

```

And this the hash of one special transaction that you just crafted, which gives 25BTC (the current reward) to yourself:

```
916d849af76

```

**Building the next block:**

Now, let's use a gross approximation of what a new block might look like (the real one uses binary format). It contains the hash of the previous block and the hashes of those 3 transactions:

```
00000000000001adf44c7d69767585--5572eca4dd4-db7d0c0b845-916d849af76--

```

Now let's do mining by hand! Our goal is to complete this block with a nonce (a piece of garbage) such that the hash of the new block starts with 13 zeros (considering the previous hash, it seems that 13 zeroes is the current difficulty!).

**Mining (trying to finalize this block):**

Let's try with nonce=1, and compute the hash of the block (I'm using the md5 hash algorithm, but Bitcoin uses double sha256):

```
> echo "00000000000001adf44c7d69767585--5572eca4dd4-db7d0c0b845-916d849af76--1" | md5sum 
8b9b994dcf57f8f90194d82e234b72ac

```

No luck, the hash does not start with a 0… Let's try with nonce=2

```
> echo "00000000000001adf44c7d69767585--5572eca4dd4-db7d0c0b845-916d849af76--2" | md5sum 
5b7ce5bcc07a2822f227fcae7792fd90

```

No luck…

…

If we pursue until nonce=16, we get our first leading zero.

```
> echo "00000000000001adf44c7d69767585--5572eca4dd4-db7d0c0b845-916d849af76--16" | md5sum 
03b80c7a34b060b33dd8fbbece79cee3

```

For nonce=208, we get two leading zeroes!

```
> echo "00000000000001adf44c7d69767585--5572eca4dd4-db7d0c0b845-916d849af76--208" | md5sum 
0055e55df5758517c9bed0981b52ce4a

```

Continue like this… If you finally find a hash that has 13 leading zeroes… you're a winner! Other miners will now build upon your block, you've just got 25BTC.

But you'll have to be fast!

**Back to step 1…**

If someone manages to build a block before you do, you'll have to start again from the beginning with the new block's hash (the one of the winner).

> **Comments:**
> **username_6**: Note that you're not actually "counting zeroes". In reality approximately the first four non zero numbers are being compared with something called a "target".  This is stored in compact form in each block in a field called "bits".  
> **username_6**: Also your example is conceptually heading in the right direction, but the real success is when the sha256 hash of the header is less than the target. Example target: `00000000000001ae00000000000000` is greater than `00000000000001adf44c7d69767585`     <-- this would be a valid hash.  
> **username_7**: "And this the hash of one special transaction that you just crafted and which gives 25BTC (the current reward) to yourself: 916d849af76" How is this transaction crafted?  
> **username_3**: @Reonarudo: the simplest is to use one of your addresses to produce a single standard output to be spent, but you can forge any kind of custom transaction with custom scripts as well if it pleases you (you are allowed a +25 BTC total balance for this transaction, additionnal inputs were not allowed some time ago, but maybe they are now).  
> **username_7**: So normally I would just append my wallet address in the end between - and --?  
> **username_3**: @Reonarudo, not exactly, this is a very simplified sketch of what is actally done. Transactions are made with scripts which are often made from adresses, you can find more info on the Bitcoin wiki.  
> **username_4**: This basically sounds like a nice (simplified) summary, but at what point does the bitcoin network accept this as _the_ next valid block, and what happens in the (unlikely) event that two different miners managed to submit a valid block almost simultaneously?  
> **username_5**: Wow, great answer! There're a couple of things I still couldn't get my head around though: Let's say you've been searching for a solution for 6 minutes and there comes a new transaction. 1) what happens now? if I have to start over, then that sounds like everyone has to start over. Then how can blockchain guarantee to find a block in ~10 minutes? 2) How does that transaction come to me anyway? 3) What if I find a solution for this block and then a new transaction comes to me from some other node who accepted it for the block I just closed?  
> **username_3**: 1) Yes everyone starts over, if you build on top of an old block there's little chance your blocks will be part of the longer chain and they will be disregarded by the rest of the network. There is no guaranty that a block is find within 10 minutes, it's just an average statistical outcome. 2) What transaction? Blocks are broadcast by whoever mined them and relayed by other nodes. 3) Nothing forces you to include all pending transactions, but the more transactions you include the more fees you can collect.  
> **username_5**: 2) The transaction to be added to current block, the one that caused me and all(?) others to restart the calculation. How does it come to me? And also, 3) Why would I accept it for 0.001 btc if I am to find a new block and get 25 btc? Thanks Stephane!  

---

### Answer by username_6 on 2013-02-28. Score: 74

The following is a description of the global, statistical gamble which is played every 10 or so minutes. The interval of the game is controlled by the [difficulty](https://bitcoinwisdom.com/bitcoin/difficulty) which says how many "hashes" are needed per interval.

In other words, the `difficulty` and `target` define the "odds of the house" against your chance of getting a winning SHA hash. The `nonce` is the "scratch off" area.

Each hash consumes electricity, and emits heat, which requires additional cooling.

This is what is done with each hash:

**Step 1**

At a high level, the miner software takes a list of active transactions, and then groups them together in something called a "block".

*Or more accurately stated:* The miner software coverts all the transactions into a summary view called a "merkle root", and hashes it, which is representative of the transactions.

**Step 2**

Then mining software converts this to into a binary format called a [Block Header](https://en.bitcoin.it/wiki/Block_hashing_algorithm), which also references the previous blocks (also called a chain).

```
Field           Purpose                          Updated when...               Size (Bytes)
Version         Block version number             You upgrade the software and   4
                                                 it specifies a new version 

hashPrevBlock   256-bit hash of the previous     A new block comes in          32
                block header    
hashMerkleRoot  256-bit hash based on all        A transaction is accepted     32
                the transactions in the block       

Time            Current timestamp as seconds     Every few seconds              4
                since 1970-01-01T00:00 UTC  

Bits            Current target in compact format   The difficulty is adjusted   4

Nonce           32-bit number (starts at 0)       A hash is tried (increments)  4

```

**Step 3:**

The miner hardware changes a small portion of this block called a "nonce".

**Step 4:**

The block header [is hashed](https://www.youtube.com/watch?v=S9JGmA5_unY) and [compared to the Target](https://en.bitcoin.it/wiki/Target) as if it were simply a large number like 10,000,000 > 7,000,000 (the real numbers are much bigger, and in hex). The target is compressed and stored in each block in a field called bits.

An expanded target looks like this:

```
  Target   0000000000000083ef00000000000000000000000000000000000000000000000

```

And the goal is to make sure the [SHA256 hash](https://www.youtube.com/watch?v=S9JGmA5_unY) of the block is *less than* this value. In the example below "`83ee`" is smaller than "`83ef`"

To simplify this concept, you can ballpark the target by counting the leading zeros (as the other answer here explains). Here is an example:

[Here is a sample block with transactions you can view on BlockChain.info.](http://blockchain.info/block-index/353394/0000000000000083ee9371ddff055eed7f02348e4eda36c741a2fc62c85bc5cf) Look in the upper right hand corner of the webpage for this hash:

```
   Hash 0000000000000083ee9371ddff055eed7f02348e4eda36c741a2fc62c85bc5cf

```

That previous hash was from today and has 14 leading zeroes. Let's compare that to what was needed 3 years ago with [block 100](http://blockchain.info/block-index/100) which has 8 leading zeros.

```
   Hash 00000000a8ed5e960dccdf309f2ee2132badcc9247755c32a4b7081422d51899

```

**Summary**

So at the end of the day, all a miner does is:

1. Take a block header as input
2. Change the Nonce
3. Test if the Block Header [hash](https://www.youtube.com/watch?v=S9JGmA5_unY) is less than the Target. If it is, you win.
4. Go to step 2 (or go to step 1 if someone else won the block)

Want to see what Bitcoin-QT does when it finds a block?... [I posted it here.](https://bitcoin.stackexchange.com/a/5782/1878). The information in this post will help you understand what happened.

> **Comments:**
> **username_8**: Isn't the nonce (32 bits) far too small to be able to find a hash that must start with 14 leading zeroes (14x4 = 56 bits) ?  Finding such a hash would require on average 2^56 / 2 attempts and with a 32 bit nonce only 2^32 attempts are possible before all possible nonce values are exhausted.  Edit: with the time changing every second, I guess this only applies if hash rate exceeds 4 GH/sec (which I think it does...)  
> **username_6**: Yup, you're right, ...from the URL on the Block header: `Whenever Nonce overflows (which it does frequently), the extraNonce portion of the generation transaction is incremented, which changes the Merkle root.`  
> **username_9**: Best answer I've been able to grok so far. I still don't get how a target is established nor do I fully understand the significance of generating a hash lesser than the target. So a hash is generated closest but lesser that the target, why is that important? Is it because it is theoretically the most complex hash so it's the most (or really close to being the most) difficult hash to crack?  
> **username_6**: @username_9 Among bitcoin mining equipment, it's a race among who can press the gas pedal the furthest without blowing up the engine. Every piston movement creates a hashcode ( so to speak). The significance is only a >>RACE TO BURN OIL<<. Bitcoin should be sponsored by Big Oil and Coal.  
> **username_9**: @ChristopherJonMankowski Except that where I live here in Washington state is literally powered by rain water (Grand Coulee Dam). Plus I rent green hosting space for miners. Nevertheless, still I have found no clear explanation on the block validation process that makes sense to me yet. Although I have yet to read the Bitcoin Standard.  
> **username_6**: @username_9 try calculating the cost per Gigahash or Terrahash per energy FOREX cost. That is the industrial cost of capitalism, but not the TCO equivalent of other debts and tradeoffs of ecology not considered as they are hidden by governance and politics to get somewhere.  

---

### Answer by username_1 on 2013-02-28. Score: 13

Mining provides a way to reach consensus on what the transaction ledger should look like and know that nobody is cheating.

That's the non-technical definition of mining.

* [What exactly is Mining?](https://bitcoin.stackexchange.com/q/148/153)

The "authority" for double spending is the blockchain. The blockchain consists of the history of all blocks in the blockchain plus the next block of transactions. The reward subsidy currently is 25 BTC to the party that submits the next block. But hey ...you would like that 25 BTC (worth currently about $825) as would I as would everyone else. So how do you make it so that I can't cheat and claim the block myself?

Well, you put in a system that you and I have to compete. That's what the proof of work does -- it makes it so that when I claim the reward it is easy to prove that I really did the work involved. So for me to have a 2% chance of solving a block I need to put in 2% of of the mining work. There's no way for me to put in less than 2% of all the work and still solve blocks at least 2% of the time (on average).

Thus as a result, when a transaction block is submitted, all the peers verify that there were no double spends, that the right amount of subsidy was claimed, and that the submitter truly expended the work necessary for that solution. With those three rules, then there doesn't not need to be a central authority managing the process or able to control the outcome.


---

### Answer by username_10 on 2023-04-26. Score: 0

Bitcoin miners are solving complex mathematical puzzles in a process called proof-of-work, which helps secure the Bitcoin network and create new bitcoins. These puzzles are based on cryptographic hash functions, and the main goal is to find a specific input called a nonce that, when combined with the transaction data and previous block's hash, produces an output (a hash) that meets certain requirements, such as having a specific number of leading zeros.

The puzzles are designed to be hard to solve, requiring a lot of computational power, but easy to verify once the solution is found. Miners are essentially searching for a needle in a haystack by trying different nonces until they find the one that meets the required conditions.

The process of solving these puzzles serves two main purposes:

Securing the network: The proof-of-work process makes it difficult for anyone to attack the network or manipulate transaction data. To do so, an attacker would need to control more than 50% of the total mining power, which is highly unlikely given the distributed nature of the network and the vast amount of computational resources required.

Creating new bitcoins: Miners who successfully solve the puzzle and add a new block to the blockchain are rewarded with newly created bitcoins (the block reward) and transaction fees from the transactions included in the block. This serves as an incentive for miners to contribute their computational resources and helps maintain a controlled and predictable supply of new bitcoins.

As more miners join the network and the total computational power increases, the difficulty of the puzzles automatically adjusts to ensure that a new block is added to the blockchain approximately every 10 minutes. This self-adjusting mechanism helps maintain the security and stability of the Bitcoin network.

Bitcoin miners solve a complex mathematical puzzle, called proof-of-work, to generate new bitcoins and secure the network. This puzzle is based on a cryptographic hash function called SHA-256, and the goal is to find a specific input (called a nonce) that results in a hash value that meets certain requirements. Here's a detailed explanation of the process:

Preparing the block: Miners gather recent, unconfirmed Bitcoin transactions and organize them into a data structure called a block. Each transaction is checked to ensure it's valid and not a double-spend attempt. The block also contains a reference to the previous block in the blockchain (by including its hash) and a timestamp.

Calculating the target: The Bitcoin network adjusts the puzzle's difficulty based on the total mining power to maintain an average block generation time of 10 minutes. The difficulty determines the target value for the hash. The target is a 256-bit number, and miners must find a hash that is equal to or lower than this target.

Finding the nonce: Miners generate the hash by combining the block's data, the previous block's hash, and a nonce (a random number). They repeatedly change the nonce and recompute the hash until they find a hash that meets the target requirement. Since hash functions are unpredictable, miners must try many different nonces before finding a valid one. This process is computationally intensive and requires a lot of trial and error.

Proof-of-work: Once a miner finds a valid nonce, they have effectively solved the puzzle and completed the proof-of-work. The valid nonce proves that the miner has expended a significant amount of computational effort to find the solution, thus securing the network.

Broadcasting the block: The miner broadcasts the solved block, along with the valid nonce, to the entire network. Other nodes in the network verify the block and its proof-of-work. If it's valid, they add the block to their local copy of the blockchain.

Block reward: As a reward for solving the puzzle and adding a new block to the blockchain, the miner receives newly created bitcoins (the block reward) and the transaction fees from the transactions in the block. The block reward serves as an incentive for miners to contribute computational resources and secures the network.

This entire process ensures that the Bitcoin network remains secure, transactions are confirmed, and new bitcoins are generated in a controlled and predictable manner. As more miners join the network and the total computational power increases, the difficulty of the puzzle automatically adjusts to maintain the 10-minute block interval, keeping the system stable and secure.


---

