Bitcoin Mining At a Low Level

Sohum Padhye
Coinmonks
11 min readOct 22, 2021

--

“Everything will be tokenized and connected by a blockchain one day.” ~ Fred Ehrsam, Paradigm

I’ve seen several Bitcoin articles talk about Bitcoin mining at a high level, but rarely have I seen one at a low level. This article will take you through how everything in Bitcoin mining works — from, “Why does it take 10 minutes to mine a block?” — to the hardware you’ll need to get started.

Before you start reading, you should have a solid understanding of blockchain, because I use terminology and concepts relating to it in this article.

Here are each of the topics:

  • The Mining Target
  • The Mempool
  • Mining Equipment
  • Conclusion

The Mining Target

A game of Limbo to symbolize the mining target

Before I get into this section, I want you to quickly think about this question: “Why does it take 10 minutes for a block to get mined in Bitcoin?” If all your answer is, goes like, “Because they have to solve a very complicated cryptographic hash puzzle,” then you probably don’t know why.

Why do people mine? What is mining? How do people mine? In this section, I will explain what the mining target is, so you can elaborate on those “cryptographic hash puzzles.”

What is a Block Made of?

A block is made out of the following fields:

  • The block index in the chain
  • The data (in a Bitcoin’s case, transactions)
  • The previous hash, which is the hash of the previous block.
  • The nonce
  • The timestamp
  • The hash of the block

The first three items in the list above are items that cannot be changed by anyone, even when mining. The block index cannot be changed, because it is the block’s place in the chain. The data cannot be changed, because it would be seen as tampering with the block. The previous hash cannot be changed because the nodes in the network would say, “Hey, this previous hash is not the hash of the previous block,” and change it back. Lastly, the hash is simply the culmination of all other fields.

One thing that I would quickly like to note here is that while all blockchains may hash the data of each block, they don’t all use the same hashing algorithms. For example, the hashing algorithm Bitcoin uses, SHA-256 — one made by the National Security Agency (NSA) — is a different one used by Ethereum, which uses the Keccak-256 hashing algorithm. Also, note that hashing algorithms are different from encryption algorithms. You can see all the requirements for an algorithm to be observed as a hashing algorithm rather than an encryption method here.

Leading Zeroes

As of October 2021, the number of the least leading zeroes required for a block to be added to the blockchain is 18. Now, what does this mean?

The “256” in SHA-256 stands for 256 bits. This means that when it is converted to hexadecimal, 64 characters appear. Consider a random string of 256 digits in base two. Then, let’s say when that is converted to a hexadecimal number, it gives this output: 3F79BB7B435B05321651DAEFD374CDC681DC06FAA65E374E38337B88CA046DEA. (By the way, I only typed “e” for this result to come.)

Each hexadecimal digit is made up of four binary digits. Now, when I say leading zeroes, I mean zeroes before the rest of the number comes in. If I have 6 leading zeroes, the hash would be something like 000000xxx…xxx (58 x’s). The reason this concept is so important is that it directly relates to the mining target, which I will get into. However, for now, I want you to think about this:

In a hexadecimal string, each digit can be 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, or F. Therefore, the total amount of possible combinations you can get with a 64-digit, hexadecimal number, is 16 to the exponent 64. That equates to about 1.1 * 10^77. While this may be very surprising, let me show you something else. If you had 18 leading zeroes, you would be able to make 16^46 combinations. That’s about 2.5 * 10^55. Also huge, right?

The Leading Zeroes Stats

Compared to our first number, no. No, not at all. To quickly put into perspective what 2.5 * 10^55 is compared to 1.1 * 10^77 is, the probability of getting a randomly chosen 64-digit hexadecimal number with 18 leading zeroes is approximately: (You ready?)

2.1 * 10^(-22) out of 1.

Let me expand that, real quick. One moment.

0.000000000000000000021%.

Yeah.

You have a much higher chance of winning the lottery than randomly picking a hexadecimal number with 18 leading zeroes. How much higher? Oh, you know, only about a trillion times as much.

The Mining Target

A mining target is essentially a number that says, “Hey! Miners! You gotta get a hash below me or you won’t be able to add your block to the chain!” The mining target was essentially made to give a challenge to miners who want to make money.

Take an example of a mining target being: 000000000000000000000FFFFFFxxx…xxx (40 x’s)

So this hash generated by a hashing algorithm that seems almost random must be below that. But the chance of getting a hash smaller than that number is extremely low like we saw before. So, what is the solution?

The Nonce

I would like to quickly make a note of the avalanche effect here. The avalanche effect is where even if you make a seemingly negligible or unnotable change, the hash will change dramatically or absolutely. Even if you input just a space, there is still a hash that doesn’t just consist of zeroes. Here it is, in case you were wondering: 36A9E7F1C95B82FFB99743E0C5C4CE95D83C9A430AAC59F84EF3CBFAB6145068

Satoshi Nakamoto was very smart. He/she predicted that the price of Bitcoin would rise, and there would need to be greater challenges for miners when advancements in technology were made. This person (Or group! Nobody knows who Satoshi Nakamoto is) foresaw that people would eventually give up mining, because of the incredibly low chances that they would strike a jackpot. People wouldn’t even make transactions because of how long it would take to get through to the other person.

Because of this, a field called the nonce was made. This is a 32-bit field, so it can only go up to 4294967296. I know. These big numbers make me feel like 4 billion is small (which it is, compared to the other monsters). Remember how I said at the very beginning that the hash was calculated based on every other field? This was one of them. The Bitcoin protocol makes it so that when somebody is mining, they iterate through the nonces until they have a digit that falls within the mining target. Because of the avalanche effect, they will end up with a different nonce each time (unless somehow the hashes become the same, which is even more unlikely than randomly choosing an 18-leading-zeroes number).

