Skip to content
DonateБГ

Data

Bytes

Bytes in Bitcoin: a byte is eight bits, written as two hex digits. Learn the sizes of keys, IDs, amounts and the fields in blocks.

By Dimitar Zurnov · Updated 4 Nov 2026
Adapted from Learn Me a Bitcoin by Greg Walker.

A byte is a group of eight bits, and it is the unit Bitcoin uses to measure its raw data. A private key is 32 bytes, a transaction ID is 32 bytes, and the nonce in a block header is 4 bytes. Once you can read a byte, most of the raw data in a transaction or a block becomes readable.

What is a bit?

The bit is the smallest piece of data in a computer. It holds one of two values, 0 or 1. In hardware, a bit is a tiny circuit that is either off (0) or on (1). Every number, letter and instruction in a computer is built from bits.

How many bits are in a byte?

A byte holds eight bits. Eight bits give 256 different patterns, from 00000000 to 11111111, so one byte can store any whole number from 0 to 255.

Each bit is worth a power of two. Counting from the right, the values are 1, 2, 4, 8, 16, 32, 64 and 128.

Bitcoin measures data in bytes, not bits. The table shows how the units relate.

Unit Bits Where you meet it
Bit 1 The smallest unit, 0 or 1
Nibble 4 Half a byte, one hex digit
Byte 8 Two hex digits, from 00 to ff
32 bytes 256 A private key, a transaction ID or a block hash

Programmers sometimes say "nibble" for half a byte. You rarely need the word for Bitcoin.

One byte: eight bits, high four bits and low four bits, shown as the hex digits 6 and B. One byte is eight bits 128 0 64 1 32 1 16 0 8 1 4 0 2 1 1 1 0110 = 6 1011 = B 6B 6B is two hex digits, one byte. The same byte is 107 in decimal.
The byte 01101011 is 107 in decimal and 6B in hex.

How do you write a byte?

You can write a byte in binary, with eight digits, or in hexadecimal, with two. The byte in the diagram is 01101011 in binary and 6B in hex. In code, binary usually starts with 0b and hex with 0x, so 0b11111111 and 0xFF both mean one byte.

Half a byte has 16 possible patterns, and hex has exactly 16 digits. So two hex digits always cover one whole byte. The hexadecimal page explains how the digits work.

Hex is not case sensitive, so 6b and 6B are the same byte. Bitcoin Core prints its hex in lowercase, so raw data usually looks lowercase.

What can a byte mean?

A byte has no meaning on its own. The field that holds it decides what its eight bits stand for. The byte 01100111 is the number 103, the letter g in ASCII, or the hex digits 67.

The byte 01100111 read as the number 103, the letter g, or the hex digits 67. The same byte, three readings 01100111 as a number 103 as a letter, in ASCII g as hex, two digits 67 The field that holds the byte decides its meaning.
ASCII is the usual table that maps bytes to letters.

Bitcoin uses bytes for five kinds of data:

  • Numbers, such as an output amount or a block time.
  • Text, such as the data in an OP_RETURN output or a miner's tag in a coinbase.
  • Bit fields, where each bit switches one setting on or off.
  • Fingerprints, such as hashes, which matter only because each value is unique.
  • Instructions and lengths, such as script opcodes and compact size prefixes.

In a script, the byte 76 is the opcode OP_DUP, and the byte ac is OP_CHECKSIG. The same byte can mean a letter, a number or an instruction, depending on where it sits.

Which fields are measured in bytes?

Most fields in raw data have a fixed size. Knowing the size tells you where a field ends and the next one begins.

Field Size What it holds
Private key 32 bytes A 256-bit number
Compressed public key 33 bytes A prefix byte and a 32-byte x coordinate
Public key hash 20 bytes A short fingerprint of a public key, used in addresses
Transaction ID (TXID) 32 bytes A hash that names a transaction
Block hash 32 bytes A hash that names a block
Output amount 8 bytes A value in satoshis
Output index (vout) 4 bytes Which output of an earlier transaction is spent
Sequence 4 bytes A bit field that sets a relative locktime
Locktime 4 bytes The earliest block height or Unix time the transaction can be mined
Block version 4 bytes A bit field that miners use to signal upgrades
Block time 4 bytes A Unix timestamp
Target 32 bytes The full threshold a block hash must be below, as a 256-bit number
Bits 4 bytes The target, stored in a compact form
Block nonce 4 bytes The number miners change while they search
Magic bytes 4 bytes The start marker of a network message, f9beb4d9 on mainnet
Message command 12 bytes The message name, such as version, padded with zeros
Services 8 bytes A bit field of the services a node offers
Signature About 71 to 73 bytes An ECDSA signature in DER form, with the sighash byte
Schnorr signature 64 bytes A taproot signature, or 65 with a non-default sighash byte
Compact size 1 to 9 bytes A count or a length, sized by its first byte (see below)

