Home › Glossary › Opcode

Opcode

Also called: op code, OP codes, script opcode, Bitcoin opcodes, operation code.

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.

An opcode (operation code) is a single instruction in Bitcoin Script. Each one is encoded as one byte, so there are at most 256, and they are written with an OP_ prefix.

Kinds of opcodes

  • Push opcodes put data on the stack. Bytes 0x01 to 0x4b push that many following bytes; OP_PUSHDATA1, 2 and 4 (0x4c to 0x4e) handle longer data. OP_0 (0x00) pushes an empty value and OP_1 to OP_16 (0x51 to 0x60) push small numbers.
  • Stack and logic: OP_DUP (0x76), OP_EQUAL (0x87), OP_EQUALVERIFY (0x88), OP_IF and its relatives.
  • Crypto: OP_SHA256 (0xa8), OP_HASH160 (0xa9), OP_CHECKSIG (0xac), OP_CHECKMULTISIG (0xae) and, in Tapscript, OP_CHECKSIGADD (0xba).
  • Timelocks: OP_CHECKLOCKTIMEVERIFY (0xb1) and OP_CHECKSEQUENCEVERIFY (0xb2).
  • OP_RETURN (0x6a) marks an output as unspendable.

How new opcodes are added

New opcodes arrive through soft forks. Earlier upgrades redefined do-nothing opcodes: BIP 65 turned OP_NOP2 into CHECKLOCKTIMEVERIFY, BIP 112 turned OP_NOP3 into CHECKSEQUENCEVERIFY, and BIP 119 proposes OP_NOP4 (0xb3) for CHECKTEMPLATEVERIFY. Tapscript (BIP 342) reserved 87 OP_SUCCESSx codes for later use, which newer proposals such as OP_CAT (BIP 347) target.

Some original opcodes, including OP_CAT (0x7e), were disabled in 2010 and make a script fail if they appear in it. The opcodes topic lists BIPs that add or change opcodes, and the opcode reference gives every opcode's byte value and status.

BIPs that define Opcode

  • 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 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 119 (OP_CHECKTEMPLATEVERIFY): CHECKTEMPLATEVERIFY: Draft. Proposes CHECKTEMPLATEVERIFY, a script instruction that restricts coins so they can only be spent in a transaction matching a predetermined template. This 'covenant' could enable vaults that protect…
  • BIP 347: OP_CAT in Tapscript: Complete. Brings back OP_CAT, an instruction that joins two pieces of data together, which was disabled in Bitcoin's early days over security concerns. Re-enabled only inside Taproot scripts, this simple…

Related terms

  • Bitcoin 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.
  • OP_RETURN: OP_RETURN is the Bitcoin Script opcode (0x6a) that makes an output provably unspendable, used to embed small amounts of data in a transaction.
  • Tapscript: Tapscript is the script language for Taproot script paths (BIP 342): Bitcoin Script with Schnorr signature checks, OP_CHECKSIGADD and OP_SUCCESS hooks.
  • OP_CHECKLOCKTIMEVERIFY (CLTV): OP_CHECKLOCKTIMEVERIFY (CLTV, BIP 65) is an opcode that keeps an output unspendable until a chosen block height or time: an absolute timelock.

Learn more

Guides