Home › Glossary › Bitcoin Script

Bitcoin Script

Also called: Script, Bitcoin scripting language, scriptPubKey, scriptSig, locking script.

Bitcoin Script is the simple stack-based language that sets the conditions for spending each output, such as which signatures or timelocks are required.

Bitcoin Script is the small programming language that decides who can spend a coin. Every output carries a locking script (scriptPubKey). To spend it, the spender supplies data in an unlocking script (scriptSig) or witness, and every node runs the two together. The spend is valid only if the script finishes without error and leaves a true value on the stack.

How Script works

Script is stack-based and read left to right. Each opcode is one byte that either pushes data onto the stack or acts on it. A classic P2PKH output is:

OP_DUP OP_HASH160 <20-byte public key hash> OP_EQUALVERIFY OP_CHECKSIG

The spender provides a signature and public key; the script checks that the key hashes to the right value and that the signature is valid.

Script deliberately has no loops, so every script finishes and its cost is predictable. Limits keep validation cheap: stack items of at most 520 bytes, at most 1,000 items on the stacks, and (outside Tapscript) scripts of at most 10,000 bytes with at most 201 non-push opcodes.

How Script has evolved

  • BIP 16 (P2SH) lets an output commit to a script hash, with the script revealed when spending.
  • BIP 65 and BIP 112 turned spare NOP opcodes into timelocks.
  • BIP 141 (SegWit) moved scripts and signatures into the witness and added script versions.
  • BIP 342 (Tapscript) added Schnorr signature checks and OP_SUCCESS upgrade hooks.

Raw Script is easy to get wrong, so wallets increasingly use Miniscript (BIP 379) and output descriptors. Every opcode is listed in the opcode reference.

BIPs that define Bitcoin Script

  • BIP 16 (P2SH): Pay to Script Hash: Deployed. Introduced Pay to Script Hash (P2SH), letting a sender pay to a short fingerprint of spending rules that the recipient reveals only when spending. This shifted the cost and complexity of setups like…
  • BIP 141 (SegWit): Segregated Witness (Consensus layer): Deployed. Defines Segregated Witness (SegWit), which moves signatures into a separate "witness" section of each transaction while remaining compatible with older nodes. This fixed transaction malleability,…
  • BIP 342 (Tapscript): Validation of Taproot Scripts: Deployed. Specifies Tapscript, the updated scripting rules used when a Taproot output is spent through one of its hidden alternative conditions. It switches signature checks to Schnorr, removes some old…
  • BIP 65: OP_CHECKLOCKTIMEVERIFY: Deployed. Adds OP_CHECKLOCKTIMEVERIFY, a script command that keeps coins unspendable until a chosen date or block height. It enables time-locked savings, escrow with deadlines, and payment channels such as…
  • BIP 112: CHECKSEQUENCEVERIFY: Deployed. Introduces CHECKSEQUENCEVERIFY, a script instruction that lets coins be locked until a certain amount of time has passed since they were received. This 'relative timelock' is a key building block…
  • BIP 379: Miniscript: Draft. Miniscript is a structured way of writing Bitcoin scripts, the small programs that define how coins can be spent. It lets software analyze spending conditions, combine them safely, and sign for them…

Related terms

  • Opcode: An opcode is a one-byte instruction in Bitcoin Script, such as OP_CHECKSIG (0xac) or OP_RETURN (0x6a), that pushes data or acts on the stack.
  • Tapscript: Tapscript is the script language for Taproot script paths (BIP 342): Bitcoin Script with Schnorr signature checks, OP_CHECKSIGADD and OP_SUCCESS hooks.
  • P2SH: P2SH (Pay to Script Hash), defined in BIP 16, locks bitcoin to the hash of a script. Its addresses start with 3, and it carried most early multisig.
  • Miniscript: Miniscript is a structured way to write Bitcoin Script, specified in BIP 379, that makes complex spending conditions easy to analyze, combine and sign.

Learn more

Guides