Bitcoin Script is a simple, stack-based programming language used to define the conditions under which Bitcoin can be spent. It is intentionally not Turing-complete, it cannot loop, which makes it predictable, auditable, and prevents denial-of-service attacks on the network.

What Is Bitcoin Script?

2 min read

The short version

Bitcoin Script is like a lock combination specified in instructions. Each transaction output says "here's the puzzle you need to solve to spend these coins." The most common puzzle is simply "prove you own the matching private key", but more complex puzzles (timelocks, multisig, hash locks) are possible.

How It Works

Bitcoin uses a two-part scripting system: the "locking script" (scriptPubKey) attached to an output defines spending conditions, and the "unlocking script" (scriptSig) provided by the spender proves those conditions are met. The scripts are executed on a stack machine: data is pushed, opcodes manipulate the stack. For a standard P2PKH transaction: the unlocking script pushes a signature and public key; the locking script hashes the pubkey, compares it to the stored hash, then verifies the signature. Bitcoin Script has ~100 opcodes but many are disabled. Common useful opcodes: OP_CHECKSIG, OP_CHECKMULTISIG, OP_HASH160, OP_EQUAL, OP_CHECKLOCKTIMEVERIFY (timelocks), OP_CHECKSEQUENCEVERIFY (relative timelocks).

A time-locked savings script

You want to lock 1 BTC until January 1, 2026. You create a transaction with the output script: OP_CHECKLOCKTIMEVERIFY OP_DROP OP_DUP OP_HASH160 <your_pubkey_hash> OP_EQUALVERIFY OP_CHECKSIG. This means: check that the spending transaction's locktime is at least block height ~920,000 (approx Jan 2026). If so, verify the signature normally. Until that block height, any attempt to spend will fail validation. This is provably enforced by every node, no trusted third party needed.

What People Get Wrong

  • Bitcoin can't do smart contracts

    Bitcoin Script enables contracts: multisig, timelocks, hash-time-locked contracts (the basis of Lightning), and more. They're simpler than Ethereum's contracts but they are contracts.

  • Script is just for basic payments

    While 95%+ of transactions are simple transfers, Script powers Lightning Network, atomic swaps, escrow services, vaults, and inheritance planning, all without intermediaries.

  • Script can do anything Ethereum does

    Script is intentionally limited, no loops, limited opcodes, predictable execution. This is a security feature. Complex general-purpose logic requires L2s or sidechains.

Sources & Further Reading

Questions People Also Ask

Why isn't Bitcoin Script Turing-complete?
By design. No loops means every script terminates in bounded time and uses bounded resources. This prevents denial-of-service attacks where someone creates a script that runs forever.
What is P2SH?
Pay-to-Script-Hash (P2SH) lets the sender pay to the hash of a script. The spender reveals the full script only when spending. This simplified complex transaction creation and enabled addresses starting with "3".
Can Script be upgraded?
Yes, through soft forks. SegWit (v0) and Taproot (v1) each introduced new script versions with new opcodes. Future witness versions can add more functionality without breaking backward compatibility.

More in Bitcoin & Base-Layer Fundamentals

See all →
Was this page helpful?

Page last checked