TERM_DEF // MODULE_2_ARITHMETIC / OP_ADD
OP_ADD
OP_ADD. Pop two numbers, push their sum.
OP_ADD pops the top two items from the stack, decodes them as CScriptNum integers, adds them, and pushes the encoded result. Both inputs and the output must fit within 4 bytes. This is the fundamental arithmetic opcode — subtraction, multiplication, and others follow the same pattern.
This page sits in the Module 2 — Arithmetic section — Vocabulary introduced in the Arithmetic module. Read on for what it is, why it exists, how it works under the hood, and what to watch out for.
OP_ADD pops the top two items from the stack, decodes them as CScriptNum integers, adds them, and pushes the encoded result. Both inputs and the output must fit within 4 bytes. This is the fundamental arithmetic opcode — subtraction, multiplication, and others follow the same pattern.
This page sits in the Module 2 — Arithmetic section — Vocabulary introduced in the Arithmetic module. Read on for what it is, why it exists, how it works under the hood, and what to watch out for.
WHAT_OP_ADD_IS
OP_ADD — at a glance
MODULE 2
OP_ADD is a Bitcoin Script opcode in the ARITH family. Its stack effect is
a b → a+b. Sum the top two CScriptNum values (each ≤ 4 bytes). Pop two numbers, push their sum.OP_ADD pops the top two items from the stack, decodes them as CScriptNum integers, adds them, and pushes the encoded result. Both inputs and the output must fit within 4 bytes. This is the fundamental arithmetic opcode — subtraction, multiplication, and others follow the same pattern.
Why it exists
DESIGN
OP_ADD exists because Bitcoin Script needs small integer arithmetic (≤ 4-byte CScriptNum values) for amounts, indices, and comparison results — anything larger is consensus-rejected.
HOW_IT_WORKS
Mechanism
HOW IT WORKS
Every UTXO is locked by a scriptPubKey — the output's locking script. To spend it, you provide a scriptSig (or witness) containing data that satisfies the lock. The node concatenates them, runs the combined script on a stack machine, and accepts the spend if and only if execution finishes with a single truthy value on the stack. OP_ADD contributes a specific stack effect within that process — opcodes either push, pop, copy, hash, branch, or verify, and they do so left-to-right deterministically.
1. The script is parsed into a sequence of opcodes and push-data items.
2. Execution starts with an empty stack and an empty alt-stack.
3. Each opcode runs in order — push opcodes add to the stack, others consume the top items and may push results.
4. When OP_ADD is reached, it performs its specific stack effect (see below).
5. Final state: a single non-zero (truthy) value on top → the spend is authorised. Anything else (empty stack, false, error) → the script fails and the tx is rejected.
WORKED_EXAMPLE
OP_ADD — stack effect + canonical use
EXAMPLE
Opcode : OP_ADD
Family : ARITH
Stack effect: a b → a+b
Behaviour : Sum the top two CScriptNum values (each ≤ 4 bytes).
Open /playground in another tab and search for OP_ADD.
Drag the opcode in, watch the stack visualisation step through it
against any combination of inputs you choose.
KEY_PROPERTIES
FAMILY
Belongs to the ARITH family of Script opcodes — siblings share validation rules and historical evolution.
STACK EFFECT
Exactly a b → a+b. Every full node enforces the same effect, byte-for-byte.
ACTIVE
Active on mainnet today; every spend that uses it is being validated by every full node.
CONSENSUS-CRITICAL
OP_ADD's behaviour is consensus rule — a node implementing it differently would fork off the network.
COMMON_PITFALLS
Things that catch people out
PITFALLS
- Arithmetic operands must encode to ≤ 4 bytes; anything larger fails the script (CScriptNum overflow).
RELATED_CONCEPTS
Other terms from Module 2 — Arithmetic — click any to read its page:
TERMINOLOGY_INDEX
TERMINOLOGY
OP_ADD
Pop two numbers, push their sum.
CScriptNum
Bitcoin's variable-length signed integer encoding.
Minimal push
Consensus rule: use the shortest encoding for a value.