This post was originally written for another publication, and is uploaded here for posterity.
There’s been a lot of press over cryptocurrencies like Bitcoin, Bitcoin Cash, Ethereum and friends - particularly due to the wildly high prices some of these currencies can reach. However, how do they actually work under the hood?
Fundamentally, cryptocurrencies have to have some way for people to own money, and to authenticate that someone is actually allowed to spend the money they say they have. In the real world, your bank knows who you are by name, has a record of your balance, and stops you from spending more than you actually have. Or, you have some physical banknotes which you can give to people, which are worth value in and of themselves. However, cryptocurrencies don’t have any central banks or paper money, so we have a problem.
To get around this problem, cryptocurrencies have addresses. An address has both a public and a secret component; the public bit is the bit you give to other people if you want them to pay you, and you keep the secret bit, well, secret, because it’s what you use to send other people money. Anyone can generate an address, using some maths called public-key cryptography to do so - for example, going to bitaddress.org and moving your mouse around for a bit will do just that. The secret bit is the key (literally); you’re only allowed to spend the money that people have sent to the public address if you have the secret component. And, since anyone can generate addresses using a common bit of maths, our problem is solved! But how does money actually move around?
An important thing about the way addresses work is that, if you have the secret component of the address, you can sign stuff - and, because of how the maths works out, everyone else can check that only you, the person with the secret, could have been able to do that. We can use this to build transactions - to pay someone some money, I simply sign something saying “I, the owner of address ABC, would like to pay address XYZ 3 bitcoins”, and tell as many people as I can about this, so everybody knows. Everybody then does the maths and checks that my signature is valid, preventing anyone without the secret from stealing my money.
In fact, everyone else also has to check that you indeed have the money you’re trying to use, which is why transactions also require you to tell everyone where the money came from - e.g. “I got 1 BTC from Bob and 2 BTC from Jim, and I’d like to send all 3 BTC to Dave”. This makes it easier for everyone to verify that what you say is true, by looking at the list of all transactions that have ever taken place and finding the ones you’re talking about. However, how do we make a list of transactions that everyone can agree on, and how do we check that the transactions are valid ones?
To solve this problem, cryptocurrencies have this concept of a block. A block is simply a bunch of transactions that someone has checked over and shown to be valid, coupled with a reference to the last block (e.g. “this is block #3, and the last one I know about was block #2”) and the solution to a really hard maths problem, called a proof-of-work (PoW). The proof-of-work is the clever bit: it’s a maths problem (which is different for every block) that takes quite a lot of computing power to solve, meaning that only people with proper hardware (so-called miners) are able to solve it. This means that a significant investment is required to be able to confirm transactions, keeping people honest: nobody’s going to buy a whole bunch of fancy stuff to do bitcoin mining and then do evil things with it, because people will stop using Bitcoin if that happens, making their investment worthless.
When miners find the correct answer to the proof-of-work, they can include it in a block and get a bunch of miner’s fees for their hard work. These are made up of a reward, which started at 50 BTC per block and has been gradually decreasing over time, and transaction fees, which people add in to their transactions to get miners to put them in the blocks (e.g. “I want to send Dave 0.9 bitcoins, and I’ll give 0.1 bitcoins to any miner who checks my transaction”). The reward is how coins come into existence in the first place - and is also why the supply of, say, Bitcoin is limited, as the reward is set to decrease as more and more blocks are mined until it reaches zero.
(Incidentally, different cryptocurrencies can have different proof-of-work problems. For example, Bitcoin uses SHA256 hashing, while Litecoin uses a hash function called ‘scrypt’. Ethereum, a relatively new currency, requires that people run mini-programs embedded in the transactions instead.)
The blocks that the miners mine are linked together in a blockchain (since every block has to say which block came before it, they’re all ‘linked together’). This blockchain is distributed amongst every person running the cryptocurrency software (e.g. the Bitcoin client) - essentially, it’s a list of all transactions that have ever taken place, together with proofs that show that a miner has verified each and every one of them. This way, everyone can agree upon who has what money, without having to trust anyone (it’s all maths!).
This has been a bit of a whistle-stop tour; if you want to learn more about any of the concepts behind cryptocurrencies, there are lots of resources available online! In particular, the original Bitcoin whitepaper, available at https://bitcoin.org/bitcoin.pdf, is worth a read, if you’re interested in what the creator of Bitcoin wrote about the protocol.