What is Bitcoin Script
What is Bitcoin Script?
Bitcoin Script is the programming language that controls how bitcoin is locked and unlocked. Every single bitcoin that exists on the blockchain is protected by a small program written in Bitcoin Script. When you want to spend bitcoin, you must satisfy the conditions written in that program. If your answer passes the script, the network lets you spend the coins. If it fails, your transaction is rejected.
Bitcoin Script was designed by Satoshi Nakamoto and included in the very first version of Bitcoin released in January 2009. It is a simple, deliberate, and intentionally limited language — and those limitations are features, not bugs.
The Purpose of Bitcoin Script
Before Script existed, the only way to send bitcoin would be to say "send to this address." That's it. One condition. One type of transaction. Bitcoin Script makes it possible to express a wide variety of spending conditions:
-
"Anyone who can provide the private key to this public key can spend this."
-
"Two out of these three people must sign before these coins move."
-
"Nobody can spend this until block 800,000 is mined."
-
"Whoever knows the secret that hashes to this value can take these coins."
All of these conditions are expressed in Bitcoin Script. The language is what gives Bitcoin its programmable money properties without turning it into a general-purpose computer.
Script is Embedded in Every Transaction
Every Bitcoin transaction has two critical parts: inputs and outputs.
-
Outputs contain a locking script (called
scriptPubKey). This is the condition that must be met to spend the coins. -
Inputs contain an unlocking script (called
scriptSig). This is the answer that satisfies the condition.
When a node validates a transaction, it runs the unlocking script followed by the locking script. If the final result on the stack is true (non-zero), the transaction is valid. If not, it is rejected.
Transaction Output (Locking):
OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
Transaction Input (Unlocking):
<signature> <publicKey>
Combined execution:
<signature> <publicKey> OP_DUP OP_HASH160 <pubKeyHash> OP_EQUALVERIFY OP_CHECKSIG
Script is a Stack-Based Language
Bitcoin Script is not like Python or JavaScript. There are no variables, no loops, no functions you define yourself. Instead, Script uses a stack — a last-in-first-out data structure. Opcodes either push data onto the stack or perform operations on data already sitting there.
This design makes Script predictable and easy to verify. Any node in the world can run a Bitcoin script and get the same result, in the same number of steps, in bounded time.
The Two Layers of Script
Script exists at two levels:
-
The locking script is set by the sender of a transaction. It is baked into the output and recorded on the blockchain forever.
-
The unlocking script is provided by the spender when they want to move those coins. It must satisfy whatever conditions the locking script demands.
This is the fundamental security model of Bitcoin. Coins sit locked by a script program. Only someone who can produce the correct unlocking data can move them. No central server. No database. Just math.
Script vs Smart Contracts
People often compare Bitcoin Script to Ethereum's Solidity smart contracts. The comparison is partly correct but mostly misleading. Ethereum contracts can loop, store state, call other contracts, and run arbitrarily complex logic. Bitcoin Script cannot do any of these things deliberately.
Bitcoin Script is stateless, non-looping, and terminating. Every script runs to completion in a fixed, predictable number of steps. This is what makes Bitcoin Script safe for a decentralized network where thousands of nodes must validate the same scripts independently and reach the same result.
Script is not trying to be a smart contract platform. It is trying to be the most secure, simple, and reliable locking mechanism for the world's hardest money.
TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation: