Morse code: the original variable-length encoding
Morse code (1830s) is one of the earliest electrical communication codes. Its short/long pulse encoding is a classic example of variable-length coding and a precursor to modern entropy coding.
The basics
Each character is a sequence of dots (·) and dashes (–):
A: · –
B: – · · ·
C: – · – ·
SOS: · · · – – – · · · - Dot: 1 time unit.
- Dash: 3 time units.
- Inter-symbol gap inside a letter: 1 unit silence.
- Inter-letter gap: 3 units silence.
- Inter-word gap: 7 units silence.
Frequency-driven length: variable-length coding’s origin
Samuel Morse assigned shorter codes to more frequent letters:
| Letter | Code | Frequency in English |
|---|---|---|
| E | · | 12.7% (highest) |
| T | – | 9.1% |
| A | · – | 8.2% |
| O | – – – | 7.5% |
| I | · · | 7.0% |
The shortest codes (1 unit) go to E and T; rare letters like Q and Z get five-unit codes.
This is the prototype of entropy coding — Huffman coding, arithmetic coding, and modern compression algorithms inherit the idea of “shorter codes for common symbols”.
International Morse vs American Morse
Two historical variants:
- American Morse (1838) — early code with some idiosyncratic characters.
- International Morse (1865) — standardized at an international telegraph conference; the version used today.
When people say “Morse code” now, they mean the international version.
SOS isn’t an acronym
The international distress signal · · · – – – · · · (adopted 1906) was chosen because:
- It’s nine continuous dots and dashes, easy to remember.
- It has a distinctive rhythm even through noise.
- It’s transmitted as a single signal, not as the letters S-O-S.
“Save Our Souls” / “Save Our Ship” are folk etymologies after the fact.
Numbers and punctuation
0: – – – – –
1: · – – – –
2: · · – – –
3: · · · – –
4: · · · · –
5: · · · · ·
6: – · · · ·
7: – – · · ·
8: – – – · ·
9: – – – – · Numbers are uniform 5-unit codes.
International Morse also defines punctuation:
. : · – · – · –
, : – – · · – –
? : · · – – · ·
@ : · – – · – · (added in 2004) Where Morse code still shows up
Telegraphy is long gone, but Morse hasn’t fully disappeared:
1. Amateur radio
Hams use CW (continuous wave) mode. It’s narrow-bandwidth and goes long distances on minimal power.
2. Aviation VOR identification
VOR navigation aids broadcast a three-letter station identifier in Morse code.
3. Military / survival
Backup communication when voice is unavailable or jammed.
4. Accessibility
Some assistive input devices let users type with Morse code.
5. Visual / audio signalling
Flashlight blinks or mirror flashes for SOS in emergencies — still taught as a survival skill.
Memorizing tips
Anchors:
- E = · (shortest)
- T = –
- I = · ·
- M = – –
- S = · · ·
- O = – – –
- H = · · · ·
“Common letters are short” gets you most of the way.
Encoding/decoding
A simple lookup-based implementation:
const morseTable = {
A: '.-',
B: '-...',
C: '-.-.'
// ... all letters
};
function toMorse(text) {
return text
.toUpperCase()
.split('')
.map((c) => morseTable[c] ?? '')
.join(' ');
}
function fromMorse(morse) {
const reverse = Object.fromEntries(Object.entries(morseTable).map(([k, v]) => [v, k]));
return morse
.split(' ')
.map((m) => reverse[m] ?? '')
.join('');
} For timing-accurate output, treat each unit as a time duration and feed it to Web Audio.
Summary
- 1830s code, still alive in narrow contexts.
- Variable-length encoding driven by letter frequency — the conceptual ancestor of Huffman.
- International Morse is the modern standard.
- SOS was chosen as an easy-to-recognize pattern, not as an acronym.
To translate between text and Morse, the Morse code tool on this site converts both ways.