Here's what the Bitcoin halving looks like. Literally

A deep dive into the code that will make the Bitcoin halving occur and the secret limit to the number of halvings.

4 min read

In brief:

  • The Bitcoin halving will happen in five days.
  • Bitcoin miners will see their mining rewards cut in half.
  • Here's what that actually looks like.

With six days left until the Bitcoin halving, the event has become one of the most talked-about topics in the crypto industry. Experts have been racing to weigh in on the effects the halving will have on the market, with many arguing over whether or not the halving has already been “priced in.”

The total supply of Bitcoin is capped at 21 million coins, which means that once the final coin is mined no new Bitcoin will enter its supply. Each new Bitcoin is created by mining, a process in which powerful hardware competes to solve complex math problems. Once a block is created, the miner that created it receives a certain amount of Bitcoin (BTC) as a reward.

When Bitcoin was created, the block reward was initially set to 50 BTC per block, meaning that each miner that discovers a valid block would earn 50 BTC. But the 10-minute block time would mean that the entire supply would be mined in less than eight years.

To solve this problem, the Bitcoin network contains a rather interesting piece of code that decreases the block rewards given to miners over time. That way, the nodes supporting the networks would be incentivized to continue mining and secure the network.

Instead of instituting a complex mechanism, the creator of Bitcoin equipped it with a single line of code that instructed the network to halve the rewards going to miners every 210,000 blocks.

Here are the main factors involved:

  • Consensus.nSubsidyHalvingInterval = 210,000
  • nHeight = current block height ( Will be 630,000 at the time of halving)
  • COIN = 100,000,000 ( Number of Satoshis in 1 Bitcoin)
  • nSubsidy = The subsidy for mining 1 block

And here is the Bitcoin code:

The code that makes the Bitcoin block reward cut in half every four years. Image: 8BTC.

The function we see in the code above is called “GetBlockSubsidy.” The purpose of the function is to calculate the subsidy, or reward, for mining a Bitcoin block. This is what determines how much miners get paid.

The variable “halvings” calculates the number of halving events by dividing the current block height by a constant value of 210,000. On the day of the halving, the variable “nHeight,” which represents the current block height, will be greater than 6,30,000. Therefore, the value of the halvings will be three (6,30,000/2,10,000). And this will tell the system that it's time for the third halving.

The number of the halving will be then checked to determine if it is greater than 64, as Bitcoin is programmed to undergo a maximum of 64 halvings. Since next week’s halving will be its third one, the code will be able to proceed.

In line 1,245, we see the original subsidy that is calculated for mining a block. The unit of “nSubsidy” is COIN, which is a constant representing 100,000,000 units—equivalent to the number of satoshis (the smallest amount of Bitcoin) in a single Bitcoin.

After line 1,245 executes, the value of “nSubsidy” is 50 Bitcoin. Then this is divided in half for every halving that has already happened. For the third halving, it will be divided in half three times, down to 6.25 Bitcoin. And this is how much each Bitcoin miner will get for mining a new block.

And there you have it folks, the magic of Bitcoin.

[This story was originally published on, and is shared by arrangement with that site. It has been edited to conform with Decrypt's style.]

Copy article link

Want to be a crypto expert? Get the best of Decrypt straight to your inbox.

Get the biggest crypto news stories + weekly roundups and more!