0%

Bitcoin: digital gold and the foundation of Web3

My detailed notes on why Bitcoin exists and the cryptography it is built on

These are my notes from learning how Bitcoin works, written as I went. I start with the problem Bitcoin tries to solve, cover the cryptography it relies on, and then walk through how I would design a decentralized currency from scratch.

The original source is the Bitcoin whitepaper by Satoshi Nakamoto. It is only nine pages long, so I recommend reading it alongside these notes: Bitcoin, A Peer-to-Peer Electronic Cash System.

Introduction: why Bitcoin?

Gold has been humanity's preferred store of value for thousands of years. In the digital age, it comes with real drawbacks:

  • Physical inconvenience: Gold is heavy and difficult to carry or transfer across borders.
  • Purity verification: Checking the purity of gold takes expert testing. You cannot simply trust a piece of gold at face value.
  • Inefficient markets: Gold prices vary by region. In India, for example, local gold shops often charge 3 to 5% in making charges, and the price can differ from US or international markets because of import duties and local demand.

Wouldn't it be ideal if something digital held the same scarcity and value preserving properties as gold, but with better price discovery, instant verifiability and global accessibility?

That is exactly the problem Satoshi Nakamoto set out to solve.

Gold and Bitcoin side by side

Property Gold Bitcoin
Portability Heavy, hard to move across borders A few bytes of data, moves anywhere
Verification Needs expert testing Anyone can verify with software
Divisibility Hard to split in small amounts Divisible to 8 decimal places
Supply Grows as more is mined from the ground Fixed cap of 21 million coins
Price discovery Varies by region and shop One global market, always open

The hard part: digital scarcity

Digital files are trivially copyable. If money were just a file, I could copy it and spend it twice. This is the double spending problem, and it is why digital cash failed for decades. Bitcoin was the first system to solve it without a bank in the middle.

Prerequisite concepts

Before diving into how Bitcoin works, I need a few foundational ideas from computer science and cryptography.

Bits, bytes and encodings

At the lowest level, computers store everything as bits (0s and 1s). A byte is a group of 8 bits. To represent text, numbers or any data in a readable form, we use encodings like UTF-8 or ASCII.

For example, the word hello is the five bytes 68 65 6c 6c 6f when written in hexadecimal. This matters because all blockchain data (addresses, transactions and signatures) is ultimately a sequence of bytes in a specific format.

Hashing vs encryption

Feature Hashing Encryption
Purpose Verify integrity and fingerprint data Protect confidentiality
Reversible? No, it is one way Yes, with the right key
Output Fixed length digest Same length as input, roughly
Examples SHA-256, Keccak-256 AES, RSA
  • Hashing turns any input into a fixed size string. Even a tiny change in the input produces a completely different hash.
  • Encryption scrambles data so only authorized parties can read it. It is reversible if you hold the correct key.

A good hash function has four properties that Bitcoin depends on:

  1. Deterministic: The same input always gives the same output.
  2. Fast to compute: Hashing any input is cheap.
  3. One way: You cannot work backwards from a hash to the input.
  4. Collision resistant: It is practically impossible to find two different inputs with the same hash.

SHA-256 always outputs 256 bits, which is 32 bytes or 64 hex characters:

import { createHash } from "crypto";
 
const hash = createHash("sha256").update("hello world").digest("hex");
 
console.log(hash);
// b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9

Bitcoin uses hashing (specifically SHA-256) to create block identifiers and to make tampering obvious. Hold on to that hash above, because it shows up again in the secp256k1 example below.

Asymmetric encryption (public key cryptography)

Asymmetric encryption, also called public key cryptography, uses a mathematically related pair of keys:

  • Public key: Can be shared openly. It is your identity on the blockchain.
  • Private key: Must stay secret. It proves ownership and authorizes transactions.

The two keys are linked, but it is computationally infeasible to derive the private key from the public key. A useful mental model is a mailbox: anyone can drop a letter in (the public key), but only the owner has the key to open it (the private key).

Digital signatures

