The current trend is to dumb down the mechanics of Bitcoin behind multiple levels of abstraction. Here we explore how it actually works without generalizing too much. What exactly is the blockchain? You've heard it countless times; blockchain! Not only is the term ubiquitous, so is the general misunderstanding behind it. And that leaves the door open towards spurious imagination. Blockchain is a technology that, as the name says, "blocks" the "chain" of fake news. It most definitely is not that! But this was actually said on national television by a . prominent Portuguese intellectual It's a continuously growing list of records that is open, distributed and impervious to the change of data. Blockchain is a unique kind of database. Let's let that sink in. Open - anyone in the world can query it. Distributed - approximately participate in its quorum. 100.000 nodes Impervious - once data is written, no single party can change it. So we've established that it's a growing list of records. And it's generally at this stage that you'll hear that cryptography glues it together. How are the blocks tied together? For that, we must explore the concept of hashing. A hashing function maps data of variable size to a fixed-size value. The one Bitcoin uses is called . You can explore how it works by playing with the following text boxes. sha256 Unfortunately, I can’t insert JavaScript on Hacker News, so this bit is only available on . Waste of Server original article Just change the string "abc" to whatever you want, and you'll see that given tiny variations, the hash changes dramatically. Bitcoin established, by design, that we would be trying to find hashes with a pre-determined number of zeros in the beginning. Use the above and try with , you'll get a hash that starts with a . Now try it with you'll have zeros at start. You can and see that the initial difficulty was set to 8 zeros. abc26 0 abc93803 0000 browse the first block ever mined As of now, is set to 19(!) zeros, but that changes depending on the amount of hashing power currently available. Bitcoin sets the difficulty (starting number of zeros) to have blocks being mined approximately every 10 minutes. But it's a game of chance, a block may take from just a few seconds to much longer. From the image below, you can see that it took 21 minutes, to mine block 673088. the current difficulty On the early stages of the network, when things were starting and hashing power was scarce, it took almost a full day to mine a single block (block to ). But since Bitcoin took off, the longest it took, was just a bit over 1 hour and 39 minutes from block to . Mind you, the more hashing power there is, the less likely it is for events like these to spur. 168 169 152218 152219 Exactly what is hashed, and what's in a block? A block header carries the following information: miner software version timestamp of the block sha256 of the merkle tree root sha256 of the previous block a nounce (random data to try and get x number of zeros) a target (number of zeros to find) We'll get to the merkle tree root in an instance but, as you can see, given these 6 items the miner starts iterating the nounce to try and find a hash that is less (has more zeros) than the target. As soon as it finds one, the nouce that solves the problem is saved to the block and the client publishes it. The miner that publishes the block first is rewarded with both the transaction fees and new Bitcoin that's minted out of thin air. What is a Merkle Tree? It's a way to verify the integrity of large data structures. In the case of Bitcoin just get all the transactions you are trying to validate and hash them two by two. Then get those hashes and also hash them two by two. Proceed like this until you have a single final hash. That is called the root hash and uniquely represents all the transactions that are below it. Say we have 4 transactions represented by letters. We join them two by two and hash them in sequential order. Then we hash the hashes. Transactions (leaves): A + B + C + D Branches Level 1: sha256(A+B) = BrnchAB Branches Level 1: sha256(C+D) = BrnchCD Merkle Root: sha256(BrnchAB + BrnchCD) = BrnchABCD As there are only 4 transactions, there's no need to get to Level 2 Branches How do you get BTCs from mining? Before starting to try finding a solution to the block, the miner simply adds a new transaction to their block that gives them X amount of BTC. This is called a and its value depends on the block being mined. generation transaction The block reward started at 50 BTC and halves every 210.000 blocks. As blocks are mined more or less every 10 minutes, you can pretty much guess when the next halving will happen. Though it has happened to be offset by months! On 2021 we're on which gives 6.25 BTC per block. halving3 HALVING DATE BLOCK BLOCK REWARD MINED IN PERIOD % MINED launch 3-Jan-2009 0 50 10,500,000 50 halving 1 28-Nov-2012 210,000 25 5,250,000 75 halving 2 9-Jul-2016 420,000 12.5 2,625,000 87.5 halving 3 11-May-2020 630,000 6.25 1,312,500 93.75 halving 4 On 2024 ? 840,000 3.125 656,250 96.88 halving 5 On 2028 ? 1,050,000 1.5625 328,125 98.44 halving 6 On 2032 ? 1,260,000 0.78125 164,062 99.22 halving 7 On 2036 ? 1,470,000 0.390625 82,031 99.61 As you can grasp from this post, the network works on the basis of done by the miners. But, being de-centralized and open, anyone can implement a miner. Proof of Work (PoS) Remember above when we said that the Block Reward paid to the miner is added by the miner itself? Well, there is at least one documented case where the miner software wasn't working as expected and successfully mined a block without transactions (no fees) and without adding it's own address(!) no block reward! You can check this . half a million bug right here, block 501727 If you liked this article, feel free to drop by wasteofserver.com where you will find similar stuff. You can try , or maybe the ? Is Bitcoin a store of value? Hitchhiker’s guide to NFTs Also published . here