A raw .hevc, .h265 or .265 file follows the byte
stream format of Annex B of ITU-T H.265, also published as ISO/IEC 23008-2. It is a series
of NAL units, each preceded by a start code. These reference pages follow the January 2026
edition of H.265 (version 11); the syntax of the parameter sets and slice headers has not
changed since the first edition of 2013, only grown extensions.
Start codes
Each NAL unit is wrapped in a byte stream NAL unit:
| Name | Coding | Description |
|---|---|---|
leading_zero_8bits | f(8), repeated | zero bytes; allowed only before the first NAL unit of the stream |
zero_byte | f(8) | one 00 byte, required before a VPS, SPS or PPS and before the first NAL unit of each access unit; optional elsewhere |
start_code_prefix_one_3bytes | f(24) | 00 00 01 |
nal_unit | the NAL unit, starting with its two-byte header | |
trailing_zero_8bits | f(8), repeated | zero bytes after the NAL unit and before the next start code |
So the four-byte form 00 00 00 01 is mandatory before parameter sets and at
the start of every access unit, and the three-byte form 00 00 01 is enough
before the other slices of a picture. A reader finds each NAL unit by searching for
00 00 01. The NAL unit ends at the last byte before the next byte-aligned
00 00 00 or 00 00 01, or at the end of the file, so zero bytes
before a start code belong to the framing, never to the NAL unit.
Emulation prevention
Inside a NAL unit, the payload (the RBSP, raw byte sequence payload) must never contain a
start code. Whenever two zero bytes would be followed by a byte of 03 or
less, the encoder inserts an emulation_prevention_three_byte,
03:
| Payload bytes | Bytes in the stream |
|---|---|
00 00 00 | 00 00 03 00 |
00 00 01 | 00 00 03 01 |
00 00 02 | 00 00 03 02 |
00 00 03 | 00 00 03 03 |
A reader removes every 03 that follows two zero bytes, from the third byte
of the NAL unit onwards (the two header bytes are never escaped). The same applies when
the payload ends in 00: the last byte of a NAL unit is never zero.
Bit syntax
Fields are packed most-significant bit first with no alignment unless a structure says otherwise. The pages here use the standard’s coding names:
| Coding | Meaning |
|---|---|
u(n) | unsigned integer of n bits; u(1) is a flag |
u(v) | unsigned integer whose width depends on earlier fields |
f(n) | fixed bit pattern of n bits |
b(8) | a byte with any value |
i(n) | signed two’s complement integer of n bits |
ue(v) | unsigned Exp-Golomb code |
se(v) | signed Exp-Golomb code |
ae(v) | context-adaptive arithmetic (CABAC) coded; used only in slice data |
Exp-Golomb codes
An Exp-Golomb code is n zero bits, a one bit, then n more bits. Its value is 2n − 1 plus the value of those last n bits:
| Bits | ue(v) | se(v) |
|---|---|---|
1 | 0 | 0 |
010 | 1 | +1 |
011 | 2 | −1 |
00100 | 3 | +2 |
00101 | 4 | −2 |
00110 | 5 | +3 |
00111 | 6 | −3 |
0001000 | 7 | +4 |
A signed code k maps to (−1)k+1 × ⌈k ÷ 2⌉.
Trailing bits and alignment
| Structure | Bits | Used |
|---|---|---|
rbsp_trailing_bits | rbsp_stop_one_bit (1), then rbsp_alignment_zero_bit (0) up to the byte boundary | at the end of every RBSP |
byte_alignment | alignment_bit_equal_to_one (1), then zeros up to the byte boundary | at the end of the slice segment header, and inside slice data after each tile or wavefront row |
cabac_zero_word | 00 00, written as 00 00 03 | optional padding after the trailing bits of a slice segment, to meet a limit on decoded bins per byte |
To find where the data of an RBSP ends, a reader scans back from the last byte to the last 1 bit.
Worked example
The start of a typical stream from an HEVC Main profile encoder:
00000000 00 00 00 01 40 01 0C 01 FF FF 01 60 00 00 03 00 …
… 00 00 00 01 42 01 01 01 60 00 00 03 00 …
… 00 00 00 01 44 01 …
… 00 00 00 01 4E 01 …
… 00 00 00 01 26 01 …
Each highlighted pair is a NAL unit header:
40 01 is a video parameter set (type 32), 42 01 a sequence
parameter set (33), 44 01 a picture parameter set (34), 4E 01
a prefix SEI (39) and 26 01 a slice of an IDR picture (19). All have layer 0
and temporal ID 0.
In the VPS, 0C is 0000 1100: VPS ID 0, both base layer flags 1,
then the first bits of vps_max_layers_minus1; FF FF is the
reserved field; 01 starts the
profile, tier and level with profile
space 0, Main tier and general_profile_idc 1, Main; 60 00 00 00
(with an emulation prevention byte) sets compatibility flags 1 and 2.