A Bitcoin transaction does not ask a central administrator whether a sender is allowed to move coins. It supplies evidence that can be checked against the conditions attached to the output being spent. One of the mechanisms behind that check is surprisingly compact: a script interpreter working through an ordered stack of data.

Understanding the stack helps demystify error messages and transaction diagrams. It does not mean ordinary wallet users should write their own spending scripts. The useful lesson is that authorization depends on how the supplied pieces fit together, not merely on whether a transaction contains something labeled a signature.

A working pile of data

Bitcoin Core describes Script as a stack machine that evaluates a condition, without loops. Its interpreter represents stack entries as byte arrays and implements operations that read, add, remove or rearrange those entries. The stack is temporary working data for evaluation, not a second ledger holding bitcoin. Bitcoin Core’s interpreter

An everyday analogy is a pile of cards on a desk. Putting a new card on top changes which card the next instruction encounters. Copying or removing a card changes the pile again. The analogy concerns order and manipulation, not the security of the underlying cryptography.

That distinction matters when looking at a script trace. A list of the correct ingredients is not necessarily the correct input. Their position and the operations that consume them are part of the construction.

Follow one familiar example

The Bitcoin developer guide illustrates a legacy pay-to-public-key-hash, or P2PKH, spend. The spender supplies a signature and public key. The output’s script duplicates the public key, hashes the duplicate and compares that hash with the value committed by the earlier output. It then checks the signature against the remaining public key and the relevant transaction data. P2PKH evaluation

The sequence serves two distinct purposes: connect the provided key to the earlier output, then test the spending authorization. A signature associated with some other key does not satisfy those conditions just because it is a genuine signature.

In this example, the duplication instruction preserves a copy for the later signature check while the hash operation consumes the other copy. The stack makes that intermediate bookkeeping explicit. This is a historical transaction form used as a teaching example, not a claim that every modern wallet transaction uses this exact script.

Missing data is not a cryptographic mystery

The interpreter checks that operations have enough stack entries to work with. For example, an instruction requiring two items cannot sensibly run on a pile containing only one. A stack-operation failure can therefore occur before a signature is evaluated at all. Interpreter operation checks

For troubleshooting, that suggests an order of questions. Was the expected spending form identified? Were its required data items supplied? Were those items serialized and arranged correctly? Only then does it make sense to focus exclusively on whether the signature itself is right.

These questions are diagnostic, not a recovery recipe. Do not change a real transaction’s script by trial and error or send funds to an experimental construction simply because an online demonstration appears to work.

Witness data changes the packaging

Segregated Witness adds another distinction. BIP141 says witness data is serialized as a collection of stack items, not as a script to execute directly. For a version-zero pay-to-witness-script-hash spend, the final witness item supplies the script; the remaining items provide its initial input stack. The script’s hash must match the output’s commitment, and successful execution must leave a single true result. BIP141 witness rules

This separates the program from the data fed into it. Seeing an item in a witness field does not mean that its bytes are instructions. Its role depends on the applicable spending construction.

For readers comparing transaction displays, “script,” “witness” and “stack” are consequently not interchangeable labels. One describes instructions, another describes a transaction-data structure, and another describes the interpreter’s working state.

The version still matters

Taproot script-path spends using leaf version 0xc0 follow the tapscript rules defined by BIP342. Those rules modify signature instructions and impose their own execution and resource requirements. Ordinary execution must finish with exactly one true stack element, while the specification also defines special upgrade mechanisms that cannot be understood by transplanting older script assumptions. BIP342

The practical conclusion is modest: always identify which rules apply before interpreting a trace. A stack diagram explains one layer of validation, not whether the whole transaction is valid, confirmed or economically sensible. Treat it as a map of how evidence is checked, rather than a shortcut around the wallet and consensus rules that give that evidence meaning.