• Skip to primary navigation
  • Skip to content
  • Skip to primary sidebar

BMONEY.CO.NZ

Kiwis to the future

  • Buy Bitcoin in NZ
  • Investor Guides ▼
    • All guides
    • Bitcoin (BTC)
    • Ethereum (ETH)
    • Ripple (XRP)
    • Stellar (XLM)
    • Bitcoin Cash (BCH)
    • Cardano (ADA)
    • Litecoin (LTC)
    • Monero (XMR)
    • NEO (NEO)
    • OmiseGo (OMG)
    • Vechain (VET)
    • Ark (ARK)
    • Aion (AION)
    • Dragonchain (DRGN)
  • Blog
  • Public Portfolio
  • About
  • Disclaimers

How Bitcoin Works (For Tech Dummies)

December 3, 2018 By B Money Leave a Comment

So Bitcoin is cool and all, but how does it actually work? Like what is happening under the hood?

You’ve probably seen people talking about mining, immutability, hash rates, algorithms but for us tech noobs, we usually just gloss over that stuff.

But you can’t do that forever. Eventually you need to read about this stuff if you want to be educated about this space. So that’s exactly what I did.

This article is everything I’ve learned about “how Bitcoin works”. I’ve collected all my notes on the topic below, and since you’re probably smarter than me, hopefully you’ll understand them all too!

Hashing

To understand Bitcoin you need to understand hashing.

WHAT IS BITCOIN? A FREE BEGINNER'S GUIDE FOR KIWIS.


ENTER YOUR EMAIL BELOW AND I'LL SEND IT STRAIGHT TO YOUR INBOX.

Hashing is almost like a form of encryption.

For example, you enter an input into an algorithm, and it spits out an output known as a hash.

A hash is nothing complicated – just a string of numbers and letters.

It’s important to see this in action so you have a mental image of what is actually happening.

To do this, you can try out the SHA-256 hashing algorithm (the one that Bitcoin uses) using this generator.

Take a look: I entered the input “bmoney.co.nz” and here’s what it gave me:

So from that we know the “hash” of “bmoney.co.nz” is:

074a99827f4fa83be70b256bec815284b0c017bef1efa94cc8dd9d62fcd8b89e

Just to test, I tried this again on a different hashing calculator site and it gave me the same hash.

You can try this yourself. Just enter anything, like your name, and it will give you a unique hash that corresponds to whatever you entered.

Now here’s another important thing to know about the SHA-256 algorithm: No matter how long or short your input is, the algorithm will always produce an output that is 256-bit (64 characters).

Meaning if your input is 1 word, the hash is 64 characters and if your input is a million words, the hash is 64 characters.

As an example, I pasted my entire Investor Guide To Bitcoin article into the generator (2,000ish words) and the output was this:

Still 64 characters.

So no matter how much data you want to store, you can do it in 64 characters with a SHA256 hash algorithm. Instead of you (or a computer program) remembering thousands of lines of data, you can just remember the hash. Pretty cool eh?

But not all hashing is created equal. Some are better than others.

For a hashing algorithm to work for Bitcoin, it needs pre-image resistance.

Pre-image resistance

Pre-image resistance means it is infeasible for you to find the hash input just by looking at the hash output.

For example, the SHA 256 hash of “one” is:

7692c3ad3540bb803c020b3aee66cd8887123234ea0c6e7143c0add73ff431ed

Is it possible for you to figure out that the string above is the hash of “one” just by looking at it?

Of course not.

But let’s take another scenario.

Let’s say I tell you the string above is the hash of a number between one and ten.

Can you figure that out?

Of course.

All you need to do is enter every number between one and ten into the algorithm and find out which one matches.

This is known as the brute force method. You can’t crack the algorithm itself, but you can simply try every possibility until you find a match.

In this scenario, the brute force method would be very effective. You would probably find the answer in just a couple of minutes.

However, let’s say we decide to change the range of inputs. Instead of one to ten, let’s say it’s one to five billion.

