Live · Sun, Aug 16, 2026 · 12:01 UTC Block 843,917 Fees 14 sat/vB Fear & Greed 72 · Greed
Newsletter Pro Terminal Sign in
McLeod Pacific Investments.
Subscribe →
Live · 12:01 UTC Block 843,917 F&G 72
Bitcoin Basics Bitcoin Basics desk

What is a Bitcoin script and how does it control transactions?

Every Bitcoin transaction is governed by a small program called a Script. Understanding what Bitcoin Script does helps beginners see why the network can enforce rules without trusting any third party.

Close-up of colorful programming code on a blurred computer monitor.

Photo by Al Nahian on Pexels

When you send Bitcoin, it doesn't just move from one address to another like an email. Every transaction carries a small set of instructions that specifies exactly who is allowed to spend those funds, and under what conditions. That set of instructions is called Bitcoin Script. It's a lightweight programming language built directly into the Bitcoin protocol, and it's been quietly running every transaction since the network launched in 2009.

Most beginners never need to write a Script themselves. But knowing what it is helps you understand why Bitcoin transactions work the way they do, why some payments require extra steps, and how the network enforces rules without relying on any bank or central authority.

What Bitcoin Script actually is

Bitcoin Script is a stack-based, intentionally limited programming language. "Stack-based" means it processes commands by pushing data onto a virtual stack and then popping it off as operations are performed. Think of the stack like a pile of cards: you add items to the top and take them from the top, in order.

The language is deliberately simple. It has no loops, and it can't store state between transactions. Satoshi Nakamoto designed it this way to keep Bitcoin predictable and secure. A Script that terminates cleanly and leaves a true value on the stack means the transaction is valid. A Script that fails means the funds can't be spent.

Every transaction output contains a locking script (also called a scriptPubKey). This sets the conditions that must be met to spend those funds. When someone wants to spend those funds later, they provide an unlocking script (called a scriptSig) as part of the new transaction. The two scripts are combined and run together. If they resolve successfully, the spend is authorised.

How a standard transaction Script works

The most common Script type is called Pay-to-Public-Key-Hash, or P2PKH. You've interacted with it every time you've sent or received standard Bitcoin payments.

Here's what happens in plain terms:

  • The locking script says: "To spend this output, prove you own the public key that hashes to this address, and provide a valid signature from that key."
  • The unlocking script provides: the spender's digital signature and their public key.
  • The two run together, the Bitcoin network verifies the hash matches and the signature is valid, and the transaction goes through.

This is the same cryptographic process described in detail in our guide on what a Bitcoin public key is and how it works. The Script is simply the mechanism that puts that cryptography to work at the transaction level.

Other Script types you'll encounter

P2PKH isn't the only Script type. Bitcoin supports several others, each designed for a different use case.

Pay-to-Script-Hash (P2SH) lets the sender pay to a hash of a Script rather than a public key. The recipient provides the full Script when spending. This is how multisig wallets work in practice: the locking condition can require, say, 2 out of 3 signatures before funds move.

Pay-to-Witness-Public-Key-Hash (P2WPKH) is the native SegWit version of a standard payment. It moves the unlocking script data into a separate "witness" field, reducing transaction size and lowering fees.

Timelocked scripts use opcodes like OP_CHECKLOCKTIMEVERIFY to prevent funds from being spent until a specific block height or time has passed. This is useful for savings arrangements or dispute resolution mechanisms.

Each Script type shapes what a transaction output looks like on the blockchain. That's why different Bitcoin addresses look different: a legacy P2PKH address starts with 1, a P2SH address starts with 3, and a native SegWit address starts with bc1.

Why Script matters for security and flexibility

Bitcoin Script is what makes the network programmable without being unpredictable. Its limited design means there's no way for a Script to accidentally run forever, consume unlimited resources, or produce unexpected results. Every possible Script either succeeds or fails. No surprises.

That simplicity is a deliberate security trade-off. Ethereum chose a more expressive language and gained flexibility. Bitcoin chose restraint and gained reliability. For a monetary network handling billions of dollars in transactions, that matters.

For holders thinking about custody and control, Script is what enforces the rules of their wallet. A standard single-key wallet uses a simple P2PKH Script. A more advanced setup, like a multisig arrangement requiring multiple approvals before funds move, uses a more complex Script. Understanding that the rules are written directly into the transaction, not held by a company or a server, is fundamental to grasping what makes Bitcoin different from a bank account.

Understanding Script also helps explain what happens at the mempool level. When miners validate transactions before adding them to a block, part of that validation is running the Script and confirming it resolves correctly. Our explainer on what the Bitcoin mempool is and why it matters covers how unconfirmed transactions queue up while awaiting that validation step.

Opcodes: the building blocks of Script

Bitcoin Script instructions are called opcodes. Each one performs a specific function. OP_DUP duplicates the top stack item. OP_HASH160 hashes it twice. OP_EQUALVERIFY checks whether two values match. OP_CHECKSIG verifies a digital signature against a public key.

A standard P2PKH locking script contains just five opcodes: OP_DUP, OP_HASH160, the address hash, OP_EQUALVERIFY, and OP_CHECKSIG. That's it. Five commands encode the entire ownership condition for a Bitcoin output.

Bitcoin currently supports around 80 active opcodes. Some were disabled early on after potential exploits were identified. Others were re-enabled or newly introduced through soft forks, including the Taproot upgrade activated in November 2021, which added OP_CHECKSIGADD and improved privacy for complex Script conditions.

What beginners actually need to take away

You don't need to read or write Bitcoin Script to buy, sell, or store Bitcoin. Your wallet handles all of this automatically. But understanding that every Bitcoin output is locked by a Script, and that spending it requires satisfying that Script's conditions, gives you a clearer picture of how the network actually enforces ownership.

It also explains why certain wallet types offer more security than others. A multisig Script genuinely requires multiple approvals at the protocol level. No company can override it. No exception exists. The Bitcoin protocol runs the Script and either the conditions are met or they aren't.

For beginners building their understanding from the ground up, Script is one of those concepts that quietly connects everything else: addresses, keys, transaction fees, and wallet types all make more sense once you know that a small program is controlling every output on the network.

→ The Confirmations · Daily newsletter

One email at 06:00 UTC. Six minutes. The only digest written for desks, not for retail.