Skip to main content

Opcode | Bitcoin Glossary | Mapping Bitcoin

Opcode

Protocol

Also known as: operation code, script opcode

An instruction in Bitcoin Script defining a single stack operation. Bitcoin has over 100 opcodes for hashing, arithmetic, signatures, and flow control.

Overview

An opcode (operation code) is a single instruction in Bitcoin Script, the stack-based programming language used to define spending conditions for bitcoin. Each opcode performs a specific operation, such as pushing data onto the stack, performing arithmetic, checking cryptographic signatures, or controlling program flow. Opcodes are the fundamental building blocks of all Bitcoin transaction logic.

Categories of Opcodes

┌──────────────────┬──────────────────────────────┐
│    Category       │    Examples                   │
├──────────────────┼──────────────────────────────┤
│ Constants        │ OP_0, OP_1, OP_PUSHDATA      │
│ Flow control     │ OP_IF, OP_ELSE, OP_ENDIF     │
│ Stack            │ OP_DUP, OP_DROP, OP_SWAP     │
│ Arithmetic       │ OP_ADD, OP_SUB, OP_EQUAL     │
│ Crypto           │ OP_HASH160, OP_CHECKSIG      │
│ Locktime         │ OP_CHECKLOCKTIMEVERIFY       │
│ Special          │ OP_RETURN, OP_NOP             │
│ Disabled         │ OP_CAT, OP_MUL (security)    │
└──────────────────┴──────────────────────────────┘

How Opcodes Execute

Bitcoin Script is a stack-based language. Data is pushed onto a stack, and opcodes pop values from the stack, perform operations, and push results back.

Example: Verify a signature (simplified P2PKH)

Stack:        Script:
              <sig> <pubKey> OP_DUP OP_HASH160
              <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG

Step 1: Push <sig>           Stack: [sig]
Step 2: Push <pubKey>        Stack: [sig, pubKey]
Step 3: OP_DUP               Stack: [sig, pubKey, pubKey]
Step 4: OP_HASH160            Stack: [sig, pubKey, hash]
Step 5: Push <pubKeyHash>   Stack: [sig, pubKey, hash, pubKeyHash]
Step 6: OP_EQUALVERIFY        Stack: [sig, pubKey] (hashes match)
Step 7: OP_CHECKSIG           Stack: [TRUE] ← Valid spend!

Disabled Opcodes

Several opcodes were disabled early in Bitcoin's history by Satoshi Nakamoto due to security concerns, including OP_CAT (concatenate), OP_MUL (multiply), and OP_LSHIFT. Some of these are subjects of ongoing re-enablement proposals in the Bitcoin development community.

Common Misconceptions

Bitcoin Script is intentionally not Turing-complete — it lacks loops and unbounded computation. This is a security feature, not a limitation. It ensures that script validation always terminates and has predictable resource usage, preventing denial-of-service attacks against nodes.