Skip to main content

How are Bitcoins mined?

The image below is an example of the screen that appears when your Bitcoins have been sent. There is some text in roughly red marked area in that image saying “0.00022368 BTC" as a transaction fee to miners.

Image result for bitcoin transaction

In order to understand how Bitcoins are mined and why you should pay that transaction fee to miners, read this whole article!

Whenever you start your transaction, there will be a transaction request (i.e. digitally signed message which is carrying your bitcoins) created and it is sent to the miners. Now, I have created a scenario in order to explain the mining process! The words in bold text will have a special significance and will help us to corelate with the actual Bitcoin terminologies later on.

Imagine your transaction request as a letter ( or a courier). Miners collect your letter and put them in a machine. Just like yours’, there might be thousands of such letters from people all around the world! They collect all these and put them in the same machine! They also put some other stuff in this machine. Now, what does this machine do? This machine is designed in such a way that it puts all the letters and other stuff in a box and packs it. After packing the box, the machine sticks a label on it. This label contains a unique serial number which represents the items which are contained in that box. So, we can say that this machine’s work is to pack the box and give a serial number to it!
Now the scenario is looking something like this!

Now, the weight of this box is measured. Let us assume that there is some relation between the serial number given to the box and it’s weight. We (You and me) will create a rule: If this weight is less than a certain limit (for example, the limit can be 2 Kgs), then and only then this box is allowed to be kept in the godown (warehouse). If it exceeds the limit, then a small change is made to the contents of the box so as to keep the weight of the box less than the limit and then it is allowed to enter the godown.

Basically, we have these words from our scenario which are in bold: Letters, machine, other stuff, box, serial number, weight, godown (or warehouse), limit, small change.
In reality (i.e. in actual bitcoin mining), the above same process is taking place digitally! Now let’s try to connect the above scenario with the reality! Now I will replace some of the words mentioned above. In the Bitcoin mining terminology,
  • letter is your transaction request.
  • The packing machine is SHA-256 (SHA-256 is an algorithm)
  • The box is called as a block
  • serial number and weight refer to hash (not the Twitter’s hash, of course).
Actual explanation:
  • Hash is a string of random numbers and letters!
  • SHA-256 is an algorithm which is used to create this hash! You can add any number of data and it combines all those data and creates a unique Hash! SHA stands for ‘Secure Hash Algorithm”.

You can convert anything into a 256-bit hash (i.e., the input data can be an audio file, video file, a simple text or anything). For example, I have generated a 256-bit hash for the text “ReadBit” which comes out to be “57f062988ce63e000c7728e1cdda48637c7c205a76814cca662ad83d8fa2ef3a”.
In the above scenario, I was referring Block as “box”. According to Wikipedia definition, ”Blocks are the files in which Transaction data is permanently recorded”. This is what I explained in simple words: Letters (transaction data) are put inside the box (block). Now, are you getting the point that why we have created the above scenario? Yes? Good! Read on…
Hash of a Block (“serial number of the box”) in Bitcoin mining looks something like this: “00000000000000000230b7a46ca4f44b17e7e20da5630438269b2a9f94a567d9”
In the explanation at the initial stage, I have also mentioned that there are some “other” stuff going into the “box”. Let’s see what these “other” stuffs are! The “other” things include:
  • The hash of previous block.
What is this ‘hash of previous block’? I will now connect this to our created scenario and explain. In the warehouse image shown above, there are many boxes kept one above the other. Now, imagine that the serial number of the previous box (i.e., the box which was previously packed by the machine) is kept inside the present box which is now being packed by the machine! This method is used because whenever the miners will open any box from the warehouse, they should automatically come to know the box which comes before the currently opened box! Also it will be appropriate to mention here that, in Bitcoin terminology, the warehouse (of our scenario) is called “Block chain”. A block chain (usually written as a single word as “Blockchain”) is a transaction database i.e., it is a collection of all the transactions (which are inside the blocks). It is a storage of all the blocks!
  • In the “other” things (apart from hash of previous block), the block also contains a timestamp.
  • The block also contains Nonce!
To relate with our scenario, this nonce is the “small change” made to the weight of the box so that it can be less than the “limit”. So, nonce is the “small change”.
Now, this part is the climax to our journey! Here you will come to know the purpose of doing all the above processes.

BITCOIN MINING: The Game of luck

