Line coding is the method used to convert binary data (ones and zeros) into electrical or optical signals that can travel over a physical medium like a copper wire or fiber optic cable. Every time you stream a video, make a phone call, or send a file over a network, line coding determines the exact pattern of voltage levels or light pulses that represent your data on the wire. It sits at the boundary between raw digital information and the physical world that carries it.
The concept matters because you can’t just slap ones and zeros onto a cable and hope for the best. The receiving device needs to stay synchronized with the sender, the signal needs to avoid certain electrical problems, and the whole thing has to fit within a limited amount of bandwidth. Different line coding schemes make different trade-offs to solve these problems.
Why Raw Binary Isn’t Enough
Imagine sending a long string of ones: 1111111111. If a “1” is simply a high voltage and a “0” is a low voltage, the receiver sees a flat, unchanging signal. Without any transitions (changes from high to low or vice versa), the receiver’s clock has nothing to latch onto. It loses track of where one bit ends and the next begins. This is the clock recovery problem, and it’s one of the central reasons line coding exists.
The other major issue is DC balance. If a signal spends more time at a positive voltage than a negative one (or vice versa), it builds up what engineers call “baseline wander.” The average voltage drifts, making it harder for the receiver to tell the difference between a one and a zero. A good line coding scheme keeps the running count of ones and zeros roughly equal over time, so the signal stays centered.
Two numbers define how well a line code performs on these fronts: the maximum run length (the longest streak of identical bits in a row) and the running disparity (the gap between the total number of ones and zeros in a given frame). Run length needs to stay short for reliable clock recovery. Running disparity needs to stay near zero to prevent baseline wander.
NRZ: The Simplest Approach
Non-Return-to-Zero (NRZ) is the most straightforward family of line codes, and it comes in two main flavors.
NRZ-L (Level) assigns one voltage level to a logic one and the opposite level to a logic zero. A “1” might be +V and a “0” might be -V for the entire duration of each bit. It’s simple and bandwidth-efficient, but a long run of the same bit produces a flat signal with no transitions, making clock recovery difficult.
NRZ-I (Inverted) takes a different approach. Instead of mapping voltage levels to bit values, it uses transitions. A logic one is represented by a change in voltage at the start of the bit period; a logic zero means no change. This helps with long runs of ones (each one forces a transition), but a long string of zeros still produces a flat line.
NRZ codes use bandwidth efficiently because the signal only changes when it needs to. But their weakness with synchronization and DC balance means they’re typically used in situations where a separate clock signal is available, or where the data naturally avoids long identical runs.
RZ and AMI: Adding Transitions
Return-to-Zero (RZ) coding forces the signal back to zero volts during the second half of every bit period. A logic one shows up as a pulse in the first half, then drops to zero. A logic zero stays at zero the entire time. This guarantees at least one transition per “1” bit, which helps the receiver stay in sync. The downside is that it requires twice the bandwidth of NRZ, since each bit now involves two signal changes instead of one at most.
Alternate Mark Inversion (RZ-AMI) builds on this by alternating the polarity of each successive “1” pulse. The first one might be a positive pulse, the next a negative pulse, the next positive again. This alternation naturally balances the DC content of the signal, since positive and negative pulses cancel each other out over time. AMI was widely used in early telephone networks for exactly this reason. Its weakness is that a long string of zeros still produces a flat line with no transitions.
How B8ZS and HDB3 Fix the Zero Problem
Traditional AMI coding works well until the data contains a long run of zeros. No ones means no pulses, which means no transitions for the receiver to synchronize with. Two clever schemes solve this by breaking the rules on purpose.
B8ZS (Bipolar with 8-Zero Substitution) is used in North American T1 telephone lines. When the transmitter detects eight consecutive zeros, it replaces them with a special pattern that includes deliberate violations of the normal alternating polarity rule. The receiver recognizes these violations as a substitution code rather than actual data, replaces them with zeros, and stays synchronized throughout.
HDB3 (High Density Bipolar 3) does the same thing but triggers after just four consecutive zeros instead of eight, giving it a higher guaranteed transition density. It’s the standard for European E1 lines. Both schemes are invisible to the higher layers of the network. The substitution happens on the wire and gets reversed before the data is passed along.
Manchester Encoding: A Transition in Every Bit
Manchester encoding solves the clock recovery problem decisively: every single bit contains a transition in the middle of the bit period. Under the IEEE standard, a logic one is represented by a rising edge (low to high) at the midpoint, and a logic zero by a falling edge (high to low).
This guarantees that the receiver sees at least one transition per bit, no matter what data pattern is being sent. Clock recovery becomes trivial. The signal also has no DC component, since it spends equal time at positive and negative voltage levels.
The trade-off is bandwidth. Because every bit forces a mid-bit transition (and sometimes an additional transition at the bit boundary), Manchester encoding requires roughly twice the bandwidth of NRZ for the same data rate. Original 10 Mbps Ethernet used Manchester encoding, where this bandwidth cost was acceptable over coaxial cable.
Block Codes: 4B/5B and 8B/10B
As network speeds increased, engineers needed schemes that offered good clock recovery and DC balance without doubling the required bandwidth. Block codes achieve this by encoding groups of data bits into slightly larger groups of code bits, carefully chosen to guarantee enough transitions.
4B/5B encoding maps every 4 data bits into a 5-bit code word. The 16 possible input patterns are mapped to 5-bit outputs that never contain more than three consecutive identical bits. This adds only 25% overhead instead of the 100% overhead of Manchester encoding. Fast Ethernet (100 Mbps) uses 4B/5B combined with a three-level line code called MLT-3 to fit the signal within the bandwidth limits of twisted-pair copper cable.
8B/10B encoding maps 8 data bits into 10-bit code words, adding 25% overhead while providing excellent DC balance and short run lengths. Gigabit Ethernet uses 8B/10B with five voltage levels to push 1 Gbps of data through just 100 MHz of cable bandwidth. The extra code bits aren’t wasted. They carry the timing and balance properties that make reliable high-speed transmission possible.
How Engineers Choose a Line Code
No single line coding scheme is best for every situation. The choice involves trade-offs between several competing factors:
- Bandwidth efficiency: NRZ codes use the least bandwidth but offer poor synchronization. Manchester encoding offers perfect synchronization but at twice the bandwidth cost. Block codes fall in between.
- DC balance: Schemes like AMI and Manchester naturally eliminate DC offset. NRZ-L does not, which limits its use on links that pass through transformers or AC-coupled circuits.
- Transition density: More transitions per bit means easier clock recovery but typically higher bandwidth. The ideal scheme provides just enough transitions to keep the receiver locked.
- Noise margin: Most line codes use only two voltage levels because this gives the largest gap between signal states for a given power level, making the signal more resistant to noise. Multilevel schemes like MLT-3 sacrifice some noise margin to gain bandwidth efficiency.
- Implementation complexity: Simple two-level codes are cheap to build in hardware. Block codes require lookup tables or logic to encode and decode, adding cost and latency.
A line code also needs to be transparent, meaning it can handle any possible sequence of input data without breaking. Schemes that rely on frequent transitions in the data itself (like basic AMI) need additional mechanisms (like B8ZS or HDB3) to maintain that transparency when the data doesn’t cooperate.
In practice, the application dictates the choice. Telephone trunk lines use AMI variants with zero-substitution. Local area networks evolved from Manchester encoding at lower speeds to block codes at higher speeds. Fiber optic links, with their enormous bandwidth, can afford the overhead of 8B/10B or even larger block codes to ensure rock-solid synchronization and error detection at multi-gigabit rates.

