Essential Points
- Bitcoin Script is a stack language that reads from left to right and decides whether a Bitcoin output can be spent.
- The scriptPubKey sets the spending conditions, and the scriptSig or witness provides the data that meets them.
- It has no loops and is not Turing complete, and consensus limits restrict the cost of validating each script.
- P2SH, SegWit, and Taproot changed where that data lives, and Tapscript added OP_CHECKSIGADD and removed two limits.
Bitcoin Script is a stack-based programming language in which each transaction output determines who can spend it and what they must provide to do so. No central server decides whether a payment is valid: each node executes the script and verifies that it ends with a true result. According to the Bitcoin Core codeA script prior to Taproot cannot exceed 10.000 bytes or 201 non-data push operations, so its validation cost is limited beforehand.
The design is intentionally austere. Script reads from left to right, has no loops, and doesn't save state between executions, so no program can get stuck or query data from other transactions. With such strict rules, payments to a single key, multiple signatures, locks until a certain date, and conditions that are only revealed upon spending are all possible, and everything has worked on the same network since the software's earliest versions.
Understanding its components allows you to open a transaction in a block explorer and see why the network accepted it. It also explains why Script has changed so much since its inception, with opcodes disappearing in 2010 and signatures now traveling in a separate field called a witness.
What is Bitcoin Script and how does the stack work?
A script is a short list of data and instructions that each node traverses from left to right. Each element contributes data to the stack or transforms what is already on it, and at the end the transaction is valid if nothing has failed and a true, non-zero value remains at the top, according to the bitcoin wiki.
The stack works like a stack of plates: the last one you put in is the first one you remove, a rule known as LIFO (Last In, First Out). If you put in a signature and then a public key, the next operation will find the public key at the top. There is also an alternative stack for intermediate results, similar to the memory key on a calculator.
Script doesn't have loops or function calls, and that's why it's not Turing completeIt only supports sequences that progress and terminate. It does have conditional statements with OP_IF and OP_ELSE, which choose between two paths without backtracking. An endless script would allow blocking nodes with a denial of service attackAnd since each instruction is executed only once, a node calculates the maximum work before starting.
What are scriptPubKey and scriptSig?
Every transaction output carries a lock script, and every input that spends it contains data that unlocks it. The scriptPubKey is the lock script: it resides in the output and sets the conditions for spending it. The scriptSig is the unlock script: it resides in the input that spends a UTXOThat is, an exit without spending, and provides the data that meets those conditions, such as a signature.
The two scripts do not execute simultaneously: the node first processes the data from the scriptSig and then executes the scriptPubKey on the resulting stack. The scriptPubKey does not always contain a public key hash, because that only occurs in P2PKH, and other types require a script hash, a direct key, or multiple signatures. Therefore, it is best to define them generally: the scriptPubKey establishes the rules, and the scriptSig, or the witness in SegWit and Taproot, provides the data that satisfies them.
With SegWit, the unlocking data for new outputs is transferred to a dedicated field called witness, and the scriptSig is left empty in native SegWit outputs, according to the BIP-141Taproot, defined in the BIP-341It maintains that distribution and adds two spending paths that are explained below.

