Direct Byte Push (Opcodes 0x01\u20130x4b)
8. Direct Byte Push (Opcodes 0x01–0x4b)
Overview
The range of bytes from 0x01 to 0x4b in the Bitcoin Script opcode space is not used for named opcodes — instead, each byte in this range is itself a push opcode whose value implicitly encodes the number of subsequent bytes to push onto the stack. This is the "direct byte push" mechanism and it is the most space-efficient way to push 1 to 75 bytes of data.
How Direct Push Works
When the Script interpreter encounters a byte N where 0x01 ≤ N ≤ 0x4b (decimal 1 through 75), it does not look the byte up in any opcode table. Instead, it directly interprets N as a length instruction: read the next N bytes and push them as a single stack item.
General form:
<N:1 byte> <data:N bytes>
where N is in range [0x01, 0x4b] = [1, 75]
Examples:
Push 1 byte (0xAB):
0x01 0xAB
Push 3 bytes (0xDE 0xAD 0xBE):
0x03 0xDE 0xAD 0xBE
Push 20 bytes (a pubkey hash):
0x14 <20 bytes>
Push 32 bytes (a script hash / witness program):
0x20 <32 bytes>
Push 33 bytes (compressed public key):
0x21 <33 bytes>
Push 65 bytes (uncompressed public key):
0x41 <65 bytes>
Push 72 bytes (DER signature with sighash flag):
0x48 <72 bytes>
Push 75 bytes (maximum for direct push):
0x4b <75 bytes>
Relationship to Named Opcodes
In Bitcoin Core's opcode enumeration, the direct push range is partially represented as a loop or handled specially:
// From src/script/interpreter.cpp
// In the main execution loop:
if (opcode <= OP_PUSHDATA4) {
// Determine nSize based on opcode
if (opcode < OP_PUSHDATA1) {
nSize = opcode; // Direct: opcode IS the length
} else if (opcode == OP_PUSHDATA1) {
nSize = *pc++;
} else if (opcode == OP_PUSHDATA2) {
nSize = ReadLE16(&pc[0]); pc += 2;
} else {
nSize = ReadLE32(&pc[0]); pc += 4;
}
// Read nSize bytes and push them
valtype vch(pc, pc + nSize);
pc += nSize;
stack.push_back(vch);
}
The opcode < OP_PUSHDATA1 condition catches the entire range 0x01–0x4b and uses the opcode value itself as the data length.
Common Direct Push Lengths
In practice, the following direct push lengths appear most frequently in real Bitcoin transactions:
0x14 (20 bytes) -- HASH160 of public key or script (P2PKH, P2SH)
0x20 (32 bytes) -- SHA256 hash or SegWit v0 script hash or Taproot key
0x21 (33 bytes) -- compressed secp256k1 public key
0x41 (65 bytes) -- uncompressed secp256k1 public key
0x47 (71 bytes) -- DER signature (common length)
0x48 (72 bytes) -- DER signature (common length)
0x49 (73 bytes) -- DER signature (maximum DER length)
Efficiency
The direct push mechanism is maximally efficient for its range. Each push requires exactly 1 overhead byte (the length) plus the data bytes themselves. There is no separate opcode byte, no opcode lookup, and no branching within the interpreter beyond a simple comparison.
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: