Inputs: ScriptSig Size

TransactionScriptSig Size
Structure
Version
4 bytes
Segwit (Optional)
Marker
1 byte
Flag
1 byte
Structure
Input Count
variable
Input Structure
Previous TXID
32 bytes
Output Index
4 bytes
ScriptSig Size
variable
ScriptSig
variable
Sequence
4 bytes
Structure
Output Count
variable
Output Structure
Amount
8 bytes
ScriptPubKey Size
variable
ScriptPubKey
variable
Structure
Witness
variable
Structure
Locktime
4 bytes

Size

variable

Format

Compact Size

Description

The size in bytes of the upcoming ScriptSig.

Example

6b

Byte Visualization

6b
Byte 1

The ScriptSig size is stored as a variable-length integer (varint) that indicates the length of the following ScriptSig field in bytes.

Let's examine our transaction to understand this better:

SVG Image

In this transaction, we can see the ScriptSig size value: 6b. When decoded, this hexadecimal value represents 107 bytes, telling us that the following ScriptSig data will be exactly 107 bytes long.

Variable Integer Encoding

Like the input count, the ScriptSig size uses varint encoding:

Decimal RangeHex RangeBytes usedFormat
0 to 2520x00 to 0xfc1uint8_t
253 to 2¹⁶-10xfd to 0xffff30xfd followed by uint16_t
2¹⁶ to 2³²-10x10000 to 0xffffffff50xfe followed by uint32_t
2³² to 2⁶⁴-10x100000000 to 0xffffffffffffffff90xff followed by uint64_t

Note

Most ScriptSig sizes are small enough to fit in a single byte, as the ScriptSig typically contains just a signature and public key that combined are less than 253 bytes in size.

Implementation Example

Here's how you might parse a ScriptSig size:

python
def parse_scriptsig_size(raw_tx: bytes, offset: int = 0) -> tuple[int, int]:
    """
    Parse ScriptSig size from raw transaction bytes
    
    Args:
        raw_tx: Raw transaction bytes
        offset: Starting position in bytes
        
    Returns:
        (size, new_offset)
    """
    # Read the varint
    size = 0
    first_byte = raw_tx[offset]
    
    if first_byte < 0xfd:
        size = first_byte
        offset += 1
    elif first_byte == 0xfd:
        size = int.from_bytes(raw_tx[offset+1:offset+3], 'little')
        offset += 3
    elif first_byte == 0xfe:
        size = int.from_bytes(raw_tx[offset+1:offset+5], 'little')
        offset += 5
    else:  # 0xff
        size = int.from_bytes(raw_tx[offset+1:offset+9], 'little')
        offset += 9
        
    return size, offset
Suggest Edits
View our public visitor count
Built with 🧡 by the Bitcoin Dev Project
We'd love to hear your feedback on this project?Give Feedback