How does the mechanism work?

Script works with a stack of byte strings. Data pushes place values on the stack; opcodes inspect or transform stack items. Some opcodes compare values, some check hashes and others verify signatures. Successful evaluation must satisfy the rules for the relevant spending construction. Legacy scripts, version-0 witness scripts and Taproot scripts do not share every detail.

A familiar public-key-hash condition duplicates a supplied public key, hashes it, checks the hash against the output’s commitment and then verifies a signature. These operations connect the revealed key with the condition set by the earlier output. Merely putting a signature somewhere in the transaction does not establish that it matches the required key or signed message.

Addresses help interfaces construct standard output scripts. Script remains the mechanism that states spending conditions. A script-hash output commits to another script, which the spender later reveals and satisfies. That extra level means the visible receiving address need not list every signer, delay or alternative encoded in the eventual spending condition.

Stack values are encoded byte strings even when an explanation displays them as convenient integers. Numeric opcodes interpret their arguments under specific encoding and size rules. A hand-written expression that looks sensible in ordinary arithmetic can fail those rules or behave differently under a different script version. For learning, draw the stack before and after each opcode and name which values it consumes. For real transaction construction, consult the exact specification and tested tooling. This distinction lets a small arithmetic example explain execution without suggesting that it covers signature hashing, script-version changes or every consensus limit on an actual spend.

How does Script decide whether an output can be spent?Script expresses conditions that a spending input must satisfy. Nodes execute the applicable script rules with the supplied data and reject a spend when those conditions fail. It is a validation language, not an account ledger.Output commits conditionInput supplies argumentsNode executes the rules
The earlier output defines the condition. The later input supplies data to satisfy it.

How do the protocol numbers work in an example?

Begin with a deliberately non-payment arithmetic illustration: OP_2 OP_3 OP_ADD OP_5 OP_EQUAL. The first two opcodes push the integers 2 and 3. OP_ADD removes them and pushes 5. OP_5 pushes another 5. OP_EQUAL compares the top items and leaves true. This shows stack evaluation without creating a real destination or requiring a secret.

Now inspect a real witness script shape: OP_0 followed by a push of a 20-byte public-key hash. Its serialized output script is 22 bytes: a version opcode, a length byte and the program. Spending this version-0 key-hash output supplies the signature and public key in the witness. The rules reconstruct and evaluate the appropriate signature-checking condition.

The arithmetic example is not a safe wallet template. Anyone could satisfy an output with an unconditional public arithmetic result. The distinction matters: a script evaluating to true is useful only if the condition corresponds to the authority you intended. A node enforces the written condition, not an explanation of what its author hoped it would mean.

An arithmetic stack before and after additionPush 2, then push 3: 3 is on top of 2. OP_ADD consumes both values and leaves 5. This public arithmetic condition is not a secure payment script.Before OP_ADDAfter OP_ADD3: top25: top2 + 3 → 5
The diagram follows the worked example. Sample heights and amounts illustrate the sourced rules.

Common misunderstandings

Script does not fetch a web page or ask a company to approve a payment. Validation must derive its result from the transaction, relevant outputs and protocol context. External promises do not become enforceable conditions merely by being described next to an address.

A valid address checksum does not establish that a hidden script is recoverable by you. With script commitments, retain the script and required recovery information as well as keys. Losing the committed script can matter even when a public explorer still shows an unspent output.

Do not mix opcode meanings from different script versions. Taproot adds its own execution rules and signature behaviour. A legacy multisig template cannot be transplanted into a new version and assumed to retain identical semantics. First identify the output type and the rules used for the eventual spend.

Check yourself

If an output’s condition is easy for anyone to satisfy, will nodes restrict spending to its creator anyway?

Reveal the answer

No. Nodes check the actual spending condition. They do not infer ownership intentions beyond that condition. This is why the arithmetic demonstration is not a payment recipe.

What does this diagram leave out?

This introduction does not provide an interpreter or deployable spending script. Signature-hash rules, numeric encodings, resource limits and the chosen script version are essential to a real construction. The linked specifications define them.