Every Bitcoin output is locked by a tiny program written in Script. Learn how locking and unlocking scripts work together and why Script is limited.
Locks and keys
Every output has a locking script saying what's needed to spend it. Every input provides an unlocking script (or witness) with the data that satisfies it. To check a spend, a node runs both together.
A stack language
Script reads left to right. Data items are pushed onto a stack; Script opcodes pop items, work on them and push results. If the script finishes without failing and the top item is true, the spend is valid.
Deliberately limited
- No loops. Every script finishes in a predictable time, so a malicious transaction can't freeze nodes.
- No access to the outside world. A script only sees its own data and the transaction.
- Many opcodes disabled early on for safety.
These limits make Bitcoin safer and simpler to verify, at the cost of flexibility.
What Script can express
- "Signature from this key" (Pay to public key hash (P2PKH))
- "Any 2 of these 3 keys" (Multisig)
- "Not before block 900,000" (Timelocks: CLTV and CSV)
- "Whoever knows this secret, or a refund after a timeout": the basis of the The Lightning Network (HTLCs: hash time-locked contracts)
Standard script types at a glance
| Type | Lock says | Lesson |
|---|---|---|
| P2PKH | Signature from the key with this hash | Pay to public key hash (P2PKH) |
| P2SH | Data that satisfies the script with this hash | Pay to script hash (P2SH) |
| P2WPKH / P2WSH | The SegWit versions of the two above | Segregated Witness (SegWit) |
| P2TR | One signature, or one revealed script branch | Taproot |
| Multisig | m signatures from n keys | Multisig |
| OP_RETURN | Nothing: unspendable data | OP_RETURN data outputs |
Is Script Turing complete?
No, deliberately. With no loops and strict limits, every script finishes quickly and predictably, so nodes can't be tricked into endless work.
Key takeaways
- Outputs are locked by scripts; inputs supply data that unlocks them.
- Script is a stack language with no loops.
- Its limits make every spend cheap and predictable to verify.
Common questions
Is Bitcoin Script a smart-contract language?
A very simple one. It supports multisig, timelocks and hash locks, which power systems like Lightning.
Do I need to write Script to use Bitcoin?
No. Wallets create standard scripts automatically.
Can Bitcoin do smart contracts?
Yes, simple ones: multisig, timelocks, hash locks and their combinations, which power systems like Lightning.
Where do I see a transaction's scripts?
On MyBitcoinExplorer, each output shows its script type, and the raw data includes the full scripts.