Bỏ qua tới nội dung chính

Exness hoàn 100% hoa hồng IB

Không khoản nào bị trừ trước khi về tài khoản bạn

EA và indicator miễn phí

XM hoàn 90%, nạp tối thiểu 5 USD

How does Bitcoin mining work?

Bitcoin miners build a candidate block, then hash its header over and over, changing a number called the nonce each time. The block counts only when its hash comes out below a target set by the network. Every 2,016 blocks the network resets the target so that blocks keep arriving about every ten minutes.

Nội dung này hiện chỉ có bản tiếng Anh.

6 phút đọcAutoFXRebate

A Bitcoin mining machine spends its whole life guessing. Almost every guess fails, and a modern machine makes trillions of them every second. One success is enough to earn a block reward.

This lesson follows one block from start to finish. The big picture of crypto mining, why it exists and how miners are paid, has its own lesson.

Step 1: build a candidate block

The miner picks transactions from its mempool, usually those paying the highest fee rate. At the top it adds the coinbase transaction, a special entry that pays the miner the new coins plus all the fees.

The term comes from Bitcoin's own code and simply means the transaction that creates new coins.

Next the miner writes the block header, a short summary of 80 bytes. Its main fields are:

  • the hash of the previous block, which links this block to the chain
  • one fingerprint that summarises every transaction in the block
  • the time
  • the current target
  • the nonce, a number the miner is free to change
A block header with five fields, previous block hash, transactions fingerprint, time, target and nonce, fed through SHA-256 twice to give a block hash that is checked against the target, with a loop back to change the nonce when the hash is too high.
Change the nonce, hash again, and check against the target.

Everything in the block is tied to the header. Change one transaction and the fingerprint changes, which changes the header and therefore its hash. The lesson on how hashing works explains why.

Step 2: guess until the hash is low enough

Bitcoin runs the header through the SHA-256 hash function twice. The output is a 256-bit number that looks random. Change the nonce by one and the output changes completely, with no way to predict the new value.

The rule is that the block is valid only if that number is below the target. A lower target leaves fewer winning numbers, so it takes more guesses on average to hit one.

Take a toy hash that turns any input into a number from 0 to 99, and a target of 10.

  1. Only the results 0 to 9 win, which is 10 out of 100 possible results.
  2. Each guess has a 1 in 10 chance, so a miner needs about 10 guesses on average.
  3. Nonces 0 to 6 give 74, 31, 90, 12, 56, 23 and 38, all 10 or higher.
  4. Nonce 7 gives 4, which is below 10, so the block is valid.
A toy chart of eight guesses: nonces 0 to 6 give hash values of 74, 31, 90, 12, 56, 23 and 38, all above the target line at 10, and nonce 7 gives 4, below the target, marked valid.
Toy numbers: only a result below the target counts.

Halve the target to 5 and only 0 to 4 win. Each guess now has a 1 in 20 chance, so the average doubles to 20 guesses. This is difficulty: a lower target means more work per block.

Real numbers are vastly bigger. The nonce field holds about 4.3 billion values, which a modern machine exhausts in a fraction of a second, so miners also change the time or a spare field in the coinbase transaction.

Checking a guess takes one hash. Anyone can check the winning guess instantly, even though finding it took the whole network a huge effort.

Step 3: broadcast, check, build on top

The winning miner broadcasts the block. Each node checks that the hash is below the target, every transaction is valid and the reward is no bigger than allowed. If anything fails, the block is rejected and its work is wasted.

Honest miners then start on the next block, using the new block's hash as their previous block field. Each block added on top of yours is one more confirmation for the transactions inside it.

Sometimes two miners find valid blocks seconds apart, and the network briefly splits. The tie breaks when the next block lands on one side. Nodes follow the chain with the most work, and the other block is dropped.

Block 100 followed by two competing blocks at height 101; blocks 102 and 103 build on the upper one, which is kept, while the lower 101 is dropped and its transactions return to the mempool.
When two blocks tie, the chain with the most work wins.

Transactions from the dropped block that the winning chain does not include go back to the mempool. This is why an exchange waits for several confirmations before crediting a Bitcoin deposit.

The dropped block's reward disappears for good. That is why Bitcoin's rules let a miner spend a new reward only in a block at least 100 blocks later.

How difficulty keeps blocks near ten minutes

Bitcoin aims for one block every ten minutes. Every 2,016 blocks, each node compares how long those blocks took with the expected 20,160 minutes, exactly 14 days, and moves the target.

With illustrative numbers:

  1. The last 2,016 blocks should have taken 14 days.
  2. New machines joined, and they took 12 days.
  3. Blocks came 14 ÷ 12 = 1.167 times too fast.
  4. The network lowers the target so each block needs about 16.7% more guesses on average.

If miners switch off after a price fall, the reverse happens: blocks slow down until the next adjustment, which raises the target and makes mining easier. Each adjustment is capped at a factor of four either way.

Why most miners join pools

Solo mining income is lumpy. Say your machines have one millionth of the network's power. At 144 blocks a day, you would expect one block every 1,000,000 ÷ 144 = 6,944 days, about 19 years.

A mining pool combines many miners' guesses and splits each reward by the work each one did, minus a pool fee.

Now join a pool with 10% of the network. It finds about 14.4 blocks a day, and your machines make up 1 in 100,000 of the pool.

Before the pool's fee, the average is the same either way: 14.4 ÷ 100,000 = 0.000144 blocks' worth a day in the pool, and 144 ÷ 1,000,000 = 0.000144 solo. The pool turns a rare jackpot into small, regular payments.

Pools carry a risk of their own. The pool operator usually chooses which transactions go into the pool's blocks. If a few pools together reached most of the network's power, they could censor payments or rewrite recent blocks.

Why the past is hard to rewrite

To change a block from an hour ago, an attacker must redo the work for that block and the five or so after it. Then they must overtake the honest chain while it keeps growing.

That needs more hashing power than all honest miners combined, which is called a 51% attack. On Bitcoin it would mean buying and running more machines than the rest of the network.

Smaller proof of work coins, with far less hashing power, have suffered such attacks. The lesson on proof of work vs proof of stake compares this defence with the one staking networks use.

Câu hỏi thường gặp

How long does it take to mine one bitcoin?

There is no fixed time per coin. The network finds a block about every ten minutes and pays the reward its schedule sets, and how long you take depends on your share of the total hashing power.

What is a nonce in Bitcoin mining?

The nonce is a number in the block header that miners change on every guess. Each new value produces a completely different hash, which gives the miner a fresh chance to land below the target.

Why does Bitcoin mining use so much electricity?

The cost of guessing is what protects the chain. Miners keep adding machines while rewards cover their power bills, and difficulty rises to match, so higher rewards in dollars tend to pull in more power use.

What happens when all bitcoins have been mined?

The subsidy keeps halving until it rounds down to zero, around the year 2140. After that, miners earn only the fees paid by the transactions they include.

Góp ý

Tài khoản của bạn đang ở sàn nào?

Mỗi sàn một đường chuyển khác nhau, nên chúng tôi đưa bạn tới đúng phần của sàn đó.