How big are transactions and blocks?

A transaction is a run of fields, one after another. Most have a fixed size. Counts and script lengths use the compact size format, so their size depends on the value they hold.

Part Size What it holds
Version 4 bytes The transaction version
Input count 1 to 9 bytes The number of inputs, as a compact size
Input At least 41 bytes TXID (32), vout (4), scriptSig length and script, sequence (4)
Output count 1 to 9 bytes The number of outputs, as a compact size
Output At least 9 bytes Amount (8), scriptPubKey length and script
Witness data Variable Only in SegWit transactions: item counts, item lengths and the items
Locktime 4 bytes The earliest block height or time the transaction can be mined

A SegWit transaction also has a marker byte, 00, and a flag byte, 01, right after the version. The witness data comes after the outputs and before the locktime.

A block is simpler. Its header comes first, and it is always 80 bytes. A compact size count of transactions follows, and then the transactions themselves.

Part Size What it holds
Block header 80 bytes Version (4), previous block hash (32), merkle root (32), time (4), bits (4), nonce (4)
Transaction count 1 to 9 bytes The number of transactions, as a compact size
Transactions The rest of the block Each transaction, one after another
The 80-byte block header, one bar per field, drawn to scale: version 4, previous block hash 32, merkle root 32, time 4, bits 4, nonce 4. The block header is 80 bytes Each bar is as long as its field is in bytes. Version 4 bytes Previous block hash 32 bytes Merkle root 32 bytes Time 4 bytes Bits 4 bytes Nonce 4 bytes Total: 4 + 32 + 32 + 4 + 4 + 4 = 80 bytes Every header is exactly 80 bytes. Read 80 bytes, and you have the whole header.
Each bar is as long as its field. The nonce is the field miners change.

Block 0, the first block ever mined, shows the layout. Its header is 80 bytes, and its transaction count is 01, one byte, because it holds one transaction.

What are bit fields?

A bit field packs several on-off settings into one field, with one bit for each setting. Three fields in Bitcoin work this way.

  • Services, in the version message. Each bit marks a service a node offers. The lowest bit, value 1, means the node serves the full chain.
  • Block version, in the block header. Recent versions start with the bits 001. Miners set further bits to show which upgrades they support, as described in BIP 9. The block version page explains the signalling.
  • Sequence, in each input. If bit 31 is set, the sequence sets no relative locktime. Bit 22 chooses blocks or time, and the low 16 bits hold the value, as BIP 68 defines.

To check one bit in code, use a bitwise AND with a mask. services & 1 is non-zero when the lowest bit is set.

Is text stored in bytes?

Text is not common in Bitcoin data, but it appears in a few places:

  • OP_RETURN outputs. An OP_RETURN output stores arbitrary data after the opcode. That data is often ASCII text.
  • Coinbase. Miners usually put a text tag in the scriptSig of the coinbase transaction, such as the name of their pool.
  • Message command. Each network message names its type in 12 bytes of ASCII, padded with zeros. Examples are version, block and tx.
  • User agent. The version message has a text field that names the node software, such as Satoshi:24.0.1.

Are hashes just bytes?

A hash function returns a fixed string of bytes. Once you have the bytes, their only job is to be unique. A TXID, a block hash and a public key hash all work as fingerprints.

A block hash does double duty. It identifies the block, and miners also read it as a number to check it against the target. Magic bytes are different again: f9beb4d9 marks the start of each mainnet network message, so a node can see where one message ends and the next begins.

How do you convert bytes in code?

Most languages can do three conversions: bytes to hex text, hex text to bytes, and bytes to an integer. The Python lines below do all three. Each comment shows the result.

# hex text to bytes
raw = bytes.fromhex("f9beb4d9")
# the bytes back to hex text: f9beb4d9
print(raw.hex())
# the bytes read as one number: 4190024921
print(int.from_bytes(raw, "big"))

The "big" argument says the first byte is the most significant one. Bitcoin stores most of its numbers the other way round, so read the little-endian page before you convert a field from a transaction or a block.

Every TXID is a 32-byte value, written as 64 hex characters. The byte order page explains why explorers often show those 64 characters reversed.

In this section: Data

All of Bitcoin from zero

Something look wrong? Tell us