What is Bitcoin Script? Understanding Bitcoin Programming Language
Discover Bitcoin Script, the stack-based programming language powering every Bitcoin transaction. Learn opcodes, script types, and how Bitcoin is programmable.
Uvin Vindula — IAMUVIN
Published 2026-04-05
What is Bitcoin Script? The Programming Language of Bitcoin
Every Bitcoin transaction is powered by a simple but powerful programming language called Bitcoin Script. While most people think of Bitcoin as just digital money, under the hood, every single transaction is actually a small program that defines the conditions under which funds can be spent. Understanding Script gives you a deeper appreciation of how Bitcoin actually works.
Bitcoin Script Fundamentals
Bitcoin Script is a stack-based, Forth-like programming language that is intentionally limited in scope. It was designed by Satoshi Nakamoto with security as the top priority.
Key Characteristics
- Stack-based: Operations push and pop values from a stack data structure, similar to Reverse Polish Notation (RPN) calculators.
- Not Turing-complete: Script deliberately lacks loops and recursion, preventing infinite execution and denial-of-service attacks.
- Stateless: Each script execution is independent; scripts cannot access external data or previous transaction states.
- Deterministic: Given the same inputs, a script always produces the same result on every node in the network.
How Bitcoin Transactions Use Script
Every Bitcoin transaction has two key script components:
ScriptPubKey (Locking Script)
This is the "lock" placed on Bitcoin when it is received. It defines the conditions that must be met to spend the funds. When someone sends you Bitcoin, the transaction output contains a ScriptPubKey that typically says: "Only the person who can prove ownership of this public key can spend these funds."
ScriptSig (Unlocking Script)
This is the "key" provided when spending Bitcoin. It contains the data (usually a digital signature and public key) that satisfies the conditions set by the ScriptPubKey.
Script Execution
When a transaction is validated, the ScriptSig and ScriptPubKey are combined and executed together. If the combined script evaluates to TRUE, the transaction is valid, and the funds can be spent. If it evaluates to FALSE, the transaction is rejected.
Common Bitcoin Script Types
P2PKH (Pay-to-Public-Key-Hash)
The original and most common transaction type. The locking script requires a signature matching a specific public key hash. Addresses start with "1".
Script structure: OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
P2SH (Pay-to-Script-Hash)
Allows funds to be locked to the hash of an arbitrary script, enabling complex spending conditions like multisig. Addresses start with "3".
P2WPKH (Pay-to-Witness-Public-Key-Hash)
SegWit version of P2PKH. Moves signature data to the witness section, reducing transaction size and fees. Addresses start with "bc1q".
P2TR (Pay-to-Taproot)
The newest type introduced with Taproot. Uses Schnorr signatures and allows complex scripts to look like simple payments, improving privacy. Addresses start with "bc1p".
Important Bitcoin Script Opcodes
| Opcode | Function |
|---|---|
| OP_DUP | Duplicates the top stack item |
| OP_HASH160 | Hashes top item with SHA-256 then RIPEMD-160 |
| OP_EQUALVERIFY | Checks if top two items are equal; fails if not |
| OP_CHECKSIG | Verifies a digital signature against a public key |
| OP_CHECKMULTISIG | Verifies multiple signatures (for multisig) |
| OP_RETURN | Marks output as unspendable; used for data storage |
| OP_IF / OP_ELSE | Conditional execution branching |
| OP_CHECKLOCKTIMEVERIFY | Time-locks funds until a specific block height or time |
| OP_CHECKSEQUENCEVERIFY | Relative time-lock based on sequence numbers |
Practical Script Examples
Simple Payment
A standard P2PKH transaction works as follows:
- The sender creates a ScriptPubKey:
OP_DUP OP_HASH160 <hash> OP_EQUALVERIFY OP_CHECKSIG - The recipient provides a ScriptSig:
<signature> <publicKey> - The network executes both scripts together and verifies the signature matches.
2-of-3 Multisig
A multisig script requires multiple signatures to spend funds: OP_2 <pubKey1> <pubKey2> <pubKey3> OP_3 OP_CHECKMULTISIG
This requires any 2 of the 3 key holders to sign. This is commonly used for business accounts, escrow services, and enhanced security setups.
Time-Locked Transaction
Using OP_CHECKLOCKTIMEVERIFY, you can create transactions that cannot be spent until a specific time. This is used in Lightning Network payment channels, inheritance planning, and vesting schedules.
Bitcoin Script and Smart Contracts
While Bitcoin Script is not as expressive as Ethereum's Solidity, it enables several types of smart contracts:
- Multi-signature wallets: Requiring multiple parties to approve transactions.
- Time-locked contracts: Funds that unlock at a future date.
- Hash Time-Locked Contracts (HTLCs): The foundation of the Lightning Network and atomic swaps.
- Escrow services: Trustless escrow using 2-of-3 multisig.
For developers in Sri Lanka interested in Bitcoin programming, understanding Script is the foundation. Check our learning resources for developer-oriented guides and our tools section for script debugging tools.
Learning Bitcoin Script
If you want to explore Bitcoin Script hands-on, consider using Bitcoin's testnet or regtest mode, where you can experiment without risking real funds. Tools like btcdeb (Bitcoin Script debugger) allow you to step through script execution instruction by instruction.
Disclaimer: This article is for educational purposes only. Interacting with Bitcoin Script directly requires advanced technical knowledge. Always test on testnet before using mainnet. This is not financial advice.

By Uvin Vindula — IAMUVIN
Sri Lanka's leading Bitcoin educator. Author of "The Rise of Bitcoin".
Learn more →Related Articles
The Bitcoin Brief: LK
Weekly Bitcoin insights, market analysis, and Sri Lanka crypto news. Join 1,000+ readers.
Unsubscribe anytime · Educational content only