{"id":2838,"date":"2024-10-22T10:34:19","date_gmt":"2024-10-22T10:34:19","guid":{"rendered":"https:\/\/apex-aiexperts.com\/?p=2838"},"modified":"2024-10-22T10:34:19","modified_gmt":"2024-10-22T10:34:19","slug":"how-bitcoin-mining-works","status":"publish","type":"post","link":"https:\/\/apex-aiexperts.com\/es\/how-bitcoin-mining-works\/","title":{"rendered":"C\u00f3mo funciona la miner\u00eda de Bitcoin"},"content":{"rendered":"<p class=\"wp-block-paragraph\">How does Bitcoin mining work?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the&nbsp;<a href=\"https:\/\/tradecenterfx.com\/beginners-guide-to-bitcoin-mining\/how-bitcoin-mining-works\/#\" target=\"_blank\" rel=\"noreferrer noopener\">lecci\u00f3n anterior<\/a>, you learned what a Bitcoin&nbsp;<strong>miner<\/strong>&nbsp;is, how it stores fresh transactions in its&nbsp;<strong>memory pool<\/strong>, and then starts the \u201cmining\u201d process by creating a&nbsp;<strong>candidate block<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If what I just wrote sounds like a foreign language to you, I strongly recommend you start with the&nbsp;<a href=\"https:\/\/tradecenterfx.com\/beginners-guide-to-bitcoin-mining\/how-bitcoin-mining-works\/#\" target=\"_blank\" rel=\"noopener\">first lesson of my Beginner\u2019s Guide to Bitcoin Mining<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you\u2019re still with me, let\u2019s take a closer look at the candidate block\u2026<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Just like you can be separated into two basic parts with a head and a body, a candidate block can be broken down into two parts:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Block\u00a0<em>header<\/em><\/strong>\u00a0(yellow area)<\/li>\n\n\n\n<li><strong>Block\u00a0<em>body<\/em><\/strong>\u00a0(gray area)<br><img fetchpriority=\"high\" decoding=\"async\" srcset=\"https:\/\/bpcdn.co\/images\/2022\/02\/18154614\/bitcoin-candidate-block-two-parts.png 960w, https:\/\/bpcdn.co\/images\/2022\/02\/18154614\/bitcoin-candidate-block-two-parts-768x432.png 768w, https:\/\/bpcdn.co\/images\/2022\/02\/18154614\/bitcoin-candidate-block-two-parts-360x203.png 360w, https:\/\/bpcdn.co\/images\/2022\/02\/18154614\/bitcoin-candidate-block-two-parts-780x439.png 780w\" width=\"960\" height=\"540\" src=\"https:\/\/bpcdn.co\/images\/2022\/02\/18154614\/bitcoin-candidate-block-two-parts.png\" alt=\"Block Header and Body\"><\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">If we look closer at a candidate block, it actually does NOT just contain transactions.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/bpcdn.co\/images\/2022\/02\/18153156\/bitcoin-candidate-block-anatomy.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/bpcdn.co\/images\/2022\/02\/18153156\/bitcoin-candidate-block-anatomy.png\" alt=\"Candidate Block Anatomy\" class=\"wp-image-219463\"\/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">When a miner creates a candidate block, it includes a \u201c<strong>block header<\/strong>\u201d (yellow area).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The \u201cbody\u201d of the block (gray area)&nbsp;<em>holds<\/em>&nbsp;the transactions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Aside from a candidate block containing a bunch of transactions, it also contains some metadata that provides a \u201csummary\u201d of the block.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Metadata<\/strong>&nbsp;is just data that provide information about other data. In this case, the metadata provides information about the block itself. This information is known as the \u201cblock header\u201d.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Inside the&nbsp;<strong>block header<\/strong>, there are several pieces of data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For the purpose of this lesson, I\u2019m going to simplify what\u2019s inside the block header.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Timestamp<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The first piece of data inside the Block Header is the \u201c<strong>Timestamp<\/strong>\u201d.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The timestamp indicates when the block was created.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/bpcdn.co\/images\/2022\/02\/18155417\/bitcoin-candidate-block-timestamp.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/bpcdn.co\/images\/2022\/02\/18155417\/bitcoin-candidate-block-timestamp.png\" alt=\"Timestamp\" class=\"wp-image-219467\"\/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Previous Block Hash<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The next piece of data is called the \u201cPrevious Block\u201d or more specifically, the \u201c<strong>Previous Block Hash<\/strong>\u201d.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The Previous Block Hash is the&nbsp;<strong>block hash of the prior block in the blockchain<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/bpcdn.co\/images\/2022\/02\/18155532\/bitcoin-candidate-block-previous-block-hash.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/bpcdn.co\/images\/2022\/02\/18155532\/bitcoin-candidate-block-previous-block-hash.png\" alt=\"Previous Block Hash\" class=\"wp-image-219468\"\/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In order to understand what this means, we need to take a look at the file.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/bpcdn.co\/images\/2022\/02\/18155745\/look-inside-blockcahin.png\" alt=\"Look inside blockchain\" class=\"wp-image-219469\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Now that we\u2019re looking inside the file, we can see that the data is structured in a specific way.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/bpcdn.co\/images\/2022\/02\/18160210\/blockchain-structure.png\" alt=\"Look inside the file and see blockchainstructure\" class=\"wp-image-219470\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s visualize this as the&nbsp;<strong>blockchain.<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The candidate block that the miner has created has to be added&nbsp;<strong>on top of the most recent block<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/bpcdn.co\/images\/2022\/02\/18160451\/add-block-top-of-blockchain.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/bpcdn.co\/images\/2022\/02\/18160451\/add-block-top-of-blockchain.png\" alt=\"Block must bee added on top of the most recent block\" class=\"wp-image-219471\"\/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s say the most recent block is the one colored in&nbsp;<strong>blue<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/bpcdn.co\/images\/2022\/02\/18160656\/most-recent-block-in-blockchain.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/bpcdn.co\/images\/2022\/02\/18160656\/most-recent-block-in-blockchain.png\" alt=\"Most recent block in blockchain\" class=\"wp-image-219472\"\/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Desde el&nbsp;<strong>Block Hash<\/strong>&nbsp;of block colored in&nbsp;<strong>blue&nbsp;<\/strong>is the most recent block in the file (the \u201cblockchain\u201d), then that\u2019s the block that the miner wants to build on top of.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of the Block Hash as like a<strong>&nbsp;custom-generated ID number<\/strong>&nbsp;for a block.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So what the miner will do is add this as the \u201c<strong>Previous Block Hash<\/strong>\u201d in the&nbsp;<strong>Block Header of its OWN candidate block<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/bpcdn.co\/images\/2022\/02\/18161013\/block-hash-addedas-previousl-block-hash.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/bpcdn.co\/images\/2022\/02\/18161013\/block-hash-addedas-previousl-block-hash.png\" alt=\"Block hash added as Previous Block Hash of Candidate Block\" class=\"wp-image-219473\"\/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u201cTransaction Summary\u201d Hash<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The next piece of data is what I\u2019ll call the&nbsp;<strong>\u201cTransaction Summary\u201d Hash.<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As the name suggests, it provides a \u201csummary\u201d of all the transactions in the block expressed as a string of characters.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Without going into specifics, what happens is that all the transactions in the block (highlighted in&nbsp;<strong>red<\/strong>) are put into a hash function and hashed in a certain order and you end up with a&nbsp;<strong>single hash<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/bpcdn.co\/images\/2022\/02\/18162406\/merkle-root-hash-function.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/bpcdn.co\/images\/2022\/02\/18162406\/merkle-root-hash-function.png\" alt=\"Merkle Root\" class=\"wp-image-219479\"\/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>This hash is what is used as the \u201cTransaction Summary\u201d Hash.<\/strong><a href=\"https:\/\/bpcdn.co\/images\/2022\/02\/18162302\/merkle-root-hash-1.png\" rel=\"noreferrer noopener\" target=\"_blank\"><\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">What this hash provides is a unique \u201c<strong>fingerprint<\/strong>\u201d based on all the transactions included in a block.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This helps to ensure that transactions&nbsp;<strong>haven\u2019t been tampered with<\/strong>.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">This \u201cTransaction Summary\u201d Hash is actually known as the \u201c<strong>Merkle Root<\/strong>\u201c.\u00a0<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">Remember,&nbsp;<strong>one tiny change in data will totally change the hash<\/strong>. This means if someone were to try to alter any transaction in the block in the future, it would cause the \u201cTransaction Summary\u201d Hash to change and be totally different from the original value that\u2019s in the Block Header.<a href=\"https:\/\/bpcdn.co\/images\/2022\/02\/18162457\/transaction-hash-summary-as-fingerprint.png\" rel=\"noreferrer noopener\" target=\"_blank\"><\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Basically, changing the transaction would create a totally different \u201cfingerprint\u201d and wouldn\u2019t match the original \u201cfingerprint\u201d.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This change would let everyone instantly know that a transaction(s) was tampered with.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Block Hash<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">So far, the Block Header contains three pieces of data:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Timestamp<\/li>\n\n\n\n<li>Previous Block Hash<\/li>\n\n\n\n<li>\u201cTransaction Summary\u201d Hash<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">The next step then is to put this Block Header data into a hash function.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This will produce a random number called the \u201c<strong>Block Hash<\/strong>\u201d.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(Although a more accurate name would be the \u201cBlock&nbsp;<em>Header<\/em>&nbsp;Hash\u201d since it\u2019s the hash of just the block header, not the entire block.)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Just like the Previous Block Hash mentioned earlier, think of the Block Hash as a custom-generated ID number that will be assigned to the candidate block.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/bpcdn.co\/images\/2022\/02\/18163634\/run-block-header-through-hash-function.png\" rel=\"noreferrer noopener\" target=\"_blank\"><\/a><br>Why does the miner do this?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In order for the miner to get its block added to the blockchain, it must<strong>&nbsp;find a Block Hash that meets a certain requirement<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If it can NOT meet this requirement, then the block will NOT be considered valid and the miner can\u2019t add its block to the blockchain.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">More specifically, the Block Hash must be&nbsp;<strong>a number that starts with a certain number of zeros<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How many zeros exactly?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It varies. The software of the Bitcoin system determines the&nbsp;<strong>minimum number of zeros<\/strong>&nbsp;that the Block Hash should begin with.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Originally, the requirement was for only a small number of zeros, but as more and more miners joined, the Bitcoin software started requiring a greater number of zeros.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/bpcdn.co\/images\/2022\/02\/18164059\/bitcoin-mining-process-no-nonce.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/bpcdn.co\/images\/2022\/02\/18164059\/bitcoin-mining-process-no-nonce.png\" alt=\"Bitcoin mining process without nonce\" class=\"wp-image-219490\"\/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">A miner must generate an output (the \u201cBlock Hash\u201d) that satisfies the output threshold set by the Bitcoin software.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This \u201cthreshold\u201d just specifies the numbers of zeros that the Block Hash must begin with.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It\u2019s like the \u201climbo\u201d dance.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/bpcdn.co\/images\/2022\/02\/18164307\/bitcoin-mining-like-limbo-dance.png\" alt=\"Bitcoin mining is like a limbo dance\" class=\"wp-image-219491\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">En&nbsp;<strong>lower the threshold, the more zeros<\/strong>&nbsp;that are required.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">En&nbsp;<strong>more zeros that are required, the higher the difficulty<\/strong>&nbsp;to find a \u201ccorrect\u201d Block Hash.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is because more leading zeros means fewer possible solutions, which means more time is required to \u201cfind\u201d a correct Block Hash.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Finding a value that starts with three zeros like \u201c<strong>000123\u2026<\/strong>\u201d is much harder than trying to find a value with six zeros like \u201c<strong>000000123\u2026<\/strong>\u201d<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here\u2019s a recent&nbsp;<a href=\"https:\/\/www.blockchain.com\/btc\/block\/0000000000000000000586b367c292dfd274bf2e67575cf8b4d00735fc1df6ff\" target=\"_blank\" rel=\"noreferrer noopener\">example<\/a>&nbsp;of an actual valid Block Hash:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">0000000000000000000586b367c292dfd274bf2e67575cf8b4d00735fc1df6ff<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Notice how many zeros it starts with.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">The \u201ccertain number of zeros\u201d comes from what\u2019s called the \u201c<strong>mining difficulty<\/strong>\u201d. This is automatically adjusted up or down by the software running the Bitcoin network. The difficulty changes based on the number of miners. The more computers that are mining, the greater the difficulty and the more zeros are needed at the start making it harder to find the winning nonce.<\/p>\n<\/blockquote>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">A Block Hash can be interpreted as&nbsp;<strong>a very large numbe<\/strong>r and must be below a certain threshold. This is why block hashes start with a series of zeros followed by an alphanumeric string. Some blocks have as many as twenty leading zeros, while earlier blocks have as few as eight. The number of zeros required roughly demonstrates the difficulty of mining at the time the block was published.<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">What happens if the Block Hash doesn\u2019t start with the required number of zeros?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Then the block can NOT be added to the file (the \u201cblockchain\u201d).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Fortunately, the&nbsp;<strong>miner can have multiple attempts<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But if a miner ran just the Block Header containing just the Timestamp, Previous Block Hash, and \u201cTransaction Summary\u201d Hash through the hash function again,&nbsp;<strong>it would always get the same result<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The miner needs to alter the data somehow before trying to hash the Block Header&nbsp;<em>again<\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Bitcoin provides a way!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Nonce<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In the Block Header, there is an extra field called the \u201c<strong>nonce<\/strong>\u201d (light blue box)<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/bpcdn.co\/images\/2022\/02\/18164859\/block-header-contains-nonce.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/bpcdn.co\/images\/2022\/02\/18164859\/block-header-contains-nonce.png\" alt=\"Block header contains a nonce\" class=\"wp-image-219494\"\/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">There is a&nbsp;<strong>special part of the Bock Header<\/strong>&nbsp;that miners can populate with an arbitrary number.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The miner is free to put any number it wants in.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The nonce is completely separate from the transactions in the block. Its only purpose is to allow miners to fill it with a number, and&nbsp;<strong>change the number<\/strong>&nbsp;if the Block Hash doesn\u2019t meet the requirement of starting with a certain number of zeros.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">By using a nonce, a miner can manipulate the output of the hash function to \u201cguess\u201d the desired output.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Since the other pieces of data in the Block Header can\u2019t be changed, the only piece of data that can be altered is the nonce.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So if the first hashing attempt of the Block Hader fails, the miner changes the value of the nonce.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can think of this process as like trying to find the combination of a&nbsp;<strong>combination padlock.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/bpcdn.co\/images\/2022\/03\/17092853\/combination-lock.png\" alt=\"Combination Lock\" class=\"wp-image-221032\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">There are no shortcuts possible when trying to find the combination of numbers that unlocks it. You have to try every possible combination until at some point, you find the correct one&nbsp;<strong>by chance<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You have to guess over and over until you get lucky!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And just as it\u2019s extremely easy and&nbsp;<strong>quick to check<\/strong>&nbsp;that a lock combination is the correct one (it either unlocks or doesn\u2019t), it is extremely easy and quick for the miner, and for other nodes after, to check that the nonce is indeed the right one.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The miner is also&nbsp;<strong>competing<\/strong>&nbsp;against other miners. The first miner to find a nonce that results in a valid Block Hash is granted the right to add its block into the blockchain and is rewarded for doing so.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, let\u2019s say the Block Hash needs to&nbsp;<strong>start with at least four zeros<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The only way to find a Block Hash with the required number of initial zeros is to&nbsp;<strong>randomly pick a nonce value<\/strong>&nbsp;and run the Block Header through the hash function.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this scenario, the miner starts with \u201c0\u201d for the nonce value (light blue box).<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/bpcdn.co\/images\/2022\/02\/18165221\/nonce-at-zero.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/bpcdn.co\/images\/2022\/02\/18165221\/nonce-at-zero.png\" alt=\"Nonce is 0\" class=\"wp-image-219495\"\/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">If that fails to produce the desired result, then all the mincer can do is to try again&nbsp;<strong>with a&nbsp;<em>diferente<\/em>&nbsp;nonce<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The miner changes the nonce, then starts over again until it manages to find a Block Hash with at least the required minimum number of zeros. In this case,&nbsp;<strong>four zeros<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Remember, even though you\u2019ve only made a small adjustment, with a hash function,&nbsp;<strong>even the tiniest change will produce completely different results<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So the miner\u2019s first attempt was to use the number \u201c0\u201d in the nonce. It then runs the Block Header through the hash function and sees if the Block Hash starts with four zeros.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As you can see, the Bloch Hash only starts with<strong>&nbsp;two zeros<\/strong>&nbsp;so it does NOT meet the criteria needed to add the block to the blockchain.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If the output is not valid, the miner keeps trying with different nonce values.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Since the value of \u201c0\u201d didn\u2019t work, the miner can change the value of the Nonce to\u201c<strong>1<\/strong>\u201d (light blue box) and then run the Block Header through the hash function again.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/bpcdn.co\/images\/2022\/02\/18165539\/nonce-changed-to-1.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/bpcdn.co\/images\/2022\/02\/18165539\/nonce-changed-to-1.png\" alt=\"Nonce changed to 1\" class=\"wp-image-219497\"\/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">As you can see, the Block Hash starts with&nbsp;<strong>no zeros<\/strong>&nbsp;so this doesn\u2019t work either.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Since the value of \u201c1\u201d didn\u2019t work, the miner can change the value of the Nonce to\u201c<strong>2<\/strong>\u201d (light blue box) and then run the Block Header through the hash function again.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/bpcdn.co\/images\/2022\/02\/18165903\/nonce-changed-to-2.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/bpcdn.co\/images\/2022\/02\/18165903\/nonce-changed-to-2.png\" alt=\"Nonce changed to 2\" class=\"wp-image-219498\"\/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In this case, the Block Hash<strong>&nbsp;finally starts with four zeros<\/strong>&nbsp;and meets the criteria.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It\u2019s a successful Block Hash result!\u00a0<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As you can see, it\u2019s unpredictable which nonce will produce a Block Hash with the correct number of zeros, so the miner has to&nbsp;<strong>keep trying different nonces to find the right value<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Miners can mine for long periods of time with no guarantee that they will ever find a correct nonce. Most never will!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The nonce is used as a counter, where its value is just constantly incremented until either it finds the correct Block Hash or some other miner does.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>It\u2019s like a number guessing game!<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You\u2019re simply trying to find a hash that begins with a certain number of zeros by changing the value of the nonce.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Miners do this repeatedly\u2026.HOPING that the result will produce a Block Hash that meets the criteria.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The more powerful their computers are, the more \u201cguesses\u201d they can make.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This \u201cguessing\u201d process is known as&nbsp;<strong>miner\u00eda<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The \u201cwinning\u201d miner is rewarded with a set number of bitcoin (plus transaction fees) called the \u201c<strong>block reward<\/strong>.\u201d<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One miner wins the block reward roughly&nbsp;<strong>every 10 minutes<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Block Reward<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Since miners expend so much time and energy to \u201cguess\u201d the correct nonce and confirm transactions on the Bitcoin blockchain, the Bitcoin software rewards them for their effort with:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Newly created bitcoin<\/strong>\u00a0When a miner confirms transactions, they are bundled in a block and added to the Bitcoin blockchain. For every new block that gets added to the blockchain, new bitcoins are paid out to the miner. This is known as the\u00a0<strong>block subsidy<\/strong>. The specific amount of bitcoins is based on an issuance schedule determined by the protocol at the time of the block creation. Currently, the new issuance is 6.25 BTC per block and will decrease to 3.125 BTC per block around May 2024.<\/li>\n\n\n\n<li><strong>Transaction fees.<\/strong>\u00a0When people transact with bitcoin, they pay a fee to the miners to incentivize them further to confirm their transaction. When a miner confirms a bundle of transactions, it also collects all the fees from each individual transaction.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Mining is a monotonous and repetitive process:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/bpcdn.co\/images\/2022\/02\/18171217\/bitcoin-mining-process.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/bpcdn.co\/images\/2022\/02\/18171217\/bitcoin-mining-process.png\" alt=\"Bitcoin Mining Process\" class=\"wp-image-219501\"\/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Take a Block Header with the nonce, hash it, see if the hash starts with a certain number of zeros, and if not, repeat the process with a different nonce.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I\u2019m getting sleepy just thinking about it.\u00a0<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So when you read or hear that mining involves \u2018\u201csolving complex mathematical problems\u201d, now you know that\u2019s not a correct description.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>There is nothing complex about mining!&nbsp;<\/strong>&nbsp;The process itself is pretty simple. You\u2019re just trying to&nbsp;<strong>guess a correct number as fast as possible<\/strong>&nbsp;or just fast enough to be the FIRST miner to guess right so your candidate block is the one that gets added to the blockchain. That\u2019s it!<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u201c<strong>Hash rate\u201d<\/strong>&nbsp;indicates the \u201cguessing power\u201d of a mining computer. The more hashes you can guess per second, the higher your hash rate. For example, 1 trillion (1,000,000,000) guesses per second is equal to a hash rate of&nbsp;<strong>1 terrahash<\/strong>&nbsp;(TH\/s).<\/p>\n<\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">Just because the process is simple, it doesn\u2019t mean it\u2019s easy. That\u2019s why it\u2019s called \u201cmining\u201d. You\u2019re trying to \u201cdig\u201d up the correct number which requires a lot of effort, similar to actual mining in the real world.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now that the miner has found a nonce to be able to generate a Block Hash that meets the requirements (starts with at least 4 zeros), the block is added to the miner\u2019s copy of the file (the \u201cblockchain\u201d).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Remember how the blue block was the most recent block in the miner\u2019s blockchain? Not anymore.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Since the miner was able to guess the correct nonce, it was able to add its block to the blockchain (colored in green).<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/bpcdn.co\/images\/2022\/02\/18171721\/mined-block.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/bpcdn.co\/images\/2022\/02\/18171721\/mined-block.png\" alt=\"Block added to blockchain\" class=\"wp-image-219503\"\/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So from a high-level view, the file on the miner\u2019s computer has been updated (denoted in&nbsp;<strong>green<\/strong>).<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/bpcdn.co\/images\/2022\/02\/18171820\/bitcoin-node-blockchain-updated.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/bpcdn.co\/images\/2022\/02\/18171820\/bitcoin-node-blockchain-updated.png\" alt=\"Miner's blockchain updated\" class=\"wp-image-219504\"\/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">And then, the node will transmit this block to nearby nodes to which it is directly connected.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The nodes will check it, verify it, and make sure the Block Header produces a Block Hash that meets the criteria. In this case, the Block Hash needed to start with four zeros.<a href=\"https:\/\/bpcdn.co\/images\/2022\/02\/18172306\/bitcoin-miner-propogates-new-block.png\" rel=\"noreferrer noopener\" target=\"_blank\"><\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">These nodes will update their file (the \u201cblockchain\u201d) by adding the block to the file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">THEIR file will be updated and now be the same version as the winning miner\u2019s (<strong>green<\/strong>&nbsp;file).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">All the transactions in their mempool that are part of this winning block move from \u201c<strong>fresh<\/strong>\u201d (or \u201cunconfirmed\u201d) to \u201c<strong>confirmed<\/strong>\u201d status and are now permanently added to the file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Any conflicting transactions will be&nbsp;<strong>kicked out<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks to the process of mining, only the purple transaction will make it into the blockchain.<a href=\"https:\/\/bpcdn.co\/images\/2022\/02\/18173933\/conflicting-transactions-kicked-out.png\" rel=\"noreferrer noopener\" target=\"_blank\"><\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Then these nodes will pass on the block to other nodes.<a href=\"https:\/\/bpcdn.co\/images\/2022\/02\/18174217\/bitcoin-nodes-pass-new-block.png\" rel=\"noreferrer noopener\" target=\"_blank\"><\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once the new block is accepted by a majority of miners, all miners start over and create a brand new candidate block and the mining process repeats itself.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Mining acts as a&nbsp;<strong>sorting mechanism for transactions<\/strong>&nbsp;across a network of computers, where \u201cmined\u201d blocks have the final say on what belongs in the blockchain.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The Block Hash from this newly created block will now be used by miners for the \u201cPrevious Block Hash\u201d in their candidate blocks.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/bpcdn.co\/images\/2022\/02\/18175105\/new-block-hash.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/bpcdn.co\/images\/2022\/02\/18175105\/new-block-hash.png\" alt=\"Newly created block will now be used by miners\" class=\"wp-image-219519\"\/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The Block Hash acts as the \u201c<strong>chain<\/strong>\u201d.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Miners must now include the previous block\u2019s Block Hash in the&nbsp;<em>new<\/em>&nbsp;block they are creating.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/bpcdn.co\/images\/2022\/02\/18175521\/miners-include-new-block-hash.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/bpcdn.co\/images\/2022\/02\/18175521\/miners-include-new-block-hash.png\" alt=\"Miner include new block hash in new block\" class=\"wp-image-219522\"\/><\/a><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">For example, this means that to mine block 101, miners need to know the hash of block 100.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Until&nbsp;<strong>block 101<\/strong>&nbsp;has been mined,<strong>&nbsp;block 102<\/strong>&nbsp;can\u2019t be mined.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This forces miners to focus on block 101 which in turn includes the hash of&nbsp;<strong>block 100<\/strong>. No miner can skip ahead.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But instead of having each block have a \u201cblock number\u201d each block refers to the previous block by its&nbsp;<strong>Bock Hash<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This implies that every block is linked to each other and this is what creates a \u201c<strong>chain of blocks<\/strong>\u201d known as a blockchain.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This \u201cchain of blocks\u201d is held together not by block numbers, but by&nbsp;<strong>block hashes<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why You Can\u2019t Cheat Bitcoin<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s say everyone is working on block 101.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But one miner wants to alter a transaction in block 80.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It would have to make its changes and redo all the computations for&nbsp;<strong>blocks 80-100 AND also do block 101<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s&nbsp;<strong>21 blocks<\/strong>&nbsp;of expensive computing!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Not only that, but the miner would have to do it all&nbsp;<strong>before the other miners on the Bitcoin network finish the current block<\/strong>&nbsp;(block 101) that they\u2019re working on. This is basically impossible.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is very hard to get away with tampering with any transactions that already form part of the blockchain.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is what is meant when blockchains are described as&nbsp;<strong>immutable<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Proof-of-Work (PoW)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The process of mining is often referred to as a \u201c<strong>Proof-of-Work<\/strong>\u201do&nbsp;<strong>PoW<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">PoW is known as the \u201c<strong>consensus mechanism\u201d<\/strong>&nbsp;that Bitcoin uses to get all nodes to agree on the \u201cofficial\u201d copy of Bitcoin\u2019s blockchain. It is how Bitcoin is able to reach a&nbsp;<em>consensus<\/em>&nbsp;without the need for dispute resolution or intervention from a central authority.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The term \u201cproof-of-work\u201d just refers to the fact that<strong>&nbsp;it takes \u201cwork\u201d<\/strong>&nbsp;to find a block hash below a certain threshold. And once you do, anyone can verify it which provides the \u201cproof\u201d.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The process of \u201cguessing a nonce\u201d and then running the block header through the hash function is being used as a way to prove that you have performed a required amount of \u201cwork\u201d on your block.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The first miner to produce a valid hash is allowed to add a new block to the blockchain and they receive a reward of bitcoins.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If a surge of miners joins the Bitcoin network, the PoW will adjust to make it more difficult to find a valid block hash. If this increased difficulty discourages too many miners and they stop mining, the difficulty will be decreased to make it easier to mine.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This process, known as the&nbsp;<strong>difficulty adjustment<\/strong>, occurs roughly every two weeks, and it ensures that new blocks are added to the blockchain&nbsp;<strong>roughly every 10 minutes<\/strong>, no matter how many miners join or leave the network.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Difficulty adjustments are made based on the speed at which miners are creating new blocks.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">By adjusting the difficulty of mining, Bitcoin can ensure new bitcoins are created at a&nbsp;<strong>predetermined rate<\/strong>, regardless of the amount of computing power participating in the network.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The difficulty adjustment is important because it ensures that miners can\u2019t mine&nbsp;<strong>too much of the supply of the bitcoin too fast<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The specialized computer hardware and electricity required to mine also means that attacking the network is prohibitively&nbsp;<strong>expensive<\/strong>. This ensures the&nbsp;<strong>security<\/strong>&nbsp;y&nbsp;<strong>integrity<\/strong>&nbsp;of Bitcoin\u2019s blockchain.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Anyone with enough computing power to attack the network is better off mining honestly and earning the block reward (new bitcoins plus transaction fees).<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Resumen<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Congratulation! You now know how \u201cmining\u201d in Bitcoin works!<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Miners search for an acceptable hash that will be the \u201cBlock Hash\u201d by choosing a nonce, running the hash function, and checking the output.<\/li>\n\n\n\n<li>If the hash doesn\u2019t have the right amount of leading zeroes, miners change the nonce, run the hash function, and check again.<\/li>\n\n\n\n<li>When a miner is finally lucky enough to find a nonce that works, and \u201cwins\u201d, the block gets sent out to other nodes (including other miners) in the Bitcoin network, each of whom can then run the hash function with the winning miner\u2019s nonce, and verify that it works.<\/li>\n\n\n\n<li>If the solution is accepted by a majority of the nodes, the block gets added to the blockchain and the winning miner gets the block reward.<\/li>\n\n\n\n<li>All miners \u201creset\u201d and start working on a new candidate block, using the recently mined block\u2019s hash as a reference in their Block Header (as the \u201cPrevious Block Header\u201d).<\/li>\n\n\n\n<li>This process where miners try to \u201cguess\u201d or find a correct nonce is known as a \u201cProof-of-Work\u201d (PoW).<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Now that we\u2019ve learned about miners and mining, let\u2019s update our map of the Bitcoin system:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/bpcdn.co\/images\/2022\/03\/17095257\/bitcoin-as-a-system-after-mining.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/bpcdn.co\/images\/2022\/03\/17095257\/bitcoin-as-a-system-after-mining.png\" alt=\"Bitcoin as a System (Mining Added)\" class=\"wp-image-221038\"\/><\/a><\/figure>","protected":false},"excerpt":{"rendered":"<p>How does Bitcoin mining work? In the&nbsp;previous lesson, you learned what a Bitcoin&nbsp;miner&nbsp;is, how it stores fresh transactions in its&nbsp;memory pool, and then starts the \u201cmining\u201d process by creating a&nbsp;candidate block. If what I just wrote sounds like a foreign language to you, I strongly recommend you start with the&nbsp;first lesson of my Beginner\u2019s Guide [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30,12],"tags":[],"class_list":["post-2838","post","type-post","status-publish","format-standard","hentry","category-beginners-guide-to-bitcoin-mining","category-learn-crypto"],"_links":{"self":[{"href":"https:\/\/apex-aiexperts.com\/es\/wp-json\/wp\/v2\/posts\/2838","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/apex-aiexperts.com\/es\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/apex-aiexperts.com\/es\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/apex-aiexperts.com\/es\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/apex-aiexperts.com\/es\/wp-json\/wp\/v2\/comments?post=2838"}],"version-history":[{"count":1,"href":"https:\/\/apex-aiexperts.com\/es\/wp-json\/wp\/v2\/posts\/2838\/revisions"}],"predecessor-version":[{"id":2839,"href":"https:\/\/apex-aiexperts.com\/es\/wp-json\/wp\/v2\/posts\/2838\/revisions\/2839"}],"wp:attachment":[{"href":"https:\/\/apex-aiexperts.com\/es\/wp-json\/wp\/v2\/media?parent=2838"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/apex-aiexperts.com\/es\/wp-json\/wp\/v2\/categories?post=2838"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/apex-aiexperts.com\/es\/wp-json\/wp\/v2\/tags?post=2838"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}