1d ago (edited) in General discussion
How the Bitcoin Halving works
Hey all, I'm a crypto lover and have been one for close to a decade. 👋
I spoke with Ted recently and he suggested I share some of my Bitcoin related posts here, so I thought I'd start with this one on the Bitcoin Halving. It's from my blog here and you can also find it in my crypto community.
This post is on how the Bitcoin Halving works from a technical standpoint, let me know your thoughts in the comments ...
**Every 210,000 blocks, around 4 years, Bitcoin's block rewards get halved.**
TLDR:
  • Bitcoin Halvings are pre-programmed and halve the block rewards every 4 years. Earlier this year at block number 840,000 we had the 4th halving!
  • The halving code is incredibly simple and elegant, it’s only 6 lines of code and you can learn how it works by reading below.
  • The result is that Bitcoin’s supply curve approximates precious metals like gold, with most of the coins mined early and them being harder to mine over time.
  • Price has historically gone up after a halving, one of the key factors is the impact on miners who are forced to sell less BTC.
  • This past halving we also had the release of Bitcoin Runes, a new fungible token standard on Bitcoin created by the Casey Rordamor who created Ordinals.
If you’ve been in Bitcoin long enough you’ll know most of this, but you may not have taken a look at the code behind it as we will below.
.
**Bitcoin Halving**
Bitcoin is programmed to produce 1 new block on average every 10 minutes. For each new block mined, miners are allowed to reward themselves a maximum “block subsidy” in a transaction known as the “coinbase transaction” that sits at the start of a block and essentially creates new Bitcoin out of nothing.
This coinbase transaction is super important because it’s what introduces new Bitcoin into the overall system and is known as mining new Bitcoin! In principle miners can introduce less than the maximum “subsidy” but that would be silly because they’d be rewarding themselves less, so they practically always mine the full block reward.
At every 210,000 blocks, which is approximately every 4 years, this maximum block reward is halved - this is known as the “Bitcon Halving”!
When this post was originally released we were approximately 1 day and 5 hours away from block 840,000, which marked the 4th Bitcoin Halving event. Now we're some 3 years and 162 days away from then next one!
[Take a look at image 1]
Bitcoin began with a block subsidy of 50 BTC per block and dropped sequentially down to 25 BTC, 12.5 BTC, 6.25 BTC and in this 4th halving dropped to 3.125 BTC per block. And this trend means that there will never be more than 21 million BTC in circulation!
Today over 93.5% of all Bitcoin that will ever exist has already been mined, in fact over half was mined in only the first 4 years of its existence.
If you’re interested you can see a fascinating visual animation of the Halving’s effect on Bitcoin’s total supply in this tweet.
[Take a look at image 2]
.
**The Halving Code**
Bitcoin is in some ways a messy system with people spread all over the world vying to influence and participate in it. Yet in other ways it’s incredibly elegant, and the “Halving” code is a great example of this elegance.
You can find Bitcoin’s pre-programmed halving code in it’s GitHub repo in the function “GetBlockSubsidy()”, that sets the maximum reward per block.
[Take a look at image 3]
Clearly the code for this function is incredibly short and elegant. If you remove comments and empty lines, it’s essentially only 6 lines of code!
Taking a quick look line by line we first see that the current “halving” is found by dividing the current block height by the “halving interval”, that’s predefined as 210,000 blocks. By storing this variable as an “int”, the result of this division is truncated meaning all decimal places are thrown away.
Therefore anything below 210,000 = 0, below 420,000 = 1, below 630,000 = 2, below 840,000 = 3, and below 1,050,000 = 4, etc. So when we passed block 840,000 earlier this year we moved into the era of the 4th halving!
You can also see that in a far future when we get beyond the 64th halving, the function will simply return a block reward of 0 BTC as all possible BTC will have been mined.
For the first 64 halvings though it takes the original subsidy of 50 BTC and halves it a proportional number of times to the number of halvenings. So now on halving 4 it will halve it 4 times. It does this through an elegant and simple “bit shift” operation:
nSubsidy >>= halvings
This works because integers are essentially sequences of 1s and 0s stored in a binary representation, and so a bit shift to the right will remove a 0 from a number. As an example 1000 » 1 = 100, this is a division by 2 in binary, ie. halves the number.
If you’re not familiar with binary, you can compare with the decimal system. In decimals 1,000 (one thousand) bit shifted right = 100 (one hundred), which is a division by 10. Meanwhile in binary 1000 (sixteen) bit shifted right = 100 (eight), a division by 2.
.
**The Result**
From this short but elegant code we get this profound and continuous halving effect of the block reward every 210,000 blocks. Starting with a 50 BTC reward and continuously halving onwards for a total of 64 times until no more BTC can be mined.
[Take a look at image 4]
A halving occurs approximately every 4 years. This is because 1 block is mined around every 10 minutes, and there are 365 days x 24 hours x 60 minutes = 525,600 minutes in a year, so that’s 52,560 blocks per year, and 210,000 / 52,560 blocks = 3.99 years!
We can approximate the outcome of the code to something very similar to a logarithmic curve trending to 21M as shown below. Note that this image was drawn in 2018 but it still stands as the trend has been pre-programmed from Bitcoin’s inception.
[Take a look at image 5]
This trend was programmed intentionally to try and emulate how rare metals like gold and platinum tend to be mined.
Gold is a rare metal that cannot be created by humans (at least not yet) it can only be mined in scarce quantities underground. In the past it was easier to find, but as humans mined more and more gold, it became harder to extract with more energy and complex machinery being needed to mine an ever smaller supply of gold on the planet.
The outcome is that larger quantities of gold were extracted at a cheaper price to start, and over time ever smaller quantities required more energy, just like Bitcoin!
These scarce properties we see in gold are a key part of what makes it command the highest market capitalisation of any asset on the planet. Emulating this core scarctiy characteristic of gold was exactly what Satoshi Nakamoto wanted built into Bitcoin.
.
**The Effect on Price**
Bitcoin’s pre-programmed scarcity is an important feature, and is a big part of why Bitcoin has experienced a continuous rise in price. And every single Bitcoin halving has historically caused a large run up in price in the months that followed.
[Take a look at image 6]
One of the key factors in this is that on the Halving block we suddenly see the economics of Bitcoin change dramatically for miners.
Not only do miners earn half the amount of BTC per day that they were previously earning, but their cost of mining also literally doubles as they they pay the same amount in electricity to get half the number of BTC rewards! This mining cost eventually re-adjusts but there’s a significant lag before it does.
This two-pronged effect on miners means that they simply cannot sell as much BTC into the market as before, so there’s less sell pressure. Plus there’s a big incentive to just hold onto the more expensive BTC mined today to offset this cost in the future, reducing their likelihood to sell even further.
Since miners are one of the most steady sellers on the market, all of this activity helps to set up a new demand and supply equilibrium pushing the price of Bitcoin up.
Plan B created Bitcoin’s Stock-to-flow model comparing this mining output to that of precious metals like gold, as discussed above. The S2F model strongly correlates the reduction in supply with an increase in price and has generally been quite accurate.
[Take a look at image 7]
Of course no model is perfect and the S2F’s accuracy in the past isn’t enough to guarantee the future. Moreover Bitcoin’s price is a complex system and the impact of miners has become lower at every halving since the inflation rate is lower.
Although nobody can predict the future and be 100% certain what we’ll get this time around, my gut feeling is we’ll see a very similar upward trend in Bitcoin price with history repeating itself in some form.
.
**Runes**
For anyone who’s been paying attention to the Ordinals ecosystem on Bitcoin the 4th Bitcoin Halving also came with an additional unlock on the Bitcoin blockchain, namely that Bitcoin “Runes” became active!
Bitcoin Runes are a new standard from Casey Rordamor, the creator of Ordinals that introduces a “fungible token” standard on Bitcoin just as Ordinals introduced a “non-fungible” standard, and they deserve a whole post of their own.
For now though it suffices to say that Runes allows people to create new tokens on Bitcoin, just like Ethereum has thousands of ERC20 tokens that live on it. And it has already created a whole new ecosystem of coins just as Ordinals created a new ecosystem of NFTs that live on Bitcoin.
[Take a look at image 8]
Casey Rordamor has symbolically chose to make the Runes system go live on block 840,000 when the 4th halving happened.
Making the 4th Halving even more impactful with the unlocking of a new design space in the Bitcoin ecosystem!
0
6 comments
Arthur Fox
2
How the Bitcoin Halving works
Bitcoin
skool.com/bitcoin
A free community for people wanting to learn about bitcoin.
Leaderboard (30-day)
powered by