How does Bitcoin work?

Lukas Gamper
4 min readApr 12, 2021

Bitcoin is a cryptocurrency. Bitcoins do not ‘exist’ per se as do gold or real coins. They only exist as transactions on a public ledger, the blockchain. Owning bitcoins means to have access to a cryptographic key pair:

  • a public key to which a previous transaction has sent some bitcoins. This is called a bitcoin address.
  • the corresponding private key which can be used to initiate bitcoin transactions.

The bitcoin address is like an IBAN in the bitcoin network where you can send bitcoins from and receive bitcoins to. The balances of all bitcoin addresses in the bitcoin network are public, but they can only be changed with the corresponding private key. All transactions in the bitcoin network can be explored with the Bitcon Explorer.

Let’s look at an Example Transaction

Bob owns 0.5 bitcoins on his bitcoin address bc1qxy. In reality the bitcoin addresses are much longer, but for demonstration purpose, let’s keep it simple.

Bob wants to send Alice 0.2 bitcoins. Alice tells Bob her bitcoin address: 1kgdyg. Now Bob can initiate a transaction to send Alice the requested bitcoins. A transaction must always include the whole amount of a bitcoin address, but it can have several senders and receivers. In our example Bob sends sends 0.2 bitcoins to Alice, and sends the remaining part back to his own address.

Every transaction costs a fee to pay the miners to write the transaction into the blockchain. Our transaction would be like this in the Bitcoin Explorer:

To initiate his transaction Bob sends the transaction informations to the bitcoin network and waits until a miner puts it in the blockchain.

How does the Blockchain work?

A blockchain is — as its name says — a chain of blocks. A block consists of 4 parts:

  • The Data, which is stored in the block. One block in the blockchain contains around 2000 transactions.
  • The Hash of the block. The hash is generated by a function which receives an input — in this case the Data, the Previous Block and the Nonce — and returns a string of fixed length. A hash function is infeasible in reverse direction. The bitcoin blockchain uses the hash function called SHA-256.
  • The Hash of the Previous Block
  • The Nonce is used to protect the blockchain from modifications. This is covered in the next section.

The blocks are forming the blockchain starting with the first block called the genesis block. The genesis block is the only block in the chain not containing the hash of the previous block.

To change data in a single block the whole blockchain from the point where the block is changed must be rewritten.

Proof of Work

To prevent an imposter from modifying a block and rewriting easily the whole blockchain, the hashes of the blocks must obey a simple rule (the unsimplified rule): It must start with a certain number of zeroes (19 at the time of writing). Based on probability theory this means that in average 16¹⁹ (a 7 followed by 22 zeros) hashes must be generated to find a valid one. This requires an enormous amount of energy and computational power. The datacenters that provide this computational power are called miners.

The above-mentioned rule is also called the difficulty. It is chosen in a way that every 10 minutes a block is generated. If more computational power is available, the difficulty increases and vice versa. Every 2016 blocks — roughly every 2 weeks — the difficulty adjusts to keep the block rate constant.

To be able to find a hash which satisfies the difficulty, the miners need a free parameter. This is the nonce, the mysterious 4th parameter in the block description above. The miners are choosing a nonce randomly and calculate the hash of the block. If the hash does no satisfy the difficulty, they choose a new nonce and try again. This process is done over and over until a hash is generated which satisfies the difficulty.

Conclusion

Out of its design the bitcoin network has the following inherent properties:

  • Decentralised: There is no central instance ‘owning’ the system. The participants are keeping it alive. This increases the security of the network: if one party gets hacked, the other members of the system keep a correct copy of the blockchain.
  • Transparency: Every transactions in the bitcoin network is stored on many different computers all over the internet. Everyone can see all transactions and the participating public keys. This protects the network against fraud and data loss.
  • Signed Transactions: Every transaction is signed with the private keys of its participants.

--

--