• Home
  • Blog
  • Halve Time: The code behind the coin

Halve Time: The code behind the coin

Christian Trummer

By Christian Trummer

Welcome back to part 3 of our Halve Time series.

You can read Eric’s intro post here, and Paul’s look at the economics of the Halving here if you haven’t already. If this is the first piece you’ve clicked on then the basic idea is that we are writing a series of articles that celebrate and explore the Halving. 

We all became interested in crypto for different reasons, we all brought different skills and passions, and the Halving is a good moment to celebrate that. At its core, the Halving is about the mechanics of a beautiful way to control supply, and a time to look at how that technology has evolved. But this isn’t just a technical event, it's a celebration of Bitcoin's enduring design and its journey toward becoming a decentralised cornerstone of the digital economy. 

First things first - let’s take a look at the code. Fair warning, we are going to get technical here, but this is one of the foundations not just of the Halving event, but also of the wider crypto world. This is the part of technology that underpins the future, so strap in. It’s also the absolute proof to all critics when they believe that 21 million bitcoin is not a hard limit.

Understanding the code

At the heart of the Halving event is a simple yet beautiful piece of code within the Bitcoin protocol. This code dictates that every 210,000 blocks, the reward for mining new blocks is halved. 

Here's a snippet of the code responsible:

Breaking this down, the top half of the code works out how many Halvings there have been.

int halvings = nHeight / consensusParams.nSubsidyHalvingInterval;

This line establishes that the number of blocks needed for a Halving event is fixed at 210,000.Because the intHalving value can only ever be a whole number and is rounded down, that means that the network has to mine 840,000 blocks to trigger the fourth Halving. 

The second half of this part of the code deals with rewards. 

CAmount nSubsidy = 50 * COIN;

nSubsidy >>= halvings;

return nSubsidy;

This means that block rewards start with a fixed 50 BTC. However, a BTC isn’t a whole solid thing in the code. Each BTC is made up of 100,000,000 smaller pieces, so miners were rewarded with 50 x 100,000,000 ‘pieces’ of BTC. Essentially they are the same value, but when it comes to the code, the difference is important. 

If we take the original reward of 5,000,000,000 (50 x 100,000,000) and write it in binary (Stay with me, yes the binary is important) we get 


Now it’s time for the really interesting and beautiful part of the code:

nSubsidy >>= halvings;

We’re coming up to the fourth halving, using that number we get: 

nSubsidy >>= 4

Or, “shift the numbers 4 places to the right”. This gives us a new binary number:


When we take this binary number and convert it back into a number we get 312,500,000. Dividing this by the 100,000,000 BTC ‘pieces’ we get as a reward, we are left with 3.125 BTC. Exactly the number everyone is talking about.

Why the code matters

The Halving, although only based on a few lines of code, is crucial to the promise of fixed supply for Bitcoin. 

Because there are only 33 digits in total, we know that it is only possible for there to be 33 Halvings. We know what the block height will be, we know we will never pass 21 million BTC in circulation, and we can predict (based on the 10-minute average time to mine a block), with some certainty that we will reach this point in the year 2140. 

A few lines of code have managed to recreate the diminishing returns of mining precious metals like gold. I think that’s pretty amazing. 

Technological Evolution Post-Halving

To wrap up this piece, I wanted to look back at one major development we’ve seen in the network since the last Halving and look ahead to the two I think will be the standouts of the next Halving cycle. 

Looking back: The Taproot Soft Fork and smart contracts 

The Taproot upgrade, activated on the Bitcoin network in November 2021, was one of the most significant enhancements to the network. Taproot marked a significant step forward, introducing enhancements in privacy, scalability, and efficiency. By enabling more complex conditions for transactions while improving their privacy, Taproot laid the groundwork for a more versatile Bitcoin network which we are still exploring. 

One of the most exciting additions was the expansion of capabilities around smart contracts on the Bitcoin network. Smart contracts are self-executing contracts with the terms of the agreement directly written into code. Before Taproot, implementing complex smart contracts on Bitcoin was possible, but clunky and inefficient. Now they are more practical and give another solid potential use case for Bitcoin beyond simple transactions to more complex financial instruments.

Already there’s talk of a Bitcoin Virtual Machine (BitVM) being possible, which would enable the creation of layers on top of the Bitcoin network. This virtual machine would open the door to smart contracts and decentralised applications, allowing it to compete with the offerings of newer blockchains such as Ethereum. 

Looking ahead:


The buzz around rollups suggests they could be the next big thing in enhancing transaction throughput and efficiency. By processing transactions off-chain and settling them on-chain, rollups could significantly reduce congestion and fees, making Bitcoin an even more attractive option for daily transactions. That will help further integrate Bitcoin as a core part of the financial ecosystem and end yet another debate about the ‘value’ it brings to the economy. 

Lightning Network's Mainstream Adoption: 

The Lightning Network has seen remarkable growth since the last Halving, emerging as a mainstream solution for Bitcoin's scalability challenges. Its primary goal is to facilitate instant, low-cost transactions, making Bitcoin a more practical option for everyday use and small payments, often referred to as microtransactions. The most exciting thing is that it’s already working. Since it was launched, we’ve seen a huge increase in lightning transactions, and I believe we’re seeing the start of more widespread adoption and perhaps to a truly functional money used by millions around the world for a wide variety of transactions…


At its core the Halving is code, but what that code represents is more exciting now than it has ever been. We are at the start of a new surge of interest, at a time of adoption and integration, and at a time of significant technological advancement. I can’t wait to see what the Bitcoin community will make of that future. 

Christian Trummer

Christian Trummer