The previous article asked how to represent a message with fewer bits. Now the question is: when a link makes errors, how can the receiver still identify what was sent?
Sending each bit three times and taking a majority vote is one option, but its rate is 1/3. More repetition further reduces the rate. Shannon’s result is stronger: for a suitable channel, fix a positive rate below capacity, then use increasingly long, well-designed block codes to make block error probability tend to zero.
Longer blocks cost delay, storage, and computation. An arbitrary longer code need not perform better. We begin with memoryless channels; logarithms in discrete formulas are base 2 and information is measured in bits.
A channel is a conditional probability model
A channel specifies P(Y=y∣X=x). The input distributionP(X) describes how the sender uses the channel; the conditional distributionP(Y∣X) describes how the link changes an input. These are different objects.
A binary symmetric channel (BSC) can be written as:
Y=X⊕Z,Z∼Bernoulli(p)
Here Z is independent of X, and noise is independent across uses. A bit flips with probability p and stays unchanged with probability 1−p.
This is an average for a specified input distribution. It does not assign the same information content to every individual received bit.
Why maximize over input distributions?
Let α=P(X=1). An output of 1 can arise from an unchanged input 1 or a flipped input 0:
β=P(Y=1)=α(1−p)+(1−α)p=p+α(1−2p)
Given either input, the remaining output uncertainty is the noise entropy h2(p). Thus:
I(X;Y)=h2(β)−h2(p)
For fixed channel parameter p, the second term is constant. Increasing mutual information means increasing output entropy h2(β).
Preparing the visual
The channel stays fixed; input choices change information
Choose a BSC flip probability p, then vary the fraction of transmitted ones α. The point is current mutual information; the curve covers all α and the dashed line marks capacity C. The formula separates output entropy from noise entropy.
{"id":"channel-bsc","title":"The channel stays fixed; input choices change information","summary":"Choose a BSC flip probability p, then vary the fraction of transmitted ones α. The point is current mutual information; the curve covers all α and the dashed line marks capacity C. The formula separates output entropy from noise entropy.","height":950,"html":"<p class=\"eyebrow\" data-i18n=\"eyebrow\"></p><h2 data-i18n=\"heading\"></h2><p class=\"intro\" data-i18n=\"intro\"></p>\n<div class=\"presets\" role=\"group\" data-i18n-label=\"noise\"><button data-p=\"0\">p = 0</button><button data-p=\"0.11\">p = 0.11</button><button data-p=\"0.5\">p = 0.5</button><button data-p=\"1\">p = 1</button></div>\n<label class=\"control\" for=\"bias\"><span data-i18n=\"control\"></span><output id=\"bias-value\"></output></label><input id=\"bias\" type=\"range\" min=\"0\" max=\"100\" value=\"20\" step=\"1\">\n<div class=\"flow\"><div><span data-i18n=\"input\"></span><strong id=\"input-value\"></strong><div class=\"binary-band\"><div id=\"input-one\"></div></div></div><span class=\"arrow\">→</span><div><span data-i18n=\"output\"></span><strong id=\"output-value\"></strong><div class=\"binary-band\"><div id=\"output-one\"></div></div></div></div>\n<p class=\"note\" data-i18n=\"axis\"></p><div class=\"plot\"><svg viewBox=\"0 0 600 190\" preserveAspectRatio=\"none\" role=\"img\" data-i18n-label=\"chart\"><path id=\"capacity-curve\" class=\"curve\"/></svg><div id=\"capacity-line\"></div><div id=\"current-point\"></div></div>\n<div class=\"scale\"><span>α = 0</span><span class=\"middle\">0.5</span><span>1</span></div>\n<div class=\"formula\"><div id=\"output-formula\"></div><div id=\"information-formula\"></div></div>\n<div class=\"metric-pair\"><div><span data-i18n=\"current\"></span><strong id=\"information\"></strong></div><div><span data-i18n=\"maximum\"></span><strong id=\"capacity\"></strong></div></div>\n<div class=\"copy-stack\"><p id=\"explanation\" aria-live=\"polite\"></p><p class=\"reserve\" aria-hidden=\"true\" data-i18n=\"ordinary\"></p><p class=\"reserve\" aria-hidden=\"true\" data-i18n=\"random\"></p><p class=\"reserve\" aria-hidden=\"true\" data-i18n=\"inverted\"></p></div>","css":".intro { margin:8px 0 18px; color:var(--muted); font-size:14px; }\n.control { display:flex; align-items:center; justify-content:space-between; gap:16px; margin-top:18px; }\n.control output { min-width:4em; flex-shrink:0; text-align:center; background:var(--accent-soft); color:var(--accent); padding:2px 8px; border-radius:6px; font-weight:600; }\n.formula { margin-top:18px; padding:14px 0; border-block:1px solid var(--rule); font-size:16px; font-variant-numeric:tabular-nums; overflow-wrap:anywhere; }\n.copy-stack { display:grid; margin-top:14px; color:var(--muted); font-size:14px; }\n.copy-stack > * { grid-area:1/1; }\n.copy-stack .reserve { visibility:hidden; }\n.note { margin-top:14px; color:var(--muted); font-size:12px; }\n.metric-pair { display:grid; grid-template-columns:1fr 1fr; gap:16px; margin-top:18px; }\n.metric-pair > div { min-width:0; }\n.metric-pair span { display:block; font-size:12px; color:var(--muted); }\n.metric-pair strong { display:block; font-size:24px; font-weight:500; font-variant-numeric:tabular-nums; }\n.scale { display:flex; justify-content:space-between; color:var(--muted); font-size:12px; font-variant-numeric:tabular-nums; }\n@media(max-width:480px) { .metric-pair strong { font-size:21px; } }\n.presets { display:flex; }\n.plot { position:relative; margin-top:18px; height:190px; border-left:1px solid var(--rule); border-bottom:1px solid var(--muted); }\n.plot svg { width:100%; height:100%; overflow:hidden; }\n.plot .curve { fill:none; stroke:var(--accent); stroke-width:2.5; vector-effect:non-scaling-stroke; }\n.plot .curve.secondary { stroke:var(--second); stroke-dasharray:5 4; }\n.scale { position:relative; }.scale .middle { position:absolute; left:50%; transform:translateX(-50%); }\n.formula { font-size:14px; }.formula div+div { margin-top:6px; }\n@media(max-width:480px) { .plot { height:170px; } }\n.plot .curve { transition:d .28s cubic-bezier(.22,1,.36,1); }\n.flow { display:grid; grid-template-columns:1fr auto 1fr; gap:12px; align-items:center; margin-top:12px; }\n.flow > div { min-width:0; }.flow span { font-size:12px; color:var(--muted); }.flow strong { display:block; font-size:16px; font-variant-numeric:tabular-nums; }.arrow { padding-top:20px; }\n.binary-band { height:12px; margin-top:6px; background:var(--surface); box-shadow:inset 0 0 0 1px var(--rule); }.binary-band div { height:100%; background:var(--accent); transition:width .28s; }\n#capacity-line { position:absolute; left:0; right:0; border-top:1px dashed var(--muted); }\n#current-point { position:absolute; width:11px; height:11px; border:2px solid var(--paper); border-radius:50%; background:var(--accent); box-shadow:0 0 0 1px var(--accent); transform:translate(-50%,50%); transition:left .2s,bottom .2s; }\n@media(max-width:480px) { .presets { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); }.flow { gap:8px; }.flow strong { font-size:14px; } }\n#capacity-line { transition:bottom .28s cubic-bezier(.22,1,.36,1); }\n","js":"let flip=.11;const bias=document.querySelector('#bias');const h=a=>viz.entropy([a,1-a]);\nfunction draw(){const a=+bias.value/100,b=flip+a*(1-2*flip),noise=h(flip),capacity=1-noise,information=Math.max(0,h(b)-noise);\n document.querySelector('#bias-value').textContent=viz.number(a,2);document.querySelector('#input-value').textContent='α = '+viz.number(a,2);document.querySelector('#output-value').textContent='β = '+viz.number(b,4);\n document.querySelector('#input-one').style.width=a*100+'%';document.querySelector('#output-one').style.width=b*100+'%';\n const points=Array.from({length:201},(_,i)=>{const x=i/200,y=Math.max(0,h(flip+x*(1-2*flip))-noise);return (i?'L':'M')+(x*600).toFixed(3)+','+((1-y)*190).toFixed(3);});document.querySelector('#capacity-curve').setAttribute('d',points.join(' '));\n document.querySelector('#capacity-line').style.bottom=capacity*100+'%';const dot=document.querySelector('#current-point');dot.style.left=a*100+'%';dot.style.bottom=information*100+'%';\n document.querySelector('#output-formula').textContent='β = p + α(1 − 2p) = '+viz.number(b,4);\n document.querySelector('#information-formula').textContent='I = h₂(β) − h₂(p) = '+viz.number(h(b),3)+' − '+viz.number(noise,3)+' ≈ '+viz.number(information,3);\n document.querySelector('#information').textContent=viz.number(information,3)+' bit';document.querySelector('#capacity').textContent=viz.number(capacity,3)+' bit';\n document.querySelector('#explanation').textContent=viz.t(flip===.5?'random':flip===1?'inverted':'ordinary');document.querySelectorAll('[data-p]').forEach(button=>button.setAttribute('aria-pressed',String(+button.dataset.p===flip)));\n}\nbias.addEventListener('input',draw);document.querySelectorAll('[data-p]').forEach(button=>button.addEventListener('click',()=>{flip=+button.dataset.p;draw();}));draw();","audio":false,"strings":{"axis":"Horizontal: input fraction α. Vertical: I, fixed at 0–1 bit. Solid curve: I(α); dashed line: capacity C; point: current value.","chart":"BSC mutual information across input proportions, with capacity and current input marked.","control":"Fraction of transmitted ones α","current":"I(X;Y) for the current input","eyebrow":"WHAT THE MAXIMUM OPTIMIZES","heading":"Why can the same channel carry different information?","input":"Sender","intro":"Fix a channel, then vary its input proportions. The point moves along the full curve. Changing the flip probability lets you compare entire curves.","inverted":"At p = 1, β = 1 − α. Output is always inverted, but the input is fully recoverable. Noise entropy is zero and capacity remains 1, attained with uniform input.","maximum":"Maximum over the curve, C","noise":"BSC flip probability","ordinary":"At α = 0.5, output entropy reaches 1 and mutual information reaches capacity. With deterministic input, all output randomness is noise and I is 0; the channel capacity itself has not decreased.","output":"Receiver","random":"At p = 0.5, the receiver sees ones half the time regardless of input. H(Y) and H(Y|X) both equal 1, so the entire curve is zero. No input distribution conveys information."}}
Binary output entropy is at most 1. Uniform input α=1/2 makes β=1/2, attaining that bound, so:
C=α∈[0,1]maxI(X;Y)=1−h2(p)
A point on the curve is mutual information for the current input distribution; the maximum of the curve is capacity. Sending the same deterministic bit every time gives H(X)=0: even a noiseless link then has no new random message to distinguish.
Flip probability
Capacity (bits/use)
Reason
p=0
1
The input is fully recoverable
p=0.11
About 0.500
With uniform input, about half the output entropy comes from unpredictable flips
p=0.5
0
Output and input are independent for every input distribution
p=1
1
Inverting the received bit recovers the input exactly
Maximum randomness at p=0.5 is destructive; deterministic inversion does not lose information. For a general discrete memoryless channel, C=maxP(X)I(X;Y), and the optimal input need not be uniform. See MIT 6.441, Chapter 16.
What kind of reliability does Shannon’s theorem guarantee?
A block code maps M possible messages to codewords of length n. Its rate is:
R=nlog2Mbits / channel use
The decoder estimates the message from the entire received block. Let Pe denote block error probability for equally likely messages. It differs from the channel’s individual bit-flip probability p.
For a discrete memoryless channel and a fixed R<C, there is a sequence of codes with rates approaching R and Pe→0 as n→∞. At a fixed R>C, no sequence of codes can make block error probability tend to zero.
Dots represent codewords; the surrounding regions suggest possible noisy receptions. More densely packed messages make overlap harder to avoid. Planar positions are not Hamming distances, and circle size is not error probability; this is a spatial intuition for capacity.
The threshold describes asymptotic achievability. It does not supply the error rate of a particular finite block, or say that arbitrary codes at R=C are reliable. Below capacity, good codes exist; an implementation still needs a code, decoder, and block length.
“More redundancy cannot rescue R>C” also needs care. Sending additional channel symbols can lower the actual rate, perhaps below capacity. The converse rules out vanishing error while keeping the rate above capacity.
A counting intuition for 1−h2(p)
For long BSC blocks with 0<p<1/2, the typical noise patterns have exponential scale 2nh2(p). Each codeword produces a region of plausible received sequences. With about 2nR codewords and 2n possible binary received strings, distinguishable high-probability regions suggest:
2nR2nh2(p)≲2n⟹R≲1−h2(p)
This connects capacity to the previous article’s typical sets. It is exponential-scale intuition, not a complete finite-length packing proof. The rigorous theorem needs achievability and converse arguments; it also does not require correcting every possible noise event.
First see competing neighborhoods in 64 positions
Enumerate all six-bit received strings. Each radius-t neighborhood contains Vt=∑j=0t(j6) strings; at t=1, this is seven. Disjoint neighborhoods require MVt≤64, but satisfying this count does not ensure a particular codebook has disjoint neighborhoods. The picture checks membership directly rather than interpreting screen distance as Hamming distance.
Preparing the visual
How do noise neighborhoods overlap as messages increase?
Enumerate all 64 six-bit received strings, vary message count and neighborhood radius, and compare overlaps with the independently calculated exact average ML error for BSC p=0.1. Finite neighborhoods and asymptotic capacity counting are distinguished.
{"id":"channel-packing","title":"How do noise neighborhoods overlap as messages increase?","summary":"Enumerate all 64 six-bit received strings, vary message count and neighborhood radius, and compare overlaps with the independently calculated exact average ML error for BSC p=0.1. Finite neighborhoods and asymptotic capacity counting are distinguished.","height":850,"html":"<p class=\"eyebrow\" data-i18n=\"eyebrow\"></p><h2 data-i18n=\"heading\"></h2><p class=\"intro\" data-i18n=\"intro\"></p>\n<div class=\"packing-controls\"><div><p class=\"control\" data-i18n=\"messages\"></p><div class=\"presets\" role=\"group\" data-i18n-label=\"messages\"><button data-count=\"2\">2</button><button data-count=\"4\">4</button><button data-count=\"8\">8</button><button data-count=\"16\">16</button></div></div><div><p class=\"control\" data-i18n=\"radius\"></p><div class=\"presets\" role=\"group\" data-i18n-label=\"radius\"><button data-radius=\"0\">0</button><button data-radius=\"1\">1</button><button data-radius=\"2\">2</button></div></div></div>\n<div class=\"metrics\"><div class=\"metric\"><span data-i18n=\"rate\"></span><strong id=\"rate\"></strong><span>C ≈ 0.531</span></div><div class=\"metric\"><span data-i18n=\"error\"></span><strong id=\"error\"></strong></div></div>\n<div class=\"space-wrap\"><div><div id=\"space\" role=\"img\" data-i18n-label=\"space\"></div><div class=\"space-legend\"><span class=\"unique\" data-i18n=\"unique\"></span><span class=\"overlap\" data-i18n=\"overlap\"></span><span class=\"codeword\" data-i18n=\"codeword\"></span></div></div><div class=\"space-readout\"><p class=\"note\" data-i18n=\"gridNote\"></p><div class=\"occupancy-stack\"><div class=\"formula\" id=\"occupancy\"></div><div class=\"formula reserve\" id=\"occupancy-reserve\" aria-hidden=\"true\"></div></div><p class=\"note\" id=\"noise-mass\"></p></div></div>\n<label class=\"control\" for=\"received\"><span data-i18n=\"received\"></span><output id=\"received-value\"></output></label><input id=\"received\" type=\"range\" min=\"0\" max=\"63\" value=\"0\">\n<div class=\"probe\" aria-live=\"polite\"><span data-i18n=\"owners\"></span><strong id=\"owners\"></strong><span data-i18n=\"nearest\"></span><div class=\"nearest-stack\"><strong id=\"nearest\"></strong><strong class=\"reserve\" aria-hidden=\"true\">000000, 000000, 000000 (d=6)</strong></div></div>\n<details class=\"audit-details\"><summary data-i18n=\"details\"></summary><div class=\"formula\" id=\"codebook\"></div><p class=\"note\" data-i18n=\"capacity\"></p><div class=\"formula\" id=\"asymptotic\"></div><p class=\"note\" data-i18n=\"asymptoticNote\"></p><p class=\"note\" data-i18n=\"errorNote\"></p></details>","css":"\n.intro { margin:8px 0 14px; color:var(--muted); font-size:14px; }\n.presets { display:flex; flex-wrap:wrap; margin:12px 0; }\n.presets button { flex:1 1 auto; min-width:0; }\n.control { display:flex; align-items:center; justify-content:space-between; gap:12px; margin-top:12px; font-size:14px; }\n.control output { flex-shrink:0; font-variant-numeric:tabular-nums; font-weight:600; }\n.metrics { grid-template-columns:repeat(2,minmax(0,1fr)); margin:12px 0; }\n.metric strong { font-size:23px; }.metric span { font-size:12px; overflow-wrap:anywhere; }\n.note { color:var(--muted); font-size:12px; line-height:1.65; margin-top:10px; }\n.formula { font-size:14px; font-variant-numeric:tabular-nums; overflow-wrap:anywhere; margin:10px 0; }\n.copy-stack { display:grid; margin:12px 0; font-size:13px; line-height:1.65; }\n.copy-stack > p { grid-area:1/1; min-width:0; }.reserve { visibility:hidden; pointer-events:none; user-select:none; }\n.audit-details { border-top:1px solid var(--rule); margin-top:14px; padding-top:10px; font-size:13px; }\n.audit-details summary { cursor:pointer; color:var(--accent); min-height:32px; padding:5px 0; }\n.audit-details summary:focus-visible { outline:2px solid var(--accent); outline-offset:2px; }\n@media(max-width:480px){.intro{font-size:13px}.metric strong{font-size:21px}.presets button{font-size:13px}.formula{font-size:13px}}\n\n.packing-controls { display:grid; grid-template-columns:1fr 1fr; gap:16px; }.packing-controls .presets { margin:6px 0; }.packing-controls button { padding-inline:8px; }.packing-controls .control { margin:0; }\n.space-wrap { display:grid; grid-template-columns:minmax(0,1fr) minmax(0,1fr); gap:20px; margin-top:16px; }#space { display:grid; grid-template-columns:repeat(8,minmax(0,1fr)); gap:3px; }.cell { display:grid; place-items:center; height:29px; border-radius:3px; background:var(--surface); color:var(--muted); font-size:12px; font-variant-numeric:tabular-nums; }.cell.unique { background:var(--accent-soft); color:var(--ink); }.cell.overlap { background:repeating-linear-gradient(135deg,transparent 0 4px,var(--second-soft) 4px 8px),var(--paper);color:var(--ink);border-bottom:2px solid var(--second); }.cell.codeword { box-shadow:inset 0 0 0 1.5px var(--ink); font-weight:700; }.cell.selected { outline:2px solid var(--accent); outline-offset:1px; }\n.space-legend { display:flex; flex-wrap:wrap; gap:4px 12px; font-size:11px; margin-top:8px; }.space-legend span::before{content:'';display:inline-block;width:10px;height:10px;margin-right:4px;background:var(--accent-soft);border:1px solid var(--accent)}.space-legend .overlap::before{background:var(--second-soft);border-color:var(--second)}.space-legend .codeword::before{background:var(--paper);border-color:var(--ink)}\n.probe { display:grid; grid-template-columns:auto minmax(0,1fr); gap:6px 12px; font-size:13px; margin-top:6px; }.probe strong { font-weight:500; text-align:right; font-variant-numeric:tabular-nums; overflow-wrap:anywhere; }.probe span{color:var(--muted)}\n.occupancy-stack,.nearest-stack{display:grid;min-width:0}.occupancy-stack>div,.nearest-stack>strong{grid-area:1/1;min-width:0}.nearest-stack strong{font-family:var(--viz-font-ui)}.probe{grid-template-columns:minmax(0,1fr) minmax(0,1.3fr)}#occupancy,#occupancy-reserve{line-height:1.8}#codebook{font-size:12px;line-height:1.8}#received-value { font-family:var(--viz-font-ui); }\n@media(max-width:600px){.space-wrap{grid-template-columns:1fr;gap:4px}.space-readout{display:grid;grid-template-columns:1fr 1fr;gap:0 10px}.space-readout>p:first-child{grid-column:1/-1}#occupancy{margin:6px 0}.packing-controls{gap:8px}#space{max-width:360px;margin:auto}.cell{height:25px}.space-wrap{margin-top:10px}.probe{font-size:12px}}\n","js":"const $=s=>document.querySelector(s),bits=x=>x.toString(2).padStart(6,'0'),dist=(a,b)=>bits(a^b).replaceAll('0','').length;let count=4,radius=1;\n// Fixed nested codebooks: greedily maximize distance to existing codewords, break ties by integer value.\nconst book=[0];while(book.length<16){let best=-1,score=-1;for(let v=0;v<64;v++){if(book.includes(v))continue;const d=Math.min(...book.map(c=>dist(v,c)));if(d>score){score=d;best=v;}}book.push(best);}\nfor(let i=0;i<64;i++){const e=document.createElement('span');e.className='cell';e.textContent=i.toString().padStart(2,'0');$('#space').append(e);}\nfunction draw(){const codes=book.slice(0,count),y=+$('#received').value,p=.1,vol=[1,7,22][radius],h=viz.entropy([p,1-p]),rate=Math.log2(count)/6;let overlaps=0,covered=0,success=0;\n for(let v=0;v<64;v++){const ds=codes.map(c=>dist(v,c)),owners=ds.filter(d=>d<=radius).length;overlaps+=owners>1;covered+=owners>0;success+=Math.max(...ds.map(d=>p**d*(1-p)**(6-d)))/count;const e=$('#space').children[v];e.classList.toggle('unique',owners===1);e.classList.toggle('overlap',owners>1);e.classList.toggle('codeword',codes.includes(v));e.classList.toggle('selected',v===y);e.dataset.coverage=owners;e.setAttribute('aria-label',bits(v)+': '+owners);}\n const ds=codes.map(c=>dist(y,c)),min=Math.min(...ds),near=codes.filter((c,i)=>ds[i]===min),ownerCount=ds.filter(d=>d<=radius).length,noiseMass=[.9**6,.9**6+6*.1*.9**5,.9**6+6*.1*.9**5+15*.1**2*.9**4][radius];\n $('#rate').textContent=viz.number(rate,3);$('#error').textContent=viz.number((1-success)*100,3)+'%';$('#received-value').textContent=bits(y)+' / '+y;\n $('#occupancy').textContent='M·Vₜ = '+count+' × '+vol+' = '+count*vol+'; '+viz.t('covered')+' '+covered+'/64; '+viz.t('overlap')+' '+overlaps+'/64';$('#noise-mass').textContent='P(d ≤ '+radius+') = '+viz.number(noiseMass*100,3)+'%';\n $('#occupancy-reserve').textContent='M·Vₜ = 16 × 22 = 352; '+viz.t('covered')+' 64/64; '+viz.t('overlap')+' 64/64';$('#owners').textContent=ownerCount+' / '+count;$('#nearest').textContent=near.map(bits).join(', ')+' (d='+min+')';$('#codebook').textContent=viz.t('codeword')+': '+codes.map(bits).join(' · ');$('#asymptotic').textContent='n = 120: 2^[n(R+h₂(p))] = 2^'+viz.number(120*(rate+h),2)+'; 2^n = 2^120';\n $('#space').setAttribute('aria-label',viz.t('space')+' M='+count+', t='+radius+', '+viz.t('covered')+' '+covered+'/64; '+viz.t('overlap')+' '+overlaps+'/64.');document.querySelectorAll('[data-count]').forEach(e=>e.setAttribute('aria-pressed',String(+e.dataset.count===count)));document.querySelectorAll('[data-radius]').forEach(e=>e.setAttribute('aria-pressed',String(+e.dataset.radius===radius)));}\n document.querySelectorAll('[data-count]').forEach(e=>e.addEventListener('click',()=>{count=+e.dataset.count;draw();}));document.querySelectorAll('[data-radius]').forEach(e=>e.addEventListener('click',()=>{radius=+e.dataset.radius;draw();}));$('#received').addEventListener('input',draw);draw();","audio":false,"strings":{"asymptoticNote":"Keep the current R and imagine n=120. This compares the exponential scales of total typical-noise neighborhood demand and receive space, ignoring subexponential factors. It is neither a simulation of an extended short code nor an exact typical-set count. When R+h₂(p)>1, demand has the larger exponent, connecting the picture to the capacity threshold.","capacity":"Capacity C≈0.531 bit/use. Here n stays at 6; R<C does not make this particular short code nearly error-free.","codeword":"Codeword","covered":"Covered","details":"Full codebook, asymptotic count and error definition","error":"Exact average ML block error","errorNote":"Codewords are added greedily to maximize minimum distance to existing codewords, breaking ties by numeric order; global optimality is not claimed. For equiprobable messages, sum over all 64 received strings: Pₑ=1−Σᵧ max꜀ P(y|c)/M. Fixing any one nearest candidate resolves ML ties. Radius t changes only the displayed neighborhoods, not the channel or decoder, so Pₑ stays unchanged. Overlapping-cell count is not error probability.","eyebrow":"Finite receive space → asymptotic counting","gridNote":"Labels 00–63 denote six-bit strings in numeric order. Screen distance is not Hamming distance. Unfilled cells lie outside all radius-t neighborhoods.","heading":"How do noise neighborhoods overlap as messages increase?","intro":"Fix n=6 and BSC p=0.1. Take received strings within distance t of each codeword. Increase M to see how neighborhoods share 64 positions.","messages":"Messages M","nearest":"Nearest codeword(s)","overlap":"Overlap","owners":"Candidates within radius t","radius":"Radius t","rate":"R · bit/use","received":"Inspect a received string","space":"Neighborhood coverage of all 64 received strings","unique":"Unique cover"}}
Neighborhood overlap, excluded noise tails, and decoding error are different quantities. The exact average maximum-likelihood (ML) block error uses the full BSC distribution for the fixed codebook. Radius only controls what is displayed. Even disjoint neighborhoods can miss noise events with distance greater than t.
For long blocks, typical noise sets replace these finite neighborhoods. Their probability approaches one and their exponential size is about 2nh2(p). Total demand has exponent n(R+h2(p)), versus receive-space exponent n. This motivates the capacity count; the six-bit example does not prove the random-coding theorem. The following Hamming code supplies a concrete error-correcting structure.
A real small code: why does distance 3 correct one error?
The Hamming distance between equal-length binary strings counts their differing positions. A code’s minimum distance dmin is the smallest distance between distinct legal codewords.
If at most t positions change and codewords are separated by at least 2t+1, the transmitted codeword is uniquely closest. The triangle inequality explains why: if a received string were within distance t of two codewords, those codewords would be at most 2t apart, contradicting the separation.
dmin≥2t+1
The following is an actual Hamming (7,4) code: four message bits become seven coded bits, with 16 legal codewords and minimum distance 3. Click received positions to inject flips. Every candidate and its distance remain visible.
Preparing the visual
Flip received bits and inspect the protection from distance
Send message 0000 as the all-zero Hamming(7,4) codeword. Toggle any of seven received bits and compare distances to all 16 legal words. One error is corrected; two errors cause miscorrection.
{"id":"channel-hamming","title":"Flip received bits and inspect the protection from distance","summary":"Send message 0000 as the all-zero Hamming(7,4) codeword. Toggle any of seven received bits and compare distances to all 16 legal words. One error is corrected; two errors cause miscorrection.","height":950,"html":"<p class=\"eyebrow\" data-i18n=\"eyebrow\"></p><h2 data-i18n=\"heading\"></h2><p class=\"intro\" data-i18n=\"intro\"></p>\n<div class=\"sent\"><span data-i18n=\"sent\"></span><strong>0000 → 0000000</strong></div>\n<fieldset><legend data-i18n=\"received\"></legend><div id=\"received-bits\"></div></fieldset>\n<div class=\"reset-row\"><span><span data-i18n=\"flips\"></span> <strong id=\"flip-count\"></strong></span><button id=\"reset\" data-i18n=\"reset\"></button></div>\n<div class=\"decoded\"><span data-i18n=\"decoded\"></span><strong id=\"decoded\"></strong></div>\n<div class=\"formula\">d<sub>min</sub> = 3 ≥ 2t + 1 ⇒ t<sub>max</sub> = 1</div>\n<div class=\"copy-stack\"><p id=\"explanation\" aria-live=\"polite\"></p><p class=\"reserve\" aria-hidden=\"true\" data-i18n=\"clean\"></p><p class=\"reserve\" aria-hidden=\"true\" data-i18n=\"corrected\"></p><p class=\"reserve\" aria-hidden=\"true\" data-i18n=\"wrong\"></p></div>\n<details class=\"audit-details\"><summary data-i18n=\"detailLabel\"></summary><p class=\"note\" data-i18n=\"candidates\"></p><div id=\"codebook\"></div></details>\n<p class=\"note\" data-i18n=\"note\"></p>","css":".intro { margin:8px 0 18px; color:var(--muted); font-size:14px; }\n.control { display:flex; align-items:center; justify-content:space-between; gap:16px; margin-top:18px; }\n.control output { min-width:4em; flex-shrink:0; text-align:center; background:var(--accent-soft); color:var(--accent); padding:2px 8px; border-radius:6px; font-weight:600; }\n.formula { margin-top:18px; padding:14px 0; border-block:1px solid var(--rule); font-size:16px; font-variant-numeric:tabular-nums; overflow-wrap:anywhere; }\n.copy-stack { display:grid; margin-top:14px; color:var(--muted); font-size:14px; }\n.copy-stack > * { grid-area:1/1; }\n.copy-stack .reserve { visibility:hidden; }\n.note { margin-top:14px; color:var(--muted); font-size:12px; }\n.metric-pair { display:grid; grid-template-columns:1fr 1fr; gap:16px; margin-top:18px; }\n.metric-pair > div { min-width:0; }\n.metric-pair span { display:block; font-size:12px; color:var(--muted); }\n.metric-pair strong { display:block; font-size:24px; font-weight:500; font-variant-numeric:tabular-nums; }\n.scale { display:flex; justify-content:space-between; color:var(--muted); font-size:12px; font-variant-numeric:tabular-nums; }\n@media(max-width:480px) { .metric-pair strong { font-size:21px; } }\n.presets { display:flex; }\n.plot { position:relative; margin-top:18px; height:190px; border-left:1px solid var(--rule); border-bottom:1px solid var(--muted); }\n.plot svg { width:100%; height:100%; overflow:hidden; }\n.plot .curve { fill:none; stroke:var(--accent); stroke-width:2.5; vector-effect:non-scaling-stroke; }\n.plot .curve.secondary { stroke:var(--second); stroke-dasharray:5 4; }\n.scale { position:relative; }.scale .middle { position:absolute; left:50%; transform:translateX(-50%); }\n.formula { font-size:14px; }.formula div+div { margin-top:6px; }\n@media(max-width:480px) { .plot { height:170px; } }\n.plot .curve { transition:d .28s cubic-bezier(.22,1,.36,1); }\n.sent,.decoded { display:flex; flex-wrap:wrap; align-items:baseline; justify-content:space-between; gap:8px; font-size:13px; }.sent strong,.decoded strong { font:600 17px/1.5 var(--viz-font-ui); }\nfieldset { border:0; padding:0; margin:18px 0 0; min-width:0; }legend { font-size:13px; padding:0; margin-bottom:8px; }\n#received-bits { display:grid; grid-template-columns:repeat(7,minmax(0,1fr)); gap:6px; }#received-bits button { min-height:50px; display:flex; flex-direction:column; gap:0; padding:5px; }#received-bits small { font-size:10px; color:var(--muted); }#received-bits strong { font-size:19px; }#received-bits button[aria-pressed='true'] { background:var(--second-soft); color:var(--second); border-color:var(--second); }\n.reset-row { display:flex; justify-content:space-between; align-items:center; margin-top:10px; font-size:13px; }\n#codebook { display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:6px; margin-top:10px; }\n.codeword { padding:7px 6px; text-align:center; border:1px solid var(--rule); border-radius:6px; background:var(--surface); transition:background .2s,border-color .2s; }.codeword code { display:block; font:13px/1.4 var(--viz-font-mono); }.codeword span { display:block; font-size:11px; color:var(--muted); }.codeword.sent-word { box-shadow:inset 0 0 0 1px var(--ink); }.codeword.nearest { background:var(--accent-soft); border-color:var(--accent); }.codeword.nearest.mistaken { background:var(--second-soft); border-color:var(--second); }\n.decoded { margin-top:16px; }\n@media(max-width:480px) { #received-bits { grid-template-columns:repeat(4,minmax(0,1fr)); }#codebook { grid-template-columns:repeat(2,minmax(0,1fr)); } }\n\n.decoded{margin-top:12px}.copy-stack{margin-top:10px}.formula{margin-top:10px;padding:10px 0}.note{margin-top:10px}\n@media(max-width:480px){#received-bits{grid-template-columns:repeat(4,minmax(0,1fr));gap:5px}#received-bits button{padding:4px 0;min-width:0}.intro{font-size:13px;margin-bottom:12px}.sent{margin-top:12px}.copy-stack{font-size:13px}}\n\n.audit-details { border-top:1px solid var(--rule); margin-top:14px; padding-top:8px; }\n.audit-details summary { cursor:pointer; color:var(--accent); font-size:13px; min-height:36px; padding:6px 0; }\n.audit-details summary:focus-visible { outline:2px solid var(--accent); outline-offset:2px; }\n.audit-details .formula { border:0; margin-top:8px; padding:8px 0; }\n","js":"function encode(value){const [a,b,c,d]=value.toString(2).padStart(4,'0').split('').map(Number);return [a^b^d,a^c^d,a,b^c^d,b,c,d];}\nconst words=Array.from({length:16},(_,i)=>encode(i)),received=Array(7).fill(0),bits=document.querySelector('#received-bits'),book=document.querySelector('#codebook');\nfor(let i=0;i<7;i++){const button=document.createElement('button');button.type='button';button.innerHTML='<small>'+(i+1)+'</small><strong>0</strong>';button.setAttribute('aria-label',viz.t('bit')+' '+(i+1));button.addEventListener('click',()=>{received[i]^=1;draw();});bits.append(button);}\nwords.forEach(word=>{const item=document.createElement('div');item.className='codeword';item.innerHTML='<code>'+word.join('')+'</code><span></span>';book.append(item);});\nfunction draw(){const distances=words.map(word=>word.reduce((s,bit,i)=>s+(bit!==received[i]),0)),nearest=distances.indexOf(Math.min(...distances)),flips=received.reduce((a,b)=>a+b,0);\n received.forEach((bit,i)=>{bits.children[i].querySelector('strong').textContent=bit;bits.children[i].setAttribute('aria-pressed',String(!!bit));});\n distances.forEach((d,i)=>{const el=book.children[i];el.classList.toggle('sent-word',i===0);el.classList.toggle('nearest',i===nearest);el.classList.toggle('mistaken',nearest!==0);el.querySelector('span').textContent='d = '+d;});\n document.querySelector('#flip-count').textContent=flips;document.querySelector('#decoded').textContent=words[nearest].join('')+' → '+nearest.toString(2).padStart(4,'0');document.querySelector('#explanation').textContent=viz.t(flips===0?'clean':flips===1?'corrected':'wrong');\n}\ndocument.querySelector('#reset').addEventListener('click',()=>{received.fill(0);draw();});draw();","audio":false,"strings":{"bit":"Flip received position","candidates":"All 16 legal codewords. d counts positions differing from the received word.","clean":"No bits have flipped. The received word matches the sent word at distance 0. Every other legal word is at least 3 bits away, leaving room for correction.","corrected":"One bit has flipped. The sent word is at distance 1 and every other codeword is at least distance 2. The original is uniquely closest, so all four message bits are recovered.","decoded":"Nearest codeword → decoded message","detailLabel":"Show all 16 valid codewords","eyebrow":"MINIMUM DISTANCE → CORRECTION RADIUS","flips":"Flipped positions","heading":"Why can one wrong bit still reveal the original message?","intro":"Click a received bit to toggle it. A dark outline marks the sent word; a colored background marks the closest candidate. Candidate positions stay fixed.","note":"Actual even-parity Hamming(7,4) coding and nearest-codeword decoding, without random sampling. Rate is 4/7 and minimum distance is 3. A finite correction example does not prove achievement of Shannon capacity.","received":"Received word: click any bit to flip it","reset":"Clear flips","sent":"Fixed transmission","wrong":"The single-error guarantee has been exceeded. Another legal word is closest and decoding is wrong. This Hamming code always has a unique closest candidate, but unique does not mean correct."}}
Data occupies positions 3,5,6,7; even-parity bits occupy 1,2,4. For data bits a,b,c,d, the codeword is:
(a⊕b⊕d,a⊕c⊕d,a,b⊕c⊕d,b,c,d)
The all-zero transmitted word makes flips easy to see. This linear code has the same single-error capability for other messages. The example uses nearest-codeword decoding, which is also maximum-likelihood decoding for a BSC with p<1/2 and equally likely messages.
Any one-bit flip is corrected. Two flips place the received string closer to another codeword, causing miscorrection. In fact, the 16 radius-one neighborhoods exactly cover all 27=128 received strings. A nearest codeword is always unique, but unique does not mean correct. Higher-weight errors are also outside the single-error guarantee.
This small code does not prove Shannon’s limit. Its rate is fixed at 4/7≈0.571. For BSC p=0.1, this decoder succeeds exactly when at most one bit flips:
Pe=1−(1−p)7−7p(1−p)6≈0.1497
Capacity here is approximately 0.531, below the code’s rate. The example shows how a finite code corrects errors, not how to obtain arbitrarily small error at this fixed rate.
Before Gaussian channels: densities and differential entropy
The preceding sections used discrete probabilities. Real-valued signals use a density f(x); integrating it over an interval gives probability. A density value is not the probability of an individual real number, and it can exceed one. Differential entropy is
h(X)=−∫f(x)log2f(x)dx.
For a uniform distribution over an interval of width a, the density is 1/a and h(X)=log2a. It is negative when a<1 and changes when the same quantity is expressed in different units. More generally, h(cX)=h(X)+log2∣c∣ for c=0 when the relevant entropies exist.
Differential entropy therefore is not the number of bits required to encode a real number exactly. Actual coding requires a quantization precision. In the next section, Gaussian output and noise use the same coordinates and units, so their common scale term cancels in the entropy difference. KL and mutual information are invariant under appropriate invertible coordinate changes.
AWGN: where do the logarithm and 1/2 come from?
A real additive white Gaussian noise channel is:
Y=X+N,N∼N(0,σ2),E[X2]≤P
Noise is independent of the input and across uses, with σ2>0. The average-power constraint is essential: unlimited signal power would remove any finite capacity bound.
Given X, the output is just translated noise, so h(Y∣X)=h(N), where h is differential entropy. Gaussian noise has:
h(N)=21log2(2πeσ2)
Also, Var(Y)≤P+σ2. A Gaussian maximizes differential entropy for a given variance, giving:
I(X;Y)=h(Y)−h(N)≤21log2σ2P+σ2
An independent zero-mean Gaussian input X∼N(0,P) attains equality. Hence:
C=21log2(1+SNR)=log2σNσY,SNR=σ2P
The latter form supplies a useful interpretation: multiplying a Gaussian’s standard deviation by a factor adds the logarithm of that factor to differential entropy. Expressing this using a variance ratio introduces the square root and thus 1/2.
Preparing the visual
A wider Gaussian adds entropy logarithmically
Fix noise variance at 1 and use capacity-achieving Gaussian input. Power P gives output standard deviation √(1+P); capacity is the logarithm of the standard-deviation ratio. A separate entropy strip splits h(Y) into fixed h(N) and added capacity.
{"id":"channel-awgn","title":"A wider Gaussian adds entropy logarithmically","summary":"Fix noise variance at 1 and use capacity-achieving Gaussian input. Power P gives output standard deviation √(1+P); capacity is the logarithm of the standard-deviation ratio. A separate entropy strip splits h(Y) into fixed h(N) and added capacity.","height":950,"html":"<p class=\"eyebrow\" data-i18n=\"eyebrow\"></p><h2 data-i18n=\"heading\"></h2><p class=\"intro\" data-i18n=\"intro\"></p>\n<label class=\"control\" for=\"power\"><span data-i18n=\"control\"></span><output id=\"power-value\"></output></label><input id=\"power\" type=\"range\" min=\"0\" max=\"150\" value=\"30\" step=\"1\">\n<div class=\"legend\"><span class=\"noise\" data-i18n=\"noise\"></span><span class=\"output\" data-i18n=\"output\"></span></div>\n<div class=\"plot\"><svg viewBox=\"0 0 600 190\" preserveAspectRatio=\"none\" role=\"img\" data-i18n-label=\"chart\"><path id=\"output-density\" class=\"curve\"/><path id=\"noise-density\" class=\"curve secondary\"/></svg></div>\n<div class=\"scale\"><span>−12</span><span class=\"middle\">0</span><span>12</span></div>\n<div class=\"formula\"><div id=\"variance-ratio\"></div><div id=\"capacity-formula\"></div></div>\n<p class=\"note\" data-i18n=\"entropy\"></p><div class=\"entropy-track\"><div id=\"noise-entropy\"></div><div id=\"capacity-extra\"></div></div><div class=\"scale\"><span>0</span><span>4.5 bit</span></div>\n<div class=\"metric-pair\"><div><span data-i18n=\"base\"></span><strong id=\"base\"></strong></div><div><span data-i18n=\"capacity\"></span><strong id=\"capacity\"></strong></div></div>\n<p class=\"note\" data-i18n=\"note\"></p>","css":".intro { margin:8px 0 18px; color:var(--muted); font-size:14px; }\n.control { display:flex; align-items:center; justify-content:space-between; gap:16px; margin-top:18px; }\n.control output { min-width:4em; flex-shrink:0; text-align:center; background:var(--accent-soft); color:var(--accent); padding:2px 8px; border-radius:6px; font-weight:600; }\n.formula { margin-top:18px; padding:14px 0; border-block:1px solid var(--rule); font-size:16px; font-variant-numeric:tabular-nums; overflow-wrap:anywhere; }\n.copy-stack { display:grid; margin-top:14px; color:var(--muted); font-size:14px; }\n.copy-stack > * { grid-area:1/1; }\n.copy-stack .reserve { visibility:hidden; }\n.note { margin-top:14px; color:var(--muted); font-size:12px; }\n.metric-pair { display:grid; grid-template-columns:1fr 1fr; gap:16px; margin-top:18px; }\n.metric-pair > div { min-width:0; }\n.metric-pair span { display:block; font-size:12px; color:var(--muted); }\n.metric-pair strong { display:block; font-size:24px; font-weight:500; font-variant-numeric:tabular-nums; }\n.scale { display:flex; justify-content:space-between; color:var(--muted); font-size:12px; font-variant-numeric:tabular-nums; }\n@media(max-width:480px) { .metric-pair strong { font-size:21px; } }\n.presets { display:flex; }\n.plot { position:relative; margin-top:18px; height:190px; border-left:1px solid var(--rule); border-bottom:1px solid var(--muted); }\n.plot svg { width:100%; height:100%; overflow:hidden; }\n.plot .curve { fill:none; stroke:var(--accent); stroke-width:2.5; vector-effect:non-scaling-stroke; }\n.plot .curve.secondary { stroke:var(--second); stroke-dasharray:5 4; }\n.scale { position:relative; }.scale .middle { position:absolute; left:50%; transform:translateX(-50%); }\n.formula { font-size:14px; }.formula div+div { margin-top:6px; }\n@media(max-width:480px) { .plot { height:170px; } }\n.plot .curve { transition:d .28s cubic-bezier(.22,1,.36,1); }\n.legend { display:flex; flex-wrap:wrap; gap:12px; margin-top:10px; font-size:12px; }.legend span::before { content:''; display:inline-block; width:16px; margin-right:6px; vertical-align:middle; border-top:2px solid var(--accent); }.legend .noise::before { border-color:var(--second); border-top-style:dashed; }\n.entropy-track { height:25px; display:flex; margin-top:8px; background:var(--surface); }#noise-entropy { background:var(--second); }#capacity-extra { background:var(--accent); transition:width .28s; }\n","js":"const input=document.querySelector('#power'),noiseEntropy=.5*Math.log2(2*Math.PI*Math.E);\nfunction density(sigma){return Array.from({length:481},(_,i)=>{const x=-12+i/20,y=Math.exp(-x*x/(2*sigma*sigma))/(Math.sqrt(2*Math.PI)*sigma);return(i?'L':'M')+(i*600/480).toFixed(3)+','+(190*(1-y/.45)).toFixed(3);}).join(' ');}\ndocument.querySelector('#noise-density').setAttribute('d',density(1));document.querySelector('#noise-entropy').style.width=noiseEntropy/4.5*100+'%';document.querySelector('#base').textContent=viz.number(noiseEntropy,3)+' bit';\nfunction draw(){const power=+input.value/10,ratio=Math.sqrt(1+power),capacity=Math.log2(ratio);document.querySelector('#power-value').textContent=viz.number(power,1);document.querySelector('#output-density').setAttribute('d',density(ratio));\n document.querySelector('#variance-ratio').textContent='σY / σN = √(1 + '+viz.number(power,1)+') ≈ '+viz.number(ratio,3);\n document.querySelector('#capacity-formula').textContent='C = log₂(σY / σN) = ½ log₂(1 + '+viz.number(power,1)+') ≈ '+viz.number(capacity,3)+' bit';\n document.querySelector('#capacity-extra').style.width=capacity/4.5*100+'%';document.querySelector('#capacity').textContent=viz.number(capacity,3)+' bit';\n}\ninput.addEventListener('input',draw);draw();","audio":false,"strings":{"base":"Fixed noise entropy h(N)","capacity":"Entropy difference h(Y) − h(N) = C","chart":"Noise and output Gaussian densities, with x from −12 to 12 and density fixed at 0–0.45.","control":"Input power P (σ² = 1)","entropy":"Entropy strip: gold is h(N), blue is C; together they equal h(Y).","eyebrow":"STANDARD-DEVIATION RATIO → ENTROPY DIFFERENCE","heading":"Why is capacity ½ log₂(1 + SNR)?","intro":"Noise stays fixed. Increase Gaussian input power and compare the widening output distribution with the extra information it permits.","noise":"Dashed: fixed noise N","note":"Density axes stay at x ∈ [−12,12] and 0–0.45. Each complete density integrates to 1; capacity is not their area difference. Input is independent Gaussian under an average-power constraint. The entropy strip has its own 0–4.5-bit scale; capacity is in bits per real channel use.","output":"Solid: output Y = X + N"}}
Noise variance is fixed at 1 and the input is capacity-achieving Gaussian. At P=0, output equals noise and capacity is zero. At P=3, the standard-deviation ratio is 2 and the entropy difference is 1 bit. At P=15, the ratio is 4 and the difference is 2 bits. Each complete density integrates to 1; capacity is not an area difference between the curves.
This also explains logarithmic power gains. At high SNR, doubling power adds approximately 0.5 bits per real channel use. A binary-input or other restricted constellation generally cannot attain this Gaussian-input capacity. See MIT 6.441, Chapter 17.
For the standard continuous-time real AWGN model with bandwidth B and two-sided noise power spectral density N0/2, in-band noise power is N0B. Capacity is commonly written C=Blog2(1+P/(N0B)) bits/s. These units differ from bits per real use; the coefficients cannot be compared without accounting for that distinction.
From a theoretical limit to an implementation
The coding theorem bounds achievable rates. A system must additionally specify block length, target block error probability, decoding latency, power, and computation. Hamming, Reed–Solomon, turbo, LDPC, and polar codes make different structural and implementation tradeoffs. Neither a longer block nor a code-family name alone establishes proximity to capacity.
Random coding proves good codes exist, but storing huge unstructured codebooks and exhaustively decoding them is usually impractical. Engineering seeks structure that permits efficient encoding and decoding while meeting finite-length requirements.
Source–channel separation: align the units first
Source coding removes predictable redundancy; channel coding adds deliberately structured redundancy for correction. For the classical point-to-point setting of a finite-alphabet stationary ergodic source and a discrete memoryless channel, allowing long blocks makes separate compression and error correction asymptotically optimal for reliable transmission.
Suppose a source produces fs symbols/s at entropy rate Hˉ bits/source symbol. A channel is used fc times/s at capacity C bits/use. The condition compares matching units:
fsHˉ<fcC
For example, 1000 source symbols/s at 0.4 bits/symbol require an asymptotic information rate of 400 bits/s. A channel used 1000 times/s with capacity 0.5 bits/use offers a theoretical budget of 500 bits/s. Compression output and channel-code rates can be chosen between them. Finite-block overhead and the reliability target still require separate calculation.
Short delay, multi-user networks, or other stringent constraints can make separately optimized compression and correction less suitable. See MIT 6.441, Chapter 20. The next article considers allowing some information loss: Rate–Distortion and the Information Bottleneck.