What is Bitcoin?
Bitcoin is a digital currency which has real value and can be traded just like money or any other commodity. However, Bitcoin is much more than that. At its root, Bitcoin is a method of securing transactions between willing parties which requires no third party such as a bank or government.
The first block in the Bitcoin blockchain Is referred to as the Genesis Block. The Genesis Block was mined on Jan 3, 2009 by Satoshi Nakamoto, the pseudonymous author(s) of the original Bitcoin whitepaper. Included in the coinbase transaction of the Genesis Block was the text
The Times 03/Jan/2009 Chancellor on brink of second bailout for banks
This headline was likely included partly as proof that the Genesis Block was mined on or after Jan 3, 2009 but also as a comment on the instability of the traditional banking system.
Interestingly, due to a quirk in the Bitcoin code the 50 BTC reward from the genesis block cannot be spent. It is unclear whether this quirk was intended by Satoshi, and if so, for what reason.
How does Bitcoin work?
- Bitcoin is a digital currency. It is also a method of performing and verifying transactions between parties with no involvement from a third party, or middle man such as a bank or government to act as a trusted intermediary. And it is also a method of securely storing the entire history of Bitcoin transactions and Bitcoin wallet balances in an immutable ledger called the Blockchain.
What is the Blockchain?
- Each block in the Blockchain is essentially a list of transactions. A single block typically contains about 1,000-2,000 transactions, however this can vary. You can look at the details of any block that has ever existed online at Blockchain.info. For example, if you search for block # 513255 which was validated on March 12, 2018, you’ll see that it contained 738 transactions exchanging a total of over 5000 BTC (worth over $45,000,000 USD at the time). Another block, # 514510, validated on March 21, 2018 contained 1,817 transactions.
- Each time a block is verified it is added to the blockchain where it is stored permanently and immutably on every node in the world that is connected to the Bitcoin network.
- The security and integrity of the blockchain requires that many nodes all around the world are all storing the same version of the blockchain and that there is a consensus on which version of the blockchain is correct. If a single computer tries to change their version of the blockchain all the other computers will recognize that version as different from the consensus version and it will be rejected. Since no one entity controls the blockchain, the security and integrity of the blockchain requires that there be a consensus among all participants on how new blocks of transactions will be added to the blockchain. This is where Bitcoin miners come in.
What do Bitcoin miners do?
- Miners are responsible for adding new blocks to the blockchain, and they are incentivised to do so by a reward granted to the miner who adds each block. To add a new block a miner must solve a block’s “proof of work” to prove that they have committed a significant amount of computing resources to earn the right to add a block to the blockchain (more details about the nature of the proof of work below). The purpose of the proof of work is to make it sufficiently difficult for any one entity to produce a valid block. The two main criteria a block must meet to be valid are
1) All the transactions in the block are valid (ie. all the spending wallets have sufficient funds)
2) The block’s proof of work has been completed (solved) successfully.
As long as the proof of work is sufficiently difficult, any miner producing blocks will be sure to include only valid transactions in their block, otherwise all their work would be wasted when the block they submit is eventually discarded by the network for containing invalid transactions.
- What does it mean to “solve” a block? Before we dive into the details of how the guts of Bitcoin mining works, we need to understand a few concepts like Functions, Cryptographic Functions, and Cryptographic Hash Functions.
- In computer programming a function is essentially a computer algorithm which takes an input value, like a number or a series of numbers and letters, and performs some operation on them to produce an output value. For example, the square root function takes a number as an input and outputs another number (example Sqrt(9) = 3.) In this case, 9 is the input and 3 is the output.
- A cryptographic function is a special kind of function which has several properties:
- It is relatively easy to perform the forward calculation of the function, ie given an input, then calculating the output is easy. However, performing the reverse calculation of the function, ie. trying to find a certain input that corresponds to a given output, is virtually impossible.
- Changing the input only slightly will completely change the output; ie. there is no way whatsoever to predict anything about the output value of the function until it has been calculated.
- A cryptographic hash function is a special kind of cryptographic function for which the input is any arbitrarily sized string of numbers and letters and the output number is always the same number of digits. The output of a cryptographic hash function is called the Hash.
- The cryptographic hash function of interest to Bitcoin mining is called SHA-256. The SHA-256 function takes an input of letters and numbers of arbitrary length and always outputs a 256 bit number. A 256 bit number is a long string of 256 zeros and ones.
- You can use this online calculator to calculate the SHA-256 hash of any string of letters and numbers. The output displayed will be in hexadecimal format.
- When new transactions appear on the Bitcoin network they are assembled into a block by concatenating the transaction details one after another into a long string of numbers and letters.
- This string is then set as the input to the SHA-256 Cryptographic hash function. The output of this is called the Merkle Root of the block.
- The Merkle Root along with several other parameters including a counter called the Nonce and a timestamp are assembled to form the Block Header
- The vast majority of what Bitcoin mining hardware does is simply running this block header through the SHA-256 function many times. Each time the Nonce counter is incremented such that the output of the SHA-256 function is different every time.
- The Nonce is a 32 bit number which means it can take on 232 (4.295 x109) different values. While this might seem like a large number, a single modern Bitcoin mining rig can run through the SHA-256 function 232 times in about 0.3ms. Each time running the SHA-256 function the miner needs only to ensure that any one single bit in the block header is changed from the previous attempts (remember that the output of a cryptographic hash function will be completely different if there is only the slightest change to the value of the input). Once the miner has runs through an entire set of 232 values of the nonce they must update some other data in the block to allow another 232 values of the nonce to be used. The coinbase transaction is the first transaction in any block and is the transaction where new Bitcoins are generated and given to the wallet specified by the miner. Along with the wallet address and transaction information there is a field in the coinbase transaction called the Extra Nonce. Once every possible value of the Nonce has been tried the miner must then increment the Extra Nonce. Since incrementing the Extra Nonce changes one of the transactions the Merkle Root must be recalculated which generates a completely new block header which allows the miner to run through all the 232 values of Nonce again.
- The result of running each block header through the SHA-256 function is a 256 bit hash, which is just a 256 bit number (ie. 256 zeros and ones).
- The goal of the Bitcoin miner is to be the first to find a particular block header input which results in a 256 bit hash that is below a certain value called the Target.
- One way to think about this is that the Bitcoin miner is essentially rolling a many sided dice, each time hoping that the value on the dice will be below the target value.
- Some more info about the target.
- The total number of possible output values of the SHA-256 function is 2256 = 1.158 x1077. Thinking back to our dice rolling analogy, this means the Bitcoin miner is effectively rolling a dice with 1.158 x1077 sides, each time hoping their roll is below the target value.
- The highest possible value of the target is 2224 = 2.696x1067. This was the value of the target during the early stages of Bitcoin mining back in 2009.
- As time goes on the target generally decreases making it more difficult for miners to find a hash below the target. More about the target and why it decreases below.
- The value of the target is related to the present mining difficulty. The Difficulty is a measure of the processing power of the entire Bitcoin network. As the processing power of the Bitcoin network grows, the difficulty is raised (ie the target is lowered) to make it more difficult to mine blocks.
- Once a miner finds a hash below the target, that block is added to the blockchain. The coinbase transaction in that block will direct the block reward to the successful miner’s wallet. And the process starts over again for the next block of transactions.
How much Bitcoin does a miner receive?
- The Bitcoin algorithm is setup such that one block will be solved on average once every 10 minutes. As the Bitcoin network grows, and all the Bitcoin miners collectively perform more hashes per second, the value of the target is automatically lowered (ie. The difficulty is raised) to maintain the same average time of 10 minutes per block.
- The precise relationship between the difficulty and the target is defined by the equation
- In 2009 when the first Bitcoin block was mined the value of the Difficulty was 1, and the value of the original target was 2224. In 2009, each time a miner calculated a 256 bit hash, which is just a number between 0 and 2256 (1.158 x1077), they would be hoping for that number to be below 2224 (2.696x1067). We can calculate the probability that any one hash would be below the target by thinking again about the dice rolling analogy. Consider a conventional 6 sided dice and choose the number 3 as our target, so that to be successful we must roll either 1 or 2. The probability of a successful roll is calculated as
The inverse of that probability would tell us the average number of rolls needed to achieve a successful roll, in this case, 3.
- Back to Bitcoin mining, remember that each time a Bitcoin miner calculates a hash they are essentially rolling a dice with 2256 (1.158 x1077) sides. In 2009 they were hoping they would roll something below 2224 (2.696x1067). The probability of a successful roll of the dice can be calculated as
- We can invert this probability of any one hash being below the target to see that in 2009 it took on average
hashes to find a hash below the target. As the total processing power of the Bitcoin network grows and the target shrinks, the expected number of hashes required to find a hash below the target grows. The general equation for this expected number of hashes is
- We can re-introduce the equation above which related the target to the difficulty to express this expected number of hashes in terms of the difficulty.
- This number is very important to the Bitcoin miner. It allows them to calculate how much Bitcoin they will mine each day on average. The equation for a miner’s expected daily reward is (assuming they have a total hash rate H)
- Breaking down this equation: Since each block will take on average 10 minutes to be solved the total number of hashes one miner will attempt on each block is their hash rate times 600 seconds or H x 600seconds. The Expected number of hashes required to solve each block is 232 x Difficulty so the value in the fraction (
H x 600seconds232 x Difficulty
- This equation gives an approximation of the miners income. In reality the income of a Bitcoin mine will be somewhat different because there are also transaction fees that accompany each transaction. While these transaction fees can’t be predicted as accurately as the block reward, we can calculate the historical income based on the history of transaction fees. You can use our interactive calculator to calculate the historic income of a Bitcoin mine including the transaction fees.