Friday, October 23, 2026
Learn / Bitcoin

What is Bitcoin Script and how does it work?

Bitcoin Script is the simple, stack-based language that sets the conditions for spending bitcoin. It is deliberately limited, with no loops, unlike Ethereum.

Bitcoin Illustration: Cryptoweek

Bitcoin Script is the scripting language Bitcoin uses to lock and unlock coins. Every transaction output carries a small script that sets spending conditions, and whoever wants to spend it must supply data that satisfies those conditions. Most of the time it simply checks a signature, but it can also express multisig, time locks and other rules.

How does the Bitcoin scripting language work?

The Bitcoin Wiki describes Script as a Forth-like, stack-based language processed from left to right. Data and instructions are pushed onto a stack, and each instruction acts on the items at the top.

A spend is valid only if, after the spender's data and the output's script run together, the result left on top of the stack is true. The output's conditions might require one key, several keys, or none at all.

Script is intentionally not Turing-complete and has no loops. That keeps validation predictable, because every node on the network must run the same checks on every transaction. Each output it protects is a UTXO, and spending one means satisfying its script.

What is a Bitcoin script example?

The classic example is pay-to-public-key-hash (P2PKH). The locking script on the output reads:

OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG

To spend it, the owner supplies a signature and a public key. The script duplicates the public key, hashes it, checks that the hash matches the one in the output, and then checks the signature. If both match, the coins can move. Newer formats like SegWit and Taproot move this data around, but the idea of meeting script conditions stays the same.

What are Bitcoin Script opcodes?

Opcodes are the individual instructions. The Bitcoin Wiki groups them into categories such as constants, flow control, stack operations, arithmetic, cryptography and locktime.

A few notable ones:

  • OP_CHECKSIG verifies a signature against a public key.
  • OP_CHECKLOCKTIMEVERIFY (BIP 65) and OP_CHECKSEQUENCEVERIFY (BIP 112) let outputs be locked until a time or block height, or for a relative period.
  • OP_RETURN marks an output as unspendable so it can carry a small amount of data.

Some early opcodes, including OP_CAT and OP_MUL, were disabled over concerns about bugs. BIP 342, which defines tapscript for Taproot, replaced OP_CHECKMULTISIG with a new OP_CHECKSIGADD, switched signature checks to Schnorr signatures, and reserved "OP_SUCCESS" codes so future soft forks can add features more safely.

How does Bitcoin scripting compare with Ethereum smart contracts?

The difference is scope. Bitcoin Script mostly answers one question: can this output be spent? It keeps little state and cannot loop.

Ethereum's documentation describes the Ethereum Virtual Machine as able to execute arbitrary code, with gas charged for each operation to meter computation. Contracts store persistent state and can call each other. That flexibility enables lending, exchanges and other smart contracts, but it also creates a larger surface for bugs. Bitcoin's design trades flexibility for simplicity and predictable validation.

This guide explains how things work. It is not financial, legal or tax advice. Last updated .