Blockchains mostly use these keys the other way around, for signatures instead of secrecy:

  1. I hash my message (for Bitcoin, a transaction).
  2. I sign the hash with my private key, which produces a signature.
  3. Anyone can verify the signature using my public key, the message and the signature.

Nobody learns my private key, yet everyone can confirm that only the owner of that key could have produced the signature. That is how Bitcoin proves you own your coins without a bank or a password.

Signing with a private key and verifying with a public key

Common asymmetric algorithms

  1. RSA: Named after Rivest, Shamir and Adleman. One of the oldest and most widely used.
  2. ECDSA: Elliptic Curve Digital Signature Algorithm. Used by Bitcoin and Ethereum.
  3. EdDSA: Edwards curve Digital Signature Algorithm. Used by Solana.

Elliptic curves

Both ECDSA and EdDSA rely on elliptic curve cryptography (ECC). ECC gives the same security as RSA with much smaller keys, which makes it efficient for blockchains.

For a deep dive into how elliptic curves work, this video explanation is excellent.

Creating public and private keypairs

Here is how to create keypairs, sign messages and verify signatures with popular libraries.

Never paste a real private key into a website, a chat or a public repository. Anyone who has it controls the funds. Use test keys while learning.

EdDSA (ed25519) for Solana

Using @noble/ed25519:

import * as ed from "@noble/ed25519";
 
async function main() {
  // Generate a secure random private key
  const privKey = ed.utils.randomPrivateKey();
 
  // Convert the message "hello world" to a Uint8Array
  const message = new TextEncoder().encode("hello world");
 
  // Generate the public key from the private key
  const pubKey = await ed.getPublicKeyAsync(privKey);
 
  // Sign the message
  const signature = await ed.signAsync(message, privKey);
 
  // Verify the signature
  const isValid = await ed.verifyAsync(signature, message, pubKey);
 
  console.log(isValid); // true
}
 
main();

Using @solana/web3.js:

import { Keypair } from "@solana/web3.js";
import nacl from "tweetnacl";
 
const keypair = Keypair.generate();
 
const publicKey = keypair.publicKey.toString();
const secretKey = keypair.secretKey;
 
console.log("Public Key:", publicKey);
console.log("Private Key (Secret Key):", secretKey);
 
const message = new TextEncoder().encode("hello world");
 
const signature = nacl.sign.detached(message, secretKey);
const result = nacl.sign.detached.verify(
  message,
  signature,
  keypair.publicKey.toBytes(),
);
 
console.log(result); // true

ECDSA (secp256k1) for Bitcoin and Ethereum

Using @noble/secp256k1. The msgHash here is the SHA-256 hash of "hello world" from earlier:

import * as secp from "@noble/secp256k1";
 
async function main() {
  const privKey = secp.utils.randomPrivateKey();
 
  const msgHash =
    "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9";
 
  const pubKey = secp.getPublicKey(privKey);
  const signature = await secp.signAsync(msgHash, privKey);
  const isValid = secp.verify(signature, msgHash, pubKey);
 
  console.log(isValid); // true
}
 
main();

Using ethers.js:

import { ethers } from "ethers";
 
const wallet = ethers.Wallet.createRandom();
 
const publicKey = wallet.address;
const privateKey = wallet.privateKey;
 
console.log("Public Key (Address):", publicKey);
console.log("Private Key:", privateKey);
 
const message = "hello world";
 
const signature = await wallet.signMessage(message);
console.log("Signature:", signature);
 
const recoveredAddress = ethers.verifyMessage(message, signature);
 
console.log("Recovered Address:", recoveredAddress);
console.log("Signature is valid:", recoveredAddress === publicKey);

Summary of curves

Blockchain Algorithm Curve
Bitcoin ECDSA secp256k1
Ethereum ECDSA secp256k1
Solana EdDSA ed25519

From public key to Bitcoin address

A Bitcoin address is not the raw public key. For the classic address format, it is built like this:

  1. Take the public key.
  2. Hash it with SHA-256, then with RIPEMD-160, to get a short 20 byte hash.
  3. Add a version byte in front.
  4. Add a 4 byte checksum at the end, taken from a double SHA-256 of the result.
  5. Encode everything in Base58 so it is easy to read and copy.