Here is a ‘Game’ that all miners play every second! Now, as you read the paragraph below, you start remembering the scenario that we created earlier.
The miners put your transaction data and everything mentioned earlier, in the block and they will hash it! There is something called as a target in Bitcoin terminology (and in our scenario above, it was called as “limit”). Target is also a 256-bit string which all of the Bitcoin software and the miners in the Bitcoin network share with each other! Target is always a constant and it is changed only at a certain condition.

Now the rule of this game is, if the hash (weight of box) obtained for the block (box) is less than (or equal to) this target (limit), then and only then the block is added in the block chain (warehouse) and the miner who has done this first will be rewarded 12.5 new Bitcoins!! This is how new bitcoins are created (mined)!!!! It is like a competition between the miners! All Bitcoin miners out there are constantly racing each other!

But, wait. It not that easy! Getting the hash value less than the target is very difficult task. If the hash value is not less than the target, then miners will change the value of nonce and will hope that this time they will get the hash less than the target and they again start the hashing process from the beginning! Here, nonce is a 32-bit random number. The actual work of every miner is to find an appropriate nonce which will make the hash less than the target. So, the nonce is varied millions of times per second and this computation process requires high amount of computer power.

Every time the nonce is changed, a new hash is formed. This hash is compared with the target. If hash is more than the target, then again the nonce is changed and a new hash is formed. Again the comparison is done with the target and if the hash is now less than target or equal to target, then the miner will get 12.5 Bitcoins as reward! After this, the block (which has won those 12.5 bitcoins for the miner) is finally placed in the block chain and the transactions which were included in that block will get confirmed and sent to their respective Bitcoin addresses. As the miner (who has won) has spent his time for putting the block in block chain and confirming your transactions, he will charge you a small amount of transaction fee.

The websites which say, ”Bitcoin mining involves solving mathematical problems” are actually talking about the mathematical operation involved in creating the hash, changing the nonce and comparing it with the target.
So, now you know what Blockchain is and how Bitcoins are mined!

Thanks for reading.

Comments

Popular posts from this blog

My-Cloud-IDE - a SaaS built using Docker

I always wanted to know about how services like Codenvy  and Heroku  internally worked. The only way to understand that was to build a similar project. The main component of this project is Docker. Docker  Docker is a software that performs OS-level virtualisation and is developed for Linux. More information about it can be found here . About My-Cloud-IDE: My-Cloud-IDE is a proof-of-concept for a Software as a Service (SaaS). It   can be used to perform software development on cloud without worrying about resolving software dependencies, software installations etc. The user gets a fully functional IDE in his/her browser after registration. Each user has his/her own isolated software environment because My-Cloud-IDE uses Docker to perform OS-level virtualisation in the backend. Technical Details I divided the project into two modules. One module was for 'management' purpose. This includes user interfaces, user management and preparing some files that are to be lo

How did I setup a Rasberry Pi 3 without any peripherals

I am an absolute beginner in this Raspberry Pi (I'll be using "RPi" for short) world and this post shows how I started up the RPi without using external keyboard or mouse (for RPi) and still managed to get a graphical desktop environment of Raspbian on my Debian workstation (and controlled my RPi remotely). Step 1: I downloaded 'Raspbian Stretch with Desktop' ( here ). I got a ZIP file. I unzipped it and ended up with a .img which was roughly 4.6 GB. Step 2: Now, to create a bootable media (a memory card perhaps) by copying the .img file onto it, I used dd command. sudo dd if=<path to img> of=/dev/<sdb,sdc..> Be particularly careful with using dd command. You can mess up a lot of things. Using dd command on your memory card will wipe out all contents in it. Using dd command on your hard disk, umm.. not a good idea. To know the disk path of your memory card, use sudo fdisk -l  (el in small caps) . Your hard disk will probably be /dev/sda. You

My Android notes - 2

Note: a few of the content of this post is taken from this StackOverflow answer. Context Context is a very important concept and you will be using it throughout your application. It is an abstract Java class defined as public abstract class Context extends Object by the Android system. What is Context? Context represents a handle to get environment data . Context class itself is declared as abstract, whose implementation is provided by the android OS. Context is like remote of a TV & channels in the television are resources, services, etc. Just keep in mind that Context contains the current state of the application/object. It lets newly-created objects understand what has been going on. How to get the Context? Ways to get context : this (inside a Service, Activity or any other class that directly or indirectly extends Context ) getApplicationContext() getContext() getBaseContext() What can you do with it ? Loading resource. this.getResources() in