Introduction

The main problem to tackle when inventing digital cash is double spending. Since everything digital can be copied, if we have digital coins, what is stopping me from paying you and still keeping a copy of the coin to myself? The most common way of solving this is to have a central authority keeping track of the coins.

What separates Bitcoin from earlier attempts at digital currency is that it is completely decentralized. The system uses peer-to-peer technology and no central authority exists or is needed.

Cryptography

In order to understand Bitcoin we first need to learn some cryptography and more specifically assymetric cryptography. We won't go into too much detail in this article but the significant feature of assymetric cryptography is that different keys are used for encryption and decryption. This means that the key for encrypting a message, the "public key", doesn't need to be kept secret. You can publish it and let anyone use it to send encrypted messages that only you can read. This is because only you have the other key, the "private key".

In Bitcoin the public key (or actually a hash of the public key) is called a Bitcoin address. Anyone can send bitcoin to an address, making it similar to an account number. In order to access the money and send them on you need the private key that corresponds to the Bitcoin address.

Transactions

To transfer bitcoins from address A to address B a transaction is created by the owner of address A. The transaction is signed using the private key corresponding to address A and then broadcasted to the Bitcoin network. There is now a transaction that is known by the nodes in the network but we still have the problem of double spending. What if the owner of adress A simultaneously broadcasted another transaction that sends the funds to address C. Which one is the valid transaction? The owner of address B needs to be sure that the transaction is confirmed, that all nodes in the network have consensus about which transaction is valid.

The blockchain

Since there is no central authority that records and validates transactions Bitcoin instead has a public, distributed database called the blockchain, where all transactions are recorded. In order for a transactions to be confirmed it has to be included in a block. Creating a block that becomes part of the blockchain is a competition between "miners", and anyone can be a miner. The price of the competition is 12,5 brand new bitcoins as well as all transaction fees attached to the transactions, and a new block is created, on average, every 10 minutes. The award was initially 50 bitcoins per block and is halved every 4 years which means that the total amount of bitcoins will never exceed 21 million.

So, how is a block created then? A block is composed by the transactions to be included, a reference to the previous block and an arbitrary value called the nonce. The information is hashed, uing SHA-256, and if the value is lower that a certain threshold (the current "difficulty" of the network) the block is valid and will be accepted by all nodes. Generating a valid block is trial-and-error work that is performed by changing the nonce to get different output hash values until one lower than the difficulty threshold is found. The difficulty is automatically adjusted every 2 weeks so that the average time to create a block is always around 10 minutes, regardless of the amount of hash power in the network.

Confirmed transactions

Since every block points to the previous one the distributed database is referred to as a "blockchain". It might happen that two miners manage to create a new block almost at the same time, so that there are several blocks pointing to the same parent. When such "forks" occur miners may temprarily work on two different chains. The rule is that the longest chain (based on amount of hash work needed to create it) is the valid one so when a new block is found on either fork the network will once again reach consensus on which is the correct chain.

When receiving a Bitcoin transaction you want to make sure that the transaction is included in a block and that a number of new blocks have been created "on top of" the block that includes your transaction. If a fork is in progress it might happen that your node "changes its mind" and realize that there is another longer chain. Worst case scenario is that the person who sent you money has another conflicting transaction on the other chain, i.e. has tried to perform a double spend. The number of blocks created after the block that contains your transaction is referred to as the number of confirmations. In order to be sure that your transaction can't possibly be reversed you want to make sure that it has a couple of confirmations. Usually something like 6 confirmations is considered to be very safe.

Continued reading

Below are some suggestions on where to continue for more in-depth knowledge about how Bitcoin works.

Latest articles:

Slide
More articles