What is an OP_CODE and what operations does it allow?
An OP_CODE is a byte that Script interprets as a command that operates on the stack, for example, duplicating the top element or comparing the last two. The general definition of an opcode, common to any processor, can be found in the guide on... What is an OP_CODE?In Bitcoin, what matters is which orders exist and which ones the network no longer accepts.
A byte holds 256 values, but not all of them are named instructions: 0x01 to 0x4b indicate how many bytes of data are pushed onto the stack, and the file Bitcoin Core script.h It defines about 113 named values as of October 31, 2026. Of these, 15 are disabled: in scripts prior to Tapscript, a script containing one fails even if the opcode is in a branch that is not executed, and unassigned values cause the script to fail when executed.
The table groups opcodes by families, using the names used in the Bitcoin Core code, and its examples are not intended to exhaust each family or replace the complete Bitcoin Wiki reference.
| Family | Examples | What do they do |
|---|---|---|
| Constants and data | OP_0, OP_1 to OP_16, OP_PUSHDATA1 | They place numbers or data on the stack |
| Flow control | OP_IF, OP_ELSE, OP_ENDIF, OP_VERIFY, OP_RETURN | They choose a path or cause the script to fail. |
| Pila | OP_DUP, OP_DROP, OP_SWAP, OP_TOALTSTACK | They copy, delete, and rearrange elements |
| Comparison | OP_EQUAL, OP_EQUALVERIFY | They compare the two top elements |
| Arithmetic | OP_ADD, OP_SUB, OP_NUMEQUAL, OP_WITHIN | They operate with integers up to 4 bytes |
| Cryptography | OP_SHA256, OP_HASH160, OP_CHECKSIG, OP_CHECKMULTISIG | They calculate hashes and verify signatures |
| Time blocking | OP_CHECKLOCKTIMEVERIFY, OP_CHECKSEQUENCEVERIFY | They prevent spending before a certain time |
| Disabled (15) | OP_CAT, OP_MUL, OP_LSHIFT and 12 others | They cause the script to fail if they appear |
| Reserved and unused | OP_RESERVED, OP_VER, OP_NOP1, OP_NOP4 to OP_NOP10 | They do nothing or are invalid if executed |
Those 15 opcodes weren't disabled from the start. In 2010, after several bugs were discovered, operations that hardly anyone used, such as OP_MUL, OP_CAT, and OP_LSHIFT, were deactivated. bitcoin wiki The OP_LSHIFT vulnerability is recorded as CVE-2010-5137: on July 28, 2010, it was demonstrated that processing this operation could block a node, it was fixed in version 0.3.5 and was never exploited on the main network.
The two time-lock opcodes occupy the codes that were formerly OP_NOP2 and OP_NOP3, and arrived via a soft fork with the BIP-65 and the BIP-112The first blocks until a certain date or block height, and the second until a relative amount of time has passed, based on the field nSequenceThe guide on time lock Explain the concept.
How do you run a P2PKH script step by step?
Payments to classic addresses, those starting with 1, use a standard script called P2PKH, acronym for Pay to Public Key Hash. According to the bitcoin wikiIts scriptPubKey is OP_DUP OP_HASH160 followed by the public key hash, OP_EQUALVERIFY and OP_CHECKSIG, and its scriptSig contains a signature and the public key. Bitcoin address It contains that hash, and that's why the script doesn't need to name anyone.
Four opcodes do all the work in this script, and each has a specific function that's best understood by thinking in terms of the stack rather than the script text. After loading the scriptSig data, the execution order is as follows:
- OP_DUP copies the top element of the stack, the public key, to have two copies.
- OP_HASH160 applies SHA-256 and then RIPEMD-160 to the copy above. It's a hashnot a code that can be undone.
- OP_EQUALVERIFY compares that hash with the expected one, which is in the scriptPubKey, and makes the script fail if they are not equal.
- OP_CHECKSIG checks that the signature is valid for a transaction summary and for the public key, and leaves true or false.
The table shows the stack state after each element, with the bottom on the left and the top on the right. The values are for illustrative purposes, because an actual signature and key occupy tens of bytes and contribute nothing to the reasoning.
| Step | Processed element | Stack after |
|---|---|---|
| 1 | company | company |
| 2 | public key | signature, public key |
| 3 | OP_DUP | signature, public key, public key |
| 4 | OP_HASH160 | signature, public key, calculated hash |
| 5 | expected hash | signature, public key, calculated hash, expected hash |
| 6 | OP_EQUALVERIFY | signature, public key |
| 7 | OP_CHECKSIG | true |
Until you spend the output, the public key doesn't appear in the chain because the address only contains its hash. Without the private key, there's no practical way to produce a valid signature, which is why the final step protects the funds.

What types of scripts exist in Bitcoin?
Over the years, Bitcoin has added standard ways to lock funds, and each one changes what the scriptPubKey stores and where the proof of unlock is stored. The table summarizes six of them, according to the Bitcoin Wiki and BIP-16, 141, and 341.
| Type | scriptPubKey Schema | What does the spender contribute? | Where is it going? |
|---|---|---|---|
| P2PK | public key, OP_CHECKSIG | A sign | scriptNext |
| P2PKH | OP_DUP OP_HASH160 key hash, OP_EQUALVERIFY OP_CHECKSIG | Signature and public key | scriptNext |
| P2SH | OP_HASH160 script hash, OP_EQUAL | Data and the complete script | scriptNext |
| P2WPKH | OP_0 and 20-byte hash of the key | Signature and public key | Witness |
| P2WSH | OP_0 and 32-byte hash of the script | Data and the complete script | Witness |
| P2TR | OP_1 and 32-byte public key | A Schnorr signature, or a script with its proof | Witness |
P2SH, defined in the BIP-16 And applied since April 1, 2012, it shifts the responsibility for the conditions to the spender: the output only contains the hash of a script, and when it is spent, the complete script, called the redeem script, is delivered, containing the data that satisfies it. Thus, a sender can pay a complex condition with a fixed 20-byte hash, as explained in the guide on P2SH.
Classic multi-signature encryption uses OP_CHECKMULTISIG, which supports up to 20 keys and, due to a historical bug, removes one extra element from the stack, so unlocking starts with a padding value. This is the mechanism of the multi-signature addresseswhich are usually wrapped in P2SH or P2WSH.
What do SegWit, Taproot, and Tapscript offer?
followedIntroduced as a soft fork with BIP-141, it separated signatures from the rest of the transaction and opened the door to new script versions. An output is a witness program if its scriptPubKey is a version push followed by a push of between 2 and 40 bytes. Version 0 covers P2WPKH and P2WSH, and versions 1 through 16 were reserved for future improvements.
tap root It uses version 1 and has been active since block 709.632, according to BIP-341 and the Bitcoin Core 0.21.1 notes. A P2TR output contains a 32-byte public key and is spent in two ways: via the key path, with a single Schnorr signature (BIP-340), or via the script path, revealing one of the scripts in a Merkle tree along with proof of its origin. If everyone cooperates, the spending appears as a single-signature payment and reveals no other conditions.
Tapscript, described in the BIP-342This governs the script path. It maintains the stack model, but OP_CHECKSIG checks Schnorr signatures, OP_CHECKMULTISIG is disabled and replaced by OP_CHECKSIGADD, and the 10.000-byte and 201-opcode limits are no longer enforced. Disabled and unassigned opcodes are renamed OP_SUCCESSx and validate the script, a mechanism reserved for future soft forks, so using them today is not safe.

