What is an Unlocking Script (scriptSig)
What is an Unlocking Script (scriptSig)?
The unlocking script is the proof you provide when spending bitcoin. It is your answer to the challenge posed by the locking script. If your answer is correct, the coins are yours to move. If it's wrong, the network rejects your transaction.
Terminology
Like the locking script, the unlocking script has multiple names:
-
scriptSig — original name (because it typically contains a signature)
-
Unlocking script — descriptive educational term
-
Input script — because it lives in transaction inputs
-
sigScript — alternative spelling used in some codebases
Where Does the Unlocking Script Live?
The unlocking script is part of a transaction input (TxIn). Every input in a Bitcoin transaction references a previous output (the UTXO being spent) and provides an unlocking script.
TxIn structure:
{
previous_output: 36 bytes (txid: 32 bytes + vout index: 4 bytes)
script_len: varint
scriptSig: N bytes (the unlocking script bytecode)
sequence: 4 bytes
}
What Goes Inside a scriptSig?
The contents of the scriptSig depend entirely on what the corresponding locking script requires. For the most common script types:
Unlocking P2PKH:
<DER-encoded signature> <compressed public key>
Unlocking P2PK:
<DER-encoded signature>
Unlocking P2SH (e.g., 2-of-3 multisig):
OP_0 <sig1> <sig2> <serialized redeem script>
Unlocking P2WPKH (native SegWit): The scriptSig is empty. Witness data replaces it:
scriptSig: (empty)
Witness: [<signature>, <pubKey>]
Unlocking P2TR key path: The scriptSig is empty. Witness data contains the Schnorr signature:
scriptSig: (empty)
Witness: [<schnorr_signature>]
The scriptSig Size Limit
The maximum size of a scriptSig is 10,000 bytes under standard relay rules, though the consensus limit is higher. In practice, scriptSigs are much smaller — a P2PKH scriptSig is typically 107 bytes.
scriptSig in SegWit Transactions
For native SegWit inputs (P2WPKH, P2WSH, P2TR), the scriptSig must be empty. The actual unlocking data is moved to the witness field, which sits in a separate part of the transaction and receives the witness discount (counted at 1/4 weight).
For nested SegWit (P2SH-P2WPKH), the scriptSig contains just the serialized witness program:
// scriptSig for P2SH-P2WPKH:
<push of 0x0014{20-byte-hash}>
// Witness field:
[<signature>, <pubKey>]
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: