TeachMeBitcoin

Locking Script Overview

From TeachMeBitcoin, the free encyclopedia Reading time: 2 min

The Locking Script (ScriptPubKey)

Every transaction output in Bitcoin is protected by a small program called a ScriptPubKey. This script defines the mathematical conditions that must be met to spend the coins in the future.

1. The Purpose of ScriptPubKey

ScriptPubKey is known as the "Locking Script." Unlike a traditional bank account where you have a "balance," Bitcoin consists of billions of these locked outputs.

2. Programmable Money

Because ScriptPubKey is a script (not just an address), it allows Bitcoin to be "programmable." You can create locks that require:

3. Storage in the UTXO Set

When a node verifies the blockchain, it keeps a database of every unspent ScriptPubKey. This is the "Ground Truth" of who owns what. When you see your balance in a wallet, the wallet is actually just summing up all the satoshis attached to ScriptPubKeys that your private key can unlock.

4. Location in the Hex

In a raw transaction output, the ScriptPubKey follows the 8-byte Value field.

[8 Bytes Value][VarInt ScriptLen][ScriptPubKey Bytes]
Property Value
Role Locking Script
Location Transaction Output
Contents Opcodes and Data
Nickname The Lock

In the next section, we will look at the Standard Script Types used in the protocol.

☕ Help support TeachMeBitcoin

TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation:

Ethereum: 0x578417C51783663D8A6A811B3544E1f779D39A85
Bitcoin: bc1q77k9e95rn669kpzyjr8ke9w95zhk7pa5s63qzz
Solana: 4ycT2ayqeMucixj3wS8Ay8Tq9NRDYRPKYbj3UGESyQ4J
Address copied to clipboard!