# What is the meaning of difficulty in Bitcoin mining?

I'm a beginner in Bitcoin and Blockchain technology, so I have a question after reading about the difficulty in Bitcoin mining:

What does the difficulty actually mean?

A high difficulty means that it will take more computing power to mine the same number of blocks, making the network more secure against attacks

However, I don't clearly understand.

Ex: When the difficulty is 6, then what I can know from that number?

Suppose I give you some very complicated function `f()`, and I assign you the task of finding an input `n` with the property that `f(n)` is small. That can be difficult. I can make it more difficult by changing the definition of "small". If I ask you to find an `n` such that `f(n)< 100`, that's difficult. If I ask you to find an `n` such that `f(n)< 90`, that's more difficult.

Once you've compiled a block, you're confronted with a function `f()`. The function itself depends both on the block you've just compiled and the solution someone found for the problem associated with the preceding block. Successfully mining the block means finding an `n` such that `f(n)` is small. The only way that anybody knows to solve this problem is by trial and error.

The definition of "small" is periodically adjusted. That definition of "small" is what people mean by "difficulty".

I'm a beginner in Bitcoin

What does difficulty actually mean?

To understand the difficulty number in Bitcoin, you have to understand it's purpose and not just the mathematics of it.

To understand the purpose of the difficulty number, you first need to understand the role of mining and timestamping.

Bitcoin is digital cash and it has no tangible coins. Bitcoin money is kept track of by keeping a record of the transactions. A transaction is a transfer of control over some amounts of money. For example if you give someone 10000 BTC for two Pizzas, the Bitcoin part of that exchange is a Bitcoin transaction.

It is obviously important that the person who already spent the money isn't allowed spend it again. To prevent that, everyone has to know what transactions already occurred and in what order.

The order is important so that you can decide which of two spends are valid.

For example Joe has 10 BTC

``````Monday,  Joe gives Sue the 10 BTC
Tuesday, Joe gives Bob the 10 BTC
``````

Is different from

``````Monday,  Joe gives Bob the 10 BTC
Tuesday, Joe gives Sue the 10 BTC
``````

We need to know which transaction is accepted and which is fraudulent and should be rejected. This is important to Sue and Bob. Those timestamps (Monday, Tuesday) enable us to do that. This has to work at a global scale so that nodes in Atlanta and Auckland agree.

In Bitcoin it is miners who add transactions to blocks and add blocks to the blockchain. The blockchain is like an accounting journal of transactions and blocks are like pages in that journal.

So miners are ordering the transactions by timestamping the blocks (and by effectively numbering the pages).

Adding a new block is also the way that new amounts of Bitcoin money are created. You can think if it as new Bitcoin "coins" being created. This money is created as a reward for the miners.

Bitcoin's designers wanted a new page to be written every ten minutes. The rate is important because it affects inflation in the currency. The rate must also be fast enough that recipients can quickly see they have been paid. The rate must be slow enough that every node can keep up with receiving and checking new pages (new blocks).

However producing a new block could be a trivial amount of work, so greedy people might mine 1000000 blocks a second to scoop up all the mining rewards. They would quickly run away with vast amounts of money. Therefore the mining is made difficult.

How difficult it needs to be depends on how much computing power all the miners have at any moment. If there are more miners with better computers, we need to increase the difficulty of mining so that they can't produce more than a block every 10 minutes on average.

The difficulty number is the inverse of a target number, higher difficulties correspond to smaller targets.

Miners construct a block (a page in the transaction journal) and then calculate a hash of that block. This hash is a very large number that has to be less than the current target number.

About every two weeks, all Bitcoin nodes (wallets, miners, etc) recalculate the difficulty based on the average time between blocks in the last two weeks. If the average is less than 10 minutes, the difficulty is increased proportionately; if more, decreased. From then on nodes reject any blocks from miners that don't have a hash less than the new target.

This prevents double spending and ensures a wealthy miner can't take over mining and commit fraud.

When the difficulty is 6, then what I can know from that number?

You could calculate the target. You could see that new blocks have a hash smaller than that target.

• Thanks @RedGrittyBrick for your detailed answer. You helped me to have a sense of what the difficulty is! Hmm, I'm a little confused that with a specific target, and the difficulty is 1, then is there any useful information that I can retrieve from that? It may be about computation power, speed, or something like that Thank you so much May 18, 2021 at 15:55

A simple way to think about bitcoin's mining "difficulty" is to remember that purpose of the difficulty (which is re-assessed/changed every 2016 blocks - about 2 weeks), is to keep the bitcoin block issuance time at 10 minutes.

The difficulty determines how much work the bitcoin miners have to do in order to solve the "puzzle" in order to create a new and valid block. If more hashrate gets added to the network, then the blocks get created faster than 10 minutes. So at the next difficulty adjustment, the difficulty will increase so that the block time (on average) will take 10 minutes. Conversely if hashrate leaves the network then blocktimes slow down, so at the next adjustment period, the difficulty reduces, returning the average block time to 10 minutes.

It's very clever and one of Satoshi's unique innovations that makes the protocol self-regulating!

Difficulty adjustment is one of the critical features of Bitcoin that Satoshi implemented. It basically means - adjusting the bitcoin block time to ~ 10 minutes as programmed.

Think of it this way - if suddenly more miners join in then there would be more hash power and blocks would be mined quicker then before (less then 10 minutes) - the difficulty adjustment, that happens every 2016 blocks (~2 weeks) would raise the difficulty of mining making if harder to find the block eventually raising the block time back to ~10 mins.

The same thing applies if there are miners leaving (shutting of their miners) - then there would be less hashpower resulting in slower block times (more then 10 minutes) so the difficulty would lower making it easier for the remaining miners to find the block eventually lowering the block time to ~ 10 minutes.

Ex: When the difficulty is 6, then what I can know from that number?

Difficulty is measured in % of change, the current difficulty change is estimated at -10%, meaning it will be 10% easier to mine a block in the next difficulty epoch (each epoch is 2016 blocks)

check it out here https://bitcoin.clarkmoody.com/dashboard/