Line Coding Techniques Explained: NRZ, Manchester and AMI
In this article
Line coding is the way a digital bit stream is shaped into a physical signal (voltage, light or radio levels) so it can travel down a cable or channel. The main families are NRZ, RZ, Manchester, and bipolar codes like AMI, each trading off bandwidth, clock recovery and DC balance.
Time 8 min · Steps 8 · Level Medium
Line coding converts your 1s and 0s into a waveform the wire can actually carry, and the choice of code decides how much bandwidth you need and whether the receiver can keep its clock in sync. The detail most people get wrong: line coding is not the same as modulation. Modulation puts bits onto a carrier wave (radio, fibre optics); line coding shapes the baseband signal itself, which is why it matters on copper cables such as Ethernet and T1 lines.
What Line Coding Has to Solve
Three problems drive every line code. First, DC balance: if the signal spends more time positive than negative, the average voltage drifts, which distorts data on lines with transformers or AC coupling. Second, clock recovery: the receiver must infer the bit timing from the signal itself, so long runs of identical bits are dangerous. Third, bandwidth: faster transitions mean more wire bandwidth used, and bandwidth costs money on real cables. Every code below is a different compromise among these three.
The Main Line Coding Techniques
- NRZ-L (Non-Return-to-Zero, Level) – a 1 is one voltage level and a 0 is another, held for the whole bit period. Simple and bandwidth-efficient, but a long run of 1s or 0s gives no transitions, so the clock drifts and the signal carries DC.
- NRZ-I (NRZ, Invert on 1) – a 1 is represented by a transition at the bit boundary, a 0 by no transition. Better against polarity confusion, but a run of 0s still gives no clock information.
- RZ (Return-to-Zero) – the signal returns to zero in the middle of every 1 bit, guaranteeing a transition. It doubles the required bandwidth because transitions happen twice as often.
- Manchester encoding – a 1 is a high-to-low transition mid-bit, a 0 is low-to-high (conventions vary). Every bit contains a transition, so clock recovery is trivial and there is no DC, at the cost of roughly double NRZ bandwidth. Used in original 10 Mbps Ethernet over coax.
- Differential Manchester – the mid-bit transition always exists for the clock, and the presence of a transition at the bit boundary signals a 0. Combines clock recovery with immunity to polarity flips; used in Token Ring.
- AMI (Alternate Mark Inversion) – 1s alternate between +V and −V, 0s stay at zero. Perfectly DC-balanced by design and lets you spot a violated alternation as an error. Long runs of 0s are its weakness.
- Scrambled and substituted codes (B8ZS, HDB3) – these fix AMI's zero-run problem by deliberately substituting a pattern of intentional violations whenever 8 (B8ZS, North American T1) or 4 (HDB3, European E1) consecutive zeros appear. The receiver recognises the violations and restores the zeros.
- Multi-level codes (2B1Q, MLT-3) – 2B1Q maps pairs of bits onto four voltage levels, halving the symbol rate for the same bit rate (used on ISDN basic rate). MLT-3 cycles through +V, 0, −V, 0 to concentrate signal energy at low frequencies (used in 100BASE-TX Ethernet over copper).
How Much Bandwidth Does Each Code Need?
Compare codes at the same bit rate R. NRZ needs its main energy below roughly R/2 Hz, because the worst-case pattern (alternating 1s and 0s) transitions at every bit boundary. RZ and Manchester force a transition inside every bit, so their fundamental sits near R Hz — about twice NRZ's requirement. Multi-level codes go the other way: 2B1Q sends one symbol per two bits, so the symbol rate is R/2 and the needed bandwidth drops to about R/4. That is the whole reason multi-level codes exist: squeeze more bits per hertz on a bandwidth-limited pair of wires.
Which Code Handles Long Zero Runs?
Any code whose zeros produce no transitions will eventually lose the receiver's clock. AMI is the classic case, and the standard fixes are the substitution codes: B8ZS replaces a run of eight zeros with a pattern containing two deliberate bipolar violations, and HDB3 replaces four zeros with a pattern containing one violation. Because a true AMI signal never violates the alternation rule, the receiver can tell substitution from error. Manchester and RZ never face this problem at all, since every bit carries a transition — which is exactly why early Ethernet chose Manchester despite its bandwidth cost.
How to Pick a Code for a Given Channel
Work through three checks in order. If the channel is transformer-coupled or AC-coupled (most telecom copper), you need DC balance, which points at AMI, B8ZS, HDB3 or Manchester. If the channel is bandwidth-poor relative to the bit rate, you need multi-level coding such as 2B1Q or MLT-3. If the receiver has no separate clock wire, you need guaranteed transitions, which rules out plain NRZ-L for long streams. Fibre and radio links usually skip straight to block or scrambling codes (like 8B/10B, which maps 8 bits onto 10 to balance ones and zeros) because at those speeds the overhead is cheaper than the clock risk.
What Goes Wrong When the Code Is Wrong
The most common failure is baseline wander: a code with DC (like NRZ) on an AC-coupled line makes the receiver's decision threshold drift, so late bits in a long run get misread. The fix is a DC-balanced code or scrambling. The second is clock jitter from sparse transitions, showing up as bit slips where the receiver drops or duplicates a bit; the fix is a code with regular transitions or a run-length limit. The third is error propagation in differential codes: one flipped bit makes the receiver misread the following bit too, since it decodes against the previous (now wrong) level. None of these are channel noise problems — they are code-choice problems, which is why the code is decided at design time, not fixed in the field.
How to Sketch Any Code by Hand
Draw the bit stream, mark bit boundaries, then apply the rule one bit at a time. For NRZ-I, draw a level change at each boundary where the bit is 1. For Manchester, split each bit cell in half and draw the fixed mid-bit transition, then set its direction from the bit value. For AMI, keep a tally: each 1 flips the polarity, each 0 stays at zero. Doing this for the pattern 1 0 1 1 0 0 0 1 across three or four codes is the fastest way to see the differences — you will notice AMI's three-zero flat stretch immediately, which is exactly the weakness B8ZS exists to patch.