Ethereum is simpler: it takes the Keccak-256 hash of the public key and keeps the last 20 bytes. Newer Bitcoin address types encode things differently, but the idea is the same: the address is a shorter fingerprint of the public key.

Real world uses of public key cryptography

Public key cryptography is not limited to blockchains. It powers much of the modern internet:

  1. SSL/TLS certificates: When you visit a website over HTTPS, your browser uses the server's public key to set up a secure, encrypted connection.
  2. SSH keys: Developers use SSH keypairs to connect to remote servers or push code to GitHub without passwords.
  3. Blockchains and cryptocurrencies: Public keys become wallet addresses, and private keys prove ownership and authorize spending.

How to create a decentralized blockchain and currency

Now that I understand the building blocks, here is how I would design a decentralized currency like Bitcoin from scratch.

Step by step design

  1. Write a miner program (bitcoin_miner.exe) that anyone can run on their machine to join the network as a miner.
  2. Define the monetary policy in code: how new currency is minted, at what rate, and who receives the initial supply (developers, early investors, airdrops and so on).
  3. Open the network: Allow anyone to join and become a miner simply by running the program. No permission and no central authority.
  4. Replace usernames with keypairs: Users who want to send or receive BTC generate a public and private keypair. There are no bank accounts or passwords.
  5. Sign and broadcast transactions: To send BTC, a user creates a transaction, signs it with their private key, and sends it to one or many miners.
  6. Miners bundle transactions into blocks: Roughly every 10 minutes, miners collect pending transactions, bundle them into a block, and broadcast that block to the entire network.
  7. Build the blockchain: Each new block references the previous block, creating a permanent, chronological chain of all transactions since the genesis block.

The life of a transaction

Here is the same flow from the moment a user signs a transaction to the moment it becomes permanent:

The life of a Bitcoin transaction in five steps

What makes it a chain

Each block stores the hash of the previous block in its header, along with a summary of its transactions (the Merkle root) and a number found by miners called the nonce. Because every block depends on the one before it, the blocks form a chain.

Blocks linked by the hash of the previous block

This is why history is so hard to rewrite. If someone changes a single transaction in Block 1, the hash of Block 1 changes. Block 2 stored the old hash, so it no longer matches, and the same is true for every block after it. To get away with it, an attacker would have to redo the work for the whole chain faster than the rest of the network, which is the idea Proof of Work builds on.

What's next?

This is a simplified overview. The design above has open problems, which Satoshi Nakamoto solved in the Bitcoin whitepaper:

  • The double spending problem: How do you stop someone from spending the same coins twice?
  • Consensus mechanism: How do miners agree on which block is valid without a central authority?
  • Sybil resistance: How do you stop someone from creating thousands of fake nodes to manipulate the network?
  • Incentive alignment: Why would miners spend electricity and computing power to secure the network?

The answers are Proof of Work, the longest chain rule, mining difficulty and the 21 million supply cap. I will cover each of them in upcoming notes. Until then, the whitepaper is the best place to look.

Key takeaways

  1. Bitcoin is an attempt at digital gold: scarce, verifiable and borderless.
  2. Hashing gives every piece of data a unique fingerprint and makes tampering obvious.
  3. Public key cryptography lets you prove ownership with a signature, without revealing your secret.
  4. Bitcoin and Ethereum use ECDSA on secp256k1, and Solana uses EdDSA on ed25519.
  5. Blocks are linked by hashes, so rewriting history means redoing the work for every block after it.

Resources

Conclusion

Bitcoin was born from a simple observation: gold is valuable but physically and economically inefficient. By combining asymmetric cryptography, hashing and decentralized networking, Bitcoin created the first truly digital store of value. It is scarce, verifiable, borderless and resistant to censorship.

Understanding these foundations is the first step toward Web3 development, and toward seeing why decentralized systems matter.


Last updated: October 2, 2026

Enjoyed this? Let's talk

I write about backend, engineering and web3 as I learn them. Always happy to compare notes.

Keep reading