4B5B


In telecommunication, 4B5B is a form of data communications line code. 4B5B maps groups of 4 bits of data onto groups of 5 bits for transmission. These 5 bit words are pre-determined in a dictionary and they are chosen to ensure that there will be sufficient transitions in the line state to produce a self-clocking signal. A collateral effect of the code is that 25% more bits are needed to send the same information.
An alternative to using 4B5B coding is to use a scrambler. Some systems use scramblers in conjunction with 4B5B coding to assure DC balance and improve electromagnetic compatibility.
Depending on the standard or specification of interest, there may be several 5-bit output codes left unused. The presence of any of the unused codes in the data stream can be used as an indication that there is a fault somewhere in the link. Therefore, the unused codes can be used to detect errors in the data stream.

Applications

4B5B was popularized by fiber distributed data interface in the mid-1980s. It was adopted for digital audio transmission by MADI in 1989. and by Fast Ethernet in 1995.
The name 4B5B is generally taken to mean the FDDI version. Other 4-to-5-bit codes have been used for magnetic recording and are known as group coded recording, but those are run-length limited codes, with at most two consecutive zeros. 4B5B allows up to three consecutive zeros, providing a greater variety of control codes.
On optical fiber, the 4B5B output is NRZI-encoded. FDDI over copper uses MLT-3 encoding instead, as does 100BASE-TX.
The 4B5B encoding is also used for USB Power Delivery communication, where it is sent over the USB-C CC pin or the USB-A/B power lines.

Clocking

4B5B codes are designed to produce at least two transitions per 5 bits of output code regardless of input data. When NRZI-encoded, the transitions provide necessary clock transitions for the receiver. For example, a run of 4 bits such as 0000 contains no transitions and that causes clocking problems for the receiver. 4B5B solves this problem by assigning the 4-bit block a 5-bit code, in this case 11110.

Encoding table

Three consecutive zero bits only appear in normal data when a code ending with two 0 bits is followed by a code beginning with a 0 bit, so will always appear separated by multiples of the 5-bit encoded symbol length. Violations of this property are used for special synchronization codes.

Command characters

The following codes are sometimes referred to as command characters. They are commonly used in pairs, although USB-PD uses 4-symbol sequences to begin its packets.
Control character5b symbolsPurpose
JK11000 10001Sync, Start delimiter
I11111100BASE-X idle marker
T01101USB-PD end delimiter
TT01101 01101FDDI end delimiter
TS01101 11001
IH11111 00100SAL
TR01101 00111100BASE-X end delimiter
SR11001 00111
SS11001 11001
H00100100BASE-X transmit error
JJJK11000 11000 11000 10001USB-PD Start Of Packet
JJLL11000 11000 00110 00110USB-PD SOP′
JLJL11000 00110 11000 00110USB-PD SOP″
JSSL11000 11001 11001 00110USB-PD SOP′_Debug
JSLK11000 11001 00110 10001USB-PD SOP″_Debug
RRRS00111 00111 00111 10001USB-PD Hard Reset
RJRL00111 11000 00111 00110USB-PD Cable Reset