📖 Term 🟢 Plain English 🔰 Beginner

📜 Bitcoin Script Bitcoin Script

A small programming language built into Bitcoin that sets the rules for spending each coin. Think of it as a lock attached to your money and the key that opens it: the rule decides who is allowed to spend, and the network only checks that the rule was satisfied.

💡
Common misconception — Bitcoin has no programming layer? Not true! Bitcoin has had Script since the start. It is kept deliberately simple for safety, but it still powers real contracts like multi-signature wallets and timelocks.
🔑 Unlocking scriptscriptSig / witness — your proof✍️signature + public key (the key)🔒 Locking scriptscriptPubKey — the rule on the coin📜"only the matching key may spend"🧮One shared stackrun unlocking, then locking — push & pop✅ top item TRUE → coins move  ·  ❌ else → rejected
🔑 Your key and 🔒 the coin's rule both run over 🧮 one shared stack. If the top ends up ✅ TRUE the coins move; otherwise ❌ the spend is rejected. The network checks the rule, not who you are.

🔐 The simple version — a lock and its key

Every time Bitcoin is sent, the coins arrive carrying a small program that says how they may be spent next. That program is the locking script (its technical name is scriptPubKey) — usually it means "only the owner of this address can spend me." To move those coins later, you provide an unlocking script (called scriptSig, or the witness in modern transactions) that contains your digital signature and public key. If the key fits the lock, the spend is valid. It works like a vending machine: the machine has a rule, you feed in what the rule asks for, and it does not care who you are as long as the rule is met.

🧮 How a node actually checks it

Script is stack-based, which is a tidy way of saying it works through a list of instructions one at a time, putting values onto a pile and taking them off the top (last in, first out). When you try to spend, a node runs your unlocking script first, then the locking script, over the same pile. If the run finishes with no errors and leaves a "true" value on top, the coins are allowed to move. If anything fails, the spend is rejected and your coins stay put.

PieceWhat it does
🔒 Locking script (scriptPubKey)Sets the spending condition — the lock attached to the coins
🔑 Unlocking script (scriptSig / witness)Provides the signature and key that satisfy the lock
🧮 The stackThe scratch pad where the node pushes and pops values to test the rule

🛡️ Why it is kept deliberately simple

Script has no loops, no recursion, and no memory that carries over between runs. In plain terms, it cannot run forever and it cannot do open-ended computation. That sounds like a weakness, but it is a safety choice: every script finishes fast, so nobody can jam the network with a program that never ends — a common shape of denial-of-service attack. The outcome of a spend is also easy to predict because the rules are small and fixed.

🧩 The real contracts it enables

Even with those limits, Script is enough to build genuine programmable money. These are what people mean by "Bitcoin smart contracts":

  • 🖊️ Multi-signature — coins that need several keys to spend, such as 2 of 3, used for shared treasuries and escrow (see multisig wallet)
  • Timelocks — coins that cannot be spent until a set time or block, useful for vesting and escrow
  • Hashed Timelock Contracts (HTLCs) — the building block behind the Lightning Network and cross-chain swaps

🌿 The Taproot upgrade (activated November 2021) added Schnorr signatures and a feature called Tapscript/MAST, which let complex Script contracts look like ordinary payments — more private and more efficient.

❓ FAQ

So Bitcoin can't do smart contracts?
It can, just in a limited way. Bitcoin has had Script since day one, and it powers real programmable spending like multi-signature wallets, timelocks, and the contracts behind the Lightning Network. It is kept deliberately simple rather than being unable to do contracts at all.
Why was Bitcoin Script made so limited on purpose?
Safety and predictability. Script has no loops and no way to run forever, so every script finishes quickly. That stops an attacker from clogging the network with a script that never ends, and it makes the outcome of a spend easy to predict.
Do I ever write Bitcoin Script myself?
Almost never. Your wallet builds the locking and unlocking scripts for you behind the scenes every time you receive or send Bitcoin. You only meet Script directly if you set up something advanced like a multi-signature wallet or a timelock.

🔗 Related