Can you still crack the input via brute force? You can, but it’s going to take you so long that it doesn’t really matter.

Why is this important? It’s a key factor in the process of Bitcoin mining.

Bitcoin Mining

Now that we understand hashing, pre-image resistance and the brute force method, we are able to understand how Bitcoin mining works.

The idea is that miners compete to solve a very complicated puzzle. The miner who solves the puzzle “wins” the block and gets rewarded with some Bitcoin. Then the next block arrives and they do it all over again.

That’s the simple explanation.

For those of you who are interested in the complicated explanation (all of you, obviously, because this is so cool) here’s the long version:

Finding the nonce

Bitcoin mining is all about finding a number known as the nonce.

If you think of Bitcoin mining as opening up a treasure chest full of Bitcoins, the nonce (short for “number only used once”) is the key to the chest.

Bitcoin miners are simply searching for this key.

Let me explain further (pay attention here because it gets nerdy):

With Bitcoin, approximately every ten minutes a new batch of transactions arrive. This information is known as a block.

When it arrives, the first thing miners do is hash the entire contents of the block.

Then, miners add an arbitrary number to the end of this hash. It’s basically just a random number the miner has guessed.

This number is known as the nonce. 

Then the whole string (the block hash + the nonce) is hashed again.

If this final hash falls within a target range, the miner has solved the puzzle and they get rewarded with Bitcoin. 

Therefore, the aim of the Bitcoin miner is simply to find the correct nonce (sometimes known as the golden nonce).

Find the golden nonce, win the Bitcoin.

Confused? An example:

Let’s do it in a very simplified example.

Let’s say the target set on the Bitcoin software puzzle is to find a number less than 100.

And let’s say we know the nonce is between 5 and 10.

The block comes in. We hash it. The hash of the block comes out as abcdef.

So, the next step is to simply add all the possible nonces to the hash.

The first option will be abcdef5 (abcdef [the hash] +5 [the nonce]).

Then we hash it again.

Let’s say the hash of abcdef5 comes out as 150.

Because 150 is not less than 100, 5 is not the nonce.

So, we try again with abcdef6, abcdef7 and so on, until we find the correct nonce.

Of course with Bitcoin, it is not that simple. There are not only 5 possible nonces. There are millions.

Therefore Bitcoin miners need to operate on brute force, going through millions of nonces, until they find the correct one.

When a miner finds the correct nonce they notify the rest of the network. The rest of the miners validate the nonce to ensure it is actually correct. Then the winning miner receives a Bitcoin reward.

Then all miners receive the next block and the process repeats.

Mining difficulty

The next thing to understand is the concept of difficulty.

It is not impossible for a miner to find the nonce on the first try. However, he would literally need to be the luckiest man alive to do that. It would be the equivalent of me asking you to guess a number between 1 and 10 million, and you getting it right on the first try.

In the same way, it would be just as unlikely for you to guess the nonce on the very last try.

Just by laws of probability we know that the usual outcome will be somewhere in between the two extremes.

And of course, we can make it easier or harder by simply changing the range. Instead of me asking you to guess a number between 1 and 10 million, I could just make it between 1 and 2 million.

The Bitcoin software’s goal is to keep average block times to ten minutes. To do this, it simply changes the target range.

If finding the nonce is taking longer than ten minutes, the target range is increased so the nonce is found faster.

If finding the nonce is happening too fast, the target range is decreased so finding the nonce takes longer.

Through adjusting the difficulty this way, the Bitcoin software is able to keep block times to an average of ten minutes.

Hash rate

Hash rate refers to the amount of hashing activity on the network.

If the hash rate is high, it means there are many miners on the network trying to solve the nonce puzzle. As a result, the Bitcoin software will start to increase the difficulty, so the nonce isn’t found too fast.

If the hash rate is low, it means miners on the network are few, possibly having left to mine other coins, or simply shut off because mining is no longer profitable. As a result, the Bitcoin software will reduce the difficulty to try and attract miners back to the network.

This is one of the impressive aspects of Bitcoin. The software encourages miners to act in their best interests – leaving the network when the difficulty is too high, and joining the network when the difficulty is low. It just so happens that what is best for the miners is also best for the network.

Verifying transactions

When miners accept the new block of transactions, they need to verify the transactions first.

That involves checking whether the people who sent the transactions actually have enough Bitcoin to spend the amount they are requesting.

If someone tries to send an invalid transaction, it will be rejected by the majority (if not all) of the miners and be excluded from the block.

When the miners have verified which transactions can be included in the block, they can then hash it and begin searching for the nonce.

The concept of blocks (in a chain)

Now that we understand hashing, mining and the nonce we can understand blocks.

Every second, people are sending transactions to the Bitcoin network.

For example, if I want to send 1 Bitcoin to Fred, I open my Bitcoin wallet and submit that transaction to the network.

Every ten minutes, miners then receive these transactions in a bundle of data. As we know, this bundle of information is known as a block.

But blocks are more than just transactions. A block also contains:

  1. Timestamp
  2. Difficulty target
  3. Nonce
  4. Hash of the previous block

It’s that last item that is essential to understanding blockchains in action. Let me explain:

Each block contains lots of data (like, a lot).

This data can’t be carried forward into each block, because it’s just too big.

So how do we keep a record of all the transactions in Bitcoin’s history?

Hashing.

Let’s say we have a starting block, we will call it Block A.

With Block A, everything gets verified by miners, the nonce is found, it gets timestamped within the ten minute window, everything is perfect, boom, block is confirmed.

Then miners move onto Block B.

Now with Block B, everything happens exactly the same. Miners verify the transactions, nonce gets found, block is confirmed. However, when the Bitcoin software adds Block B to the chain, it includes one special thing – the hash of Block A.

Remember, including the hash is easy. It’s just a 64 character string. So even if Block A is enormous, it can still be hashed into a small 64 character string.

This will continue down the line, so the hash of Block B will be included in Block C, and the hash of Block C will be included in Block D and so on.

This means every block is connected in a chain, hence the term blockchain.

If someone tried to “hack” the chain and modify Block A to say, give themselves a million Bitcoins, then the hash of Block A would change.

And that would mean it would no longer match the hash of Block A that’s recorded in Block B.

Therefore they would also need to hack Block B.

However, after hacking Block B, the hash of Block B would change also, and it wouldn’t match the hash that’s been recorded in Block C.

So they would also need to hack Block C, and Block D, and so on.

Now in this example, it might not seem that impossible, because there are only four blocks.

But what if there are 10 million blocks? And a new block being formed every 10 minutes?

Therefore, the blockchain cannot be modified because modifying one block requires modifying every other block as well. Because all those blocks have already been confirmed, this task is very close to impossible.

This is the underlying concept of the so-called immutable blockchain.

Conclusion

So what did we learn?

That the Bitcoin network is secured by miners.

Mining is the process of finding a secret key known as a nonce, through a process known as hashing.

Hashing is performed on groups of transactions known as blocks.

Blocks are validated by miners during the mining process and then are added to the blockchain.

Each new block contains the hash of the previous block.

Therefore a block cannot be modified without modifying every other block, making the blockchain immutable.


Do you now understand the Bitcoin blockchain? What did I miss? Let me know in the comments 😉

Filed Under: Bitcoin

B Money

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

I’m now on Twitter! Follow me :)

My Tweets

Recent Posts

  • Analysing The Bitcoin Bear Market
  • How Bitcoin Works (For Tech Dummies)
  • A Guide To Using Your Ledger Nano Hardware Wallet
  • What Is The Best Bitcoin Wallet?
  • Do you have to pay tax on cryptocurrency gains in NZ?
  • A Guide To Purchasing Bitcoin On Independent Reserve (with NZD)
  • Bitcoin Price Prediction: $20,000 by 2020
  • Crypto Passive Income: Top Coins For A Long Term Dividend Play
This is not financial advice. All writings are personal opinions of the writer. Consult your own professionals before making investment decisions.