How Bitcoin Actually Works Under the Hood

Bitcoin, introduced in 2008 by the pseudonymous Satoshi Nakamoto in the whitepaper “Bitcoin: A Peer-to-Peer Electronic Cash System,” is a decentralized digital currency that operates without a central authority. It achieves this through a combination of cryptography, distributed consensus, and economic incentives. At its core, Bitcoin is a protocol that enables peer-to-peer transfers of value over a network of computers, secured by mathematical proofs rather than trust in institutions.

This article dives into the technical mechanisms that power Bitcoin, explaining its key components: cryptographic foundations, transaction structure, the scripting language, the blockchain ledger, proof-of-work mining, and network consensus. By understanding these elements, one can appreciate how Bitcoin solves problems like double-spending and maintains security in a trustless environment.

Cryptographic Foundations: Keys and Addresses

Bitcoin’s security relies on public-key cryptography, specifically the Elliptic Curve Digital Signature Algorithm (ECDSA) with the secp256k1 curve. Each user generates a private key, a 256-bit random number kept secret. From this, a public key is derived mathematically, a process that is easy to compute in one direction but computationally infeasible to reverse.

The public key is then hashed (using SHA-256 followed by RIPEMD-160) and encoded into a Bitcoin address, typically starting with “1” for legacy addresses or “bc1” for newer formats. Addresses are what users share to receive funds; they act as pseudonyms, providing some privacy.

Ownership of bitcoin is proven by signing transactions with the private key corresponding to the address holding the funds. Anyone can verify the signature using the public key, ensuring the spender controls the funds without revealing the private key.

Transaction Structure: Inputs, Outputs, and UTXOs

Bitcoin does not have “accounts” with balances like traditional banking. Instead, it uses an Unspent Transaction Output (UTXO) model. Every transaction consumes previous UTXOs as inputs and creates new UTXOs as outputs.

A typical transaction consists of:

  • Version number: Indicates the transaction format.
  • Input count: Number of UTXOs being spent.
  • Inputs: Each input references a previous UTXO by its transaction ID (TXID) and output index (vout). It also includes a scriptSig (unlocking script) that satisfies the conditions of the previous output’s locking script.
  • Output count: Number of new UTXOs created.
  • Outputs: Each specifies a value in satoshis (1 BTC = 100,000,000 satoshis) and a scriptPubKey (locking script) defining spending conditions, usually requiring a signature from a specific address.
  • Locktime: Optional field to delay the transaction.
  • Witness data (for SegWit transactions): Separated signatures to improve efficiency.

Transactions must balance: total input value equals total output value plus fees (paid to miners). Change outputs return excess to the sender.

To prevent double-spending, nodes track all UTXOs. A transaction is invalid if it tries to spend a already-spent UTXO.

Bitcoin Script: The Mini Programming Language

Bitcoin uses a simple, stack-based, non-Turing-complete scripting language called Script to define spending conditions. Scripts are executed on a stack: data is pushed/popped, and opcodes perform operations.

A full script combines the unlocking script (from the input) and locking script (from the previous output). Execution starts with the unlocking script, then the locking one. It must evaluate to TRUE for the spend to be valid.

Common scripts include:

  • Pay-to-Public-Key-Hash (P2PKH): The most standard. Locking script: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG. Unlocking: <signature> <pubKey>.
  • Pay-to-Script-Hash (P2SH): Allows complex conditions, like multisig.
  • SegWit variants (P2WPKH, P2WSH): Move witness data separately for scalability.

Script is deliberately limited (no loops) to avoid infinite execution or complexity attacks, ensuring predictability and security.

Advanced uses include timelocks, multisignatures (requiring multiple keys), and covenants (future spending restrictions, emerging in proposals).

The Blockchain: A Chain of Blocks

The blockchain is a append-only ledger of all transactions, structured as linked blocks.

Each block contains:

  • Block header: Version, previous block hash, Merkle root (hash of all transactions), timestamp, difficulty target (bits), nonce.
  • Transaction list: Including the coinbase (first transaction, rewarding the miner).

Blocks are linked via the previous hash, forming an immutable chain: altering one block invalidates all subsequent ones.

The Merkle root efficiently proves transaction inclusion without downloading the full block.

Full nodes store the entire blockchain (over 500 GB as of late 2025) and validate every rule.

Proof-of-Work Mining: Securing the Network

New blocks are created through mining, using proof-of-work (PoW). Miners compete to find a nonce such that the block header’s double SHA-256 hash is below a target value (starting with many leading zeros).

This puzzle is hard to solve (requiring trillions of hashes per second via ASICs) but easy to verify.

The difficulty adjusts every 2016 blocks (~2 weeks) to maintain ~10-minute block times.

The first miner to solve it broadcasts the block, earning:

  • Block subsidy: Newly minted bitcoin (halving every 210,000 blocks; currently 3.125 BTC post-2024 halving).
  • Transaction fees.

PoW secures the chain: the longest chain with the most cumulative work is canonical. Attacking (e.g., 51% attack) requires overwhelming hash power to rewrite history, which is economically prohibitive.

Network Consensus and Operation

Bitcoin nodes form a peer-to-peer network. Transactions are broadcast, entering mempools. Miners select and include them in candidate blocks.

Upon a valid block, nodes validate it (rules, signatures, PoW) and extend the chain. Orphan blocks (on shorter chains) are discarded.

Consensus emerges from following the heaviest chain (most work). Soft forks (tightening rules) and hard forks (loosening) require community agreement for upgrades.

As of 2025, Bitcoin remains robust, with enhancements like Taproot (2021) improving privacy and efficiency, and ongoing discussions for further script capabilities.

Why It Works: Incentives and Security

Bitcoin aligns incentives: miners invest in hardware/energy for rewards, securing the network. Honest behavior is profitable; attacks are costly.

Cryptography ensures ownership proof, PoW prevents centralization of history control, and decentralization (thousands of nodes) resists censorship.

Despite energy concerns (comparable to some countries), PoW’s security has proven resilient over 16 years, with no successful double-spends on the main chain.

In essence, Bitcoin transforms digital scarcity into verifiable ownership through elegant protocol design, enabling a global, permissionless monetary system. Understanding these mechanics reveals why it endures as sound money in a digital age.