# 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.

Canonical page: https://mybitcoinexplorer.com/learn/bitcoin-script
Topic: Bitcoin Script
Published: 2026-10-29
Updated: 2026-10-30


## Locks and keys
Every [output](https://mybitcoinexplorer.com/learn/transaction-outputs) has a **locking script** saying what's needed to spend it. Every [input](https://mybitcoinexplorer.com/learn/transaction-inputs) provides an **unlocking script** (or [witness](https://mybitcoinexplorer.com/learn/witness-data)) with the data that satisfies it. To check a spend, a node runs both together.

> Diagram: Spending: the unlocking data is run with the locking script — Unlocking script: signature, public key → (joined with)Locking script: from the output → *Run on the stack → Valid?: true = spend allowed

## A stack language
Script reads left to right. Data items are pushed onto a [stack](https://mybitcoinexplorer.com/learn/the-stack); **[Script opcodes](https://mybitcoinexplorer.com/learn/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)](https://mybitcoinexplorer.com/learn/p2pkh))
- "Any 2 of these 3 keys" ([Multisig](https://mybitcoinexplorer.com/learn/multisig))
- "Not before block 900,000" ([Timelocks: CLTV and CSV](https://mybitcoinexplorer.com/learn/timelocks-cltv-csv))
- "Whoever knows this secret, or a refund after a timeout": the basis of the [The Lightning Network](https://mybitcoinexplorer.com/learn/lightning-network) ([HTLCs: hash time-locked contracts](https://mybitcoinexplorer.com/learn/htlc))


## Standard script types at a glance
| Type | Lock says | Lesson |
|---|---|---|
| P2PKH | Signature from the key with this hash | [Pay to public key hash (P2PKH)](https://mybitcoinexplorer.com/learn/p2pkh) |
| P2SH | Data that satisfies the script with this hash | [Pay to script hash (P2SH)](https://mybitcoinexplorer.com/learn/p2sh) |
| P2WPKH / P2WSH | The SegWit versions of the two above | [Segregated Witness (SegWit)](https://mybitcoinexplorer.com/learn/segwit) |
| P2TR | One signature, or one revealed script branch | [Taproot](https://mybitcoinexplorer.com/learn/taproot) |
| Multisig | m signatures from n keys | [Multisig](https://mybitcoinexplorer.com/learn/multisig) |
| OP_RETURN | Nothing: unspendable data | [OP_RETURN data outputs](https://mybitcoinexplorer.com/learn/op-return) |

## 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.

## Related lessons

- [The stack](https://mybitcoinexplorer.com/learn/the-stack)
- [Script opcodes](https://mybitcoinexplorer.com/learn/opcodes)
- [Pay to public key hash (P2PKH)](https://mybitcoinexplorer.com/learn/p2pkh)
- [Taproot](https://mybitcoinexplorer.com/learn/taproot)