So now, if we multiply 4294967296 by 0.000000000000000000021% we get…

Still a pretty small number.

0.00000000009%

So now, even if you go through all the 4 billion nonces in one second, there’s still a very small chance that you’ll get a hash that has 18 leading zeroes.

However, there’s still one field in a block that I have not yet talked about. It is the one that will never be trumped by leading zeroes. Please welcome the last field:

The Timestamp

The timestamp in a block says when that block is created. Applying the avalanche effect here, with each second that changes, the entire hash changes and a new opportunity to get the required number of leading zeroes arises.

But what format is used to post the timestamp? Is it ‘yyyy-mm-dd,’ ‘yyyy-dd-mm,’ or ‘yy-mm-dd’? You’ll be surprised to hear that it’s none of them. Instead, there is something called the Unix time. The Unix time is the number of seconds that have passed since the Unix epoch, which was on 00:00:00, January 1, 1970. The Unix time is something that will never reset and doesn’t need any formatting or parsing for a program to make sense of it. The program will just have to check what the number is to make sure everything in the blockchain is in check.

Now that we’ve covered all fields, I’d like to quickly tell you again that Satoshi Nakamoto was a very smart person (I’m going to refer to Satoshi Nakamoto as a single person for the explanation’s sake). He/she understood that eventually, technology would allow for people to iterate through those 4 billion nonces in less than a second, and that’s what happening right now. As you’re reading this article, somebody is mining a block. Somebody is continuously going through those 4 billion nonces, and that timestamp keeps updating each time he or she fails to find the golden hash.

Maybe there are some casual miners who can only iterate through 150 MH/s (mega-hashes or million hashes per second). But for the hardcore miners — I’m talking about the ones with the huge warehouses — they can get a couple of TH/s (tera-hashes or trillion hashes per second)!

The point or thought that I’m trying to get across here is: “What are the miners doing with all their extra time as they mine?”

The Mempool

Say you’re a good miner. You average about 10 GH/s (giga-hashes or billion hashes per second). So, it takes you about 0.43 seconds on average to go through all the nonce iterations. What do you do with your remaining 0.57 seconds? Luckily, Bitcoin’s protocol already has a built-in function to switch the data, so now you can have another go at the 4 billion nonces.

This section explains what the mempool is, how it works, how miners are associating it with the blocks they create, and lastly, to answer our previous question, what they do with all that extra time.

What is it?

The mempool is a distributed list of transactions that haven’t gone through to the intended recipient yet. These are the transactions that miners use to add to their blocks. Each block has about 1000 transactions stored inside.

Each transaction has some fees attached to it. That means that if the miner mines a block, they get the fees attached to each transaction in the block along with the mining reward (Currently 6.25 BTC). So, Bitcoin’s protocol automatically selects the highest fees to go into the block.

Getting back to our last scenario, where you’re a hardcore miner — in those 0.57 seconds, a lot can be done. The Bitcoin protocol senses when a miner goes through all 4 billion nonces in less than a second (or before the timestamp updates).

In this block, what can you switch now?

  1. You can’t switch the block index.
  2. You can’t switch the previous hash.
  3. You can’t switch the timestamp (until it updates, of course).
  4. You can’t switch the nonce (yet!).
  5. You can switch the transactions listed in the data.

After it senses that the last nonce was passed in the second, it then switches out the lowest value transaction for the next highest value transaction in the mempool.

A little bit about fees

Money for the miners! Money for everyone! (No, just for the miners)

Let’s say you wanted to send some Bitcoin to your friend — maybe 0.003 BTC. The miners who want to make money are going to choose the transactions with the highest fees. So, you should take some fees to accompany the transaction. If your payment has no fees, then the miners will never choose them (if your transaction doesn’t go through in 72 hours, the Bitcoin you sent is returned to you).

What I’m trying to say is, look from the perspective of the miners. You may not want to give them any money, but it’s not a matter of what you want in the end.

Another quick thing I’d like to note is that the idea of stocks also comes into play here. Now, I’m no expert at investing, but I know that when the demand goes up, usually the price follows.

When more people want to send money at the same time to someone else, they recognize that other people are also sending it, so they need to increase their fees because they want their transaction to go first. In the end, it all comes down to who’s the most desperate for their transaction.

Mining Equipment

Now that you have a better understanding of Bitcoin mining (I hope!), here are some tips on how you can get started.

CPUs vs GPUs vs ASICs

CPUs are Central Processing Units. They can be and are used for almost everything that goes on in your computer. While CPUs can do everything, that doesn’t mean they’re phenomenal at it. Most CPUs can achieve about 1 to 2 MH/s.

After that, we have GPUs. Graphics Processing Units are much better at certain things but have a much more limited skill set compared to CPUs. You use GPUs for running your code, playing games, and more. You have GPUs in your computer, but you can purchase much better ones in packs online if you want to get into mining crypto. Most GPUs can crunch up to about 1 GH/s.

Lastly, we have the ASICs. ASICs were made specifically for mining Bitcoin and other cryptocurrencies that use SHA-256. Their circuits were physically made to calculate the SHA-256 hash so that there would be no memory that would have to be accessed.

Mining pools

Mining pools are places where you can combine your hashing power with other members of the pool to create and mine blocks. You get awarded for how much hashing power you contribute to the team.

Conclusion

In conclusion, Bitcoin mining has a lot to it. There are several aspects to it and how it works. I’ve enjoyed writing about this exciting topic and I hope you can take something away from it. Lastly, make sure to keep an eye out for my October newsletter on my Substack!

Join Coinmonks Telegram Channel and Youtube Channel learn about crypto trading and investing

Also Read

--

--