BITCOIN MAINNETLive explorer status
PROGRAMMABLE LOCKS

Bitcoin Script

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.

Spending: the unlocking data is run with the locking scriptUnlockingscriptsignature, public keyjoined withLocking scriptfrom the outputRun onthe stackValid?true = spendallowed
Spending: the unlocking data is run with the locking script

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

Standard script types at a glance

TypeLock saysLesson
P2PKHSignature from the key with this hashPay to public key hash (P2PKH)
P2SHData that satisfies the script with this hashPay to script hash (P2SH)
P2WPKH / P2WSHThe SegWit versions of the two aboveSegregated Witness (SegWit)
P2TROne signature, or one revealed script branchTaproot
Multisigm signatures from n keysMultisig
OP_RETURNNothing: unspendable dataOP_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.

Share this guide
Share on X ↗

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.