What are the consensus limits of Bitcoin Script?
The fact that Script doesn't have loops isn't enough to limit the cost of validating a transaction, and that's why the protocol adds consensus limits: a block that violates them is invalid, unlike relay policies, which each node adjusts. The table shows the four from the code of Bitcoin Core as of October 31, 2026.
| Limit | Price | What is it for | Which scripts does it apply to? |
|---|---|---|---|
| Script size | 10.000 bytes | Avoid huge scripts that force the processing of data without measure. | Legacy and SegWit version 0, not Tapscript |
| Non-push opcodes | 201 per script | Limit the number of operations for each validation | Legacy and SegWit version 0, not Tapscript |
| Size of an element | 520 bytes | Avoid placing giant data in a single position in the stack. | All |
| Elements in the stacks | 1.000 between the main and the alternative | Limit the memory used by the execution | All |
These limits date back to 2010. On July 31 of that year, version 0.3.7 included a c, signed by Satoshi Nakamoto and uploaded by Gavin Andresen, whose title speaks of "additional security limits": he reduced the maximum size of a script from 20.000 to 10.000 bytes and limited non-push operations, a limit that is now 201.
Can smart contracts be created in Bitcoin?
Yes, provided that by smart contract you understand a spending condition that the network validates without intermediaries, and not a general-purpose program. A multi-signature contract that requires two out of three keys, or an output that can only be spent after a certain block, are examples. smart contracts in that restricted sense.
Ethereum is taking a different path. According to ethereum.org, the EVM executes arbitrary code on a shared global state, and the gas It measures the effort of each operation to prevent accidental or hostile loops, while Script is stateless between executions and controls the cost with consensus limits.
| Appearance | Bitcoin Script | Ethereum EVM |
|---|---|---|
| Loops | They do not exist | They exist, and the gas limits how much calculation is possible |
| State between executions | None | Shared global state |
| How is the cost limited? | Script consensus limits | Gas per operation, with a limit per transaction |
| Usual use | Spending conditions: signatures, time blocks, and hashes | Programs with their own logic that store data |
Neither approach is inherently better, because they serve different purposes, as the guide explains. EthereumA reduced language reduces the attack surface, but does not eliminate implementation flaws, as demonstrated by CVE-2010-5137.
Current state of Bitcoin Script
Tapscript and OP_CHECKSIGADD are active since Taproot, and the four consensus limits in the table above remain unchanged in the Bitcoin Core code as of October 31, 2026. Proposals to extend Script are discussed as BIPs, and neither of the two cited below are active.
Bitcoin Core 30.0, released on October 10, 2025, increased the default value of datacarriersize to 100.000 bytes, effectively eliminating the previous 83-byte cap, and allowed multiple OP_RETURN exits per transaction, according to the Version 30.0 notesIt's a relay and mining policy, not a consensus rule: each node sets its own value, for example, datacarriersize=83 to return to the previous limit. The guide on Bitcoin Core and Bitcoin Knots Compare how two programs manage these filters.
El BIP-347 It proposes returning OP_CAT to Tapscript and is listed as complete since March 1, 2026, but that status describes the specification and not an activation. BIP-119 OP_CHECKTEMPLATEVERIFY is proposed, which changes the meaning of OP_NOP4, and is listed as a draft. No primary source sets activation dates, and any circulating schedule is speculation. Furthermore, according to docs.ordinals.com, the inscriptions of Bitcoin Ordinals They store their content in Taproot scripts.
A small language that you can read in any transaction
All of the above can be verified without installing anything: open a transaction in a block explorer, look for the scriptPubKey in its outputs and the scriptSig or witness in its inputs, and you'll recognize its script type. If you want to repeat the test with a small transaction of your own, you can consult the bitcoin price Before moving funds, remember that the value of crypto assets changes rapidly and that a confirmed transfer cannot be reversed.
Script will remain small by design. Current proposals, such as OP_CAT or CTV, will have to go through the same process. BIP process and by activation via soft fork, as happened with P2SH, SegWit and Taproot.



Author


