LOADING 0%
// nav_menu.exe
Home Resume Blog Contact Order
English فارسی
~/blog / technology / morse-code

HOW DOES MORSE CODE WORK? WHEN TWO SYMBOLS WERE ENOUGH

Imagine, centuries ago, you have an urgent message that must reach a city hundreds of kilometers away. There is no internet, no mobile phone, no satellite, not even a telephone line. A letter could take days or weeks in transit. But you do have one thing: a wire connecting two points. A simple question arises: how can we send a complete message over this single wire? The answer is astonishing — we don't need a separate wire for every letter. All we need is an agreement. That simple idea built one of the most important breakthroughs in the history of communication.

# One Wire and a Simple Agreement

Over that wire, we can really only distinguish two states from each other: a short signal and a long signal. At first glance, two states seem far too few to carry a complete message. But all we have to do is make an agreement:
contract.txt
.  = short signal  // Dot
-  = long signal   // Dash
 
A = .-
B = -...
C = -.-.
D = -..
E = .
And suddenly we realize we don't need many symbols to build a complete communication system. Two symbols are enough. This simple idea built one of the most important long-distance communication methods of the nineteenth century: Morse code.

# What Is Morse Code? Encoding, Not Encryption

Morse code is a method of encoding information: we convert letters and numbers into sequences of short and long signals. In International Morse there are two primary elements: the dot . and the dash -. For example, the letter S is ... and the letter O is ---. So the famous sequence SOS is written as ... --- ....
But here's the key point: Morse code is not encryption. If I send you .... . .-.. .-.. ---, I haven't hidden anything. Anyone with a Morse table can convert it back to HELLO. Morse is much more like Encoding than Encryption — just as converting a character to a few bytes with UTF-8 changes its representation without hiding it.

# Why Are Two Symbols Enough? The Math of Combinations

To represent information, we don't need a distinct symbol for every possible state. We can use combinations of a few simple symbols. With two states — dot and dash — if we have n positions and two choices at each position, the number of combinations is:
combinations.txt
// one position → two states:
.  -
 
// two positions → four states:
..  .-  -.  --
 
// three positions → eight states:
...  ..-  .-.  .--  -..  -.-  --.  ---
 
count = 2^n
Positions (n) Possible states (2ⁿ) What it covers
1 2 Two letters (E and T)
2 4 Four letters (I, A, N, M)
3 8 Eight letters (S, U, R, W, D, K, G, O)
4 16 More than half the alphabet
5 32 Full alphabet + digits
This same idea underpins the entire digital world. Computers work on exactly this logic: bits, 0 and 1. With 8 bits you get 256 states — enough for every ASCII character. Morse and the CPU feed on the same insight: combining a few simple states builds an enormous space of meaning.

# Why Is E Just a Single Dot? The Hidden Intelligence in the Table

If every letter had the same length, sending messages would take far longer. Here a clever idea comes in: more frequent letters should be shorter. In English, E is extremely common, so it's a single dot: E = . — and T, also very common, is a single dash: T = -. The other letters are then built from combinations:
morse_tree.txt
              start
           /      \
        .        -
      /  \    /  \
   E   T  N   M
  / \  / \  / \  / \
I  A D K S U R W G O
Seen as a tree, Morse becomes even more interesting: each dot or dash moves you one level down the tree. So Morse isn't just an arbitrary table of letters — behind it lies a very simple structure, one we know today as a prefix tree (Trie), used in search, compression, and data routing. It's also strikingly similar to the logic behind Huffman coding, invented more than a century later.

# Try It Yourself: The Interactive Morse Converter

Before going deeper, let's get hands-on. With the tool below you can type any text (English or Persian) and instantly see its Morse equivalent — or type a Morse string and convert it back to text. Letters are separated by spaces and words by /. You can even play the message as audible beeps.
morse_converter.exe — interactive
A fun experiment: Convert HELLO WORLD and look at the output length. Now convert EEEEEEE (seven E's). The difference in output length is exactly the "frequent letter = short code" intelligence we discussed in the previous section.

# The Complete Morse Table: English and Persian

For reference, here is the complete table of English letters, digits, and Persian letters. The Persian letters follow the Persian Morse standard (the code once used for telegraphy in Persian) with their own dedicated codes:
LetterMorseLetterMorseLetterMorseLetterMorse
A.-B-...C-.-.D-..
E.F..-.G--.H....
I..J.---K-.-L.-..
M--N-.O---P.--.
Q--.-R.-.S...T-
U..-V...-W.--X-..-
Y-.--Z--..0-----1.----
2..---3...--4....-5.....
6-....7--...8---..9----.
LetterMorseLetterMorseLetterMorseLetterMorse
ا (A).-ب (B)-...پ (P).--.ت (T)-
ث (S)-.-.ج (J).---چ (CH)---.ح (H)....
خ (KH)---د (D)-..ذ (DH)--..ر (R).-.
ز (Z)--.ژ (ZH)...-س (S)...ش (SH)----
ص (S)-..-ض (Z)..--ط (T)..-ظ (Z)-.--
ع (A).-.-غ (GH)--.ف (F)..-.ق (Q)--.-
ک (K)-.-گ (G)--.-ل (L).-..م (M)--
ن (N)-.و (V).--ه (H)..-..ی (E)..
Note: Watch the differences — for example, the Persian letter و is .-- while English V is ...-. Every language has its own table, which is exactly why Morse isn't a "language" — it's an encoding system any language can use.

# Silence Is Part of the Message: Timing in Morse

Suppose I send ..... How do we know it's an H? Easy. But now imagine this arrives with no gaps at all: ......-...-..---. Is that HELLO, or something completely different? This is where time and spacing enter the system — and this part may matter even more than the dots and dashes themselves.
In International Morse, one dot is taken as a single unit of time, and every other element is defined relative to it:
Element Standard length
Dot 1 unit
Dash 3 units
Gap between elements of a letter 1 unit
Gap between letters 3 units
Gap between words 7 units
So ... --- ... isn't just three groups of dots and dashes; between them sit silences of precise lengths that themselves carry information. Morse information lives not only in the shape of the signal but also in its timing. Silence is data.

# What If the Power Goes Out? Morse Doesn't Need a Wire

One of the most fascinating properties of Morse is this: we don't strictly need electricity or a telegraph wire. Morse only says: produce two distinguishable states in a way the receiver can recognize. So we can send messages by sound, light, radio, a flashlight, or even taps. With a flashlight: a short blink is a dot, a long flash is a dash.
Ways to send Morse
  • Sound — short and long beeps
  • Light — flashlight or lantern blinks
  • Radio — continuous wave (CW)
  • Taps — knocking on a pipe or wall
  • Flags, or even blinking your eyes
Why it still matters
  • Works in emergencies with no infrastructure
  • Executable with the simplest possible tools
  • Amateur radio CW is still alive today
  • Excellent signal-to-noise ratio
Suppose we want to send SOS: ... --- ... — three short blinks, three long flashes, and three short blinks again. The same message — no internet, no screen, not a single word.

# Where Did the Story Begin? May 24, 1844

In the 1830s, Samuel Morse was working on the electromagnetic telegraph, and together with collaborators including Alfred Vail, developed a system for sending messages with dots and dashes. The core problem was simple: how does information traveling over a wire become human language at the destination? The solution was the very chain computers still perform constantly today:
1
Letter — human input
2
Code — converted to dots and dashes
3
Signal — travels over the wire
4
Code — dots and dashes recognized
Letter — human output
On May 24, 1844, Morse sent a famous message from Washington to Baltimore: "What hath God wrought?" — from a room in the US Capitol to Alfred Vail in Baltimore. For the first time in history, information produced by a human at one point could travel electrically, far faster than any previous method, to a distant point. It's the same lineage that later became Telegraph → Telephone → Radio → Internet → Mobile Networks → Satellite Internet.
What was the real leap? Before the telegraph, the speed of information was limited to the speed of a human, horse, train, or ship. The telegraph broke that chain: information could move without a human carrier having to travel. The message no longer needed to move physically — it only needed to become a signal.

# How Do We Know Where a Message Ends? The Lesson of Framing

One of Morse's most interesting problems is exactly this. Look at .... . .-.. .-.. --- — clearly five letters spelling HELLO. But remove the gaps (......-...-..---) and crucial information is lost. In a communication system, the data alone isn't enough: the rules for separating pieces of data are part of the protocol.
You see this concept almost everywhere today; it's called Framing:
System Framing components
Morse Signal + Timing + Gap
Internet packet Header + Payload + Length + Checksum
Files Start + Data + End (Delimiter)
JSON / CSV Braces / Commas / Quotes
So Morse is one of the simplest and oldest examples of this idea: communication isn't just sending data — both sides must agree on how to read the data too.

# Let's Build Our Own Morse Encoder

Now for every programmer's favorite part. First we define the Morse table and build its reverse:
morse_table.py — Python
MORSE = {
    "A": ".-",    "B": "-...",  "C": "-.-.",
    "D": "-..",   "E": ".",     "F": "..-.",
    # ... up to Z and 0 to 9
}
 
REVERSE_MORSE = {
    code: char
    for char, code in MORSE.items()
}
Now the text-to-Morse function — letters separated by spaces, words by /:
encode.py — Python
def encode(text):
    words = text.upper().split()
 
    return " / ".join(
        " ".join(MORSE.get(char, "?") for char in word)
        for word in words
    )
decode.py — Python
def decode(morse):
    words = morse.strip().split(" / ")
 
    return " ".join(
        "".join(
            REVERSE_MORSE.get(code, "?")
            for code in word.split()
        )
        for word in words
    )
run.py — output
text = "HELLO WORLD"
encoded = encode(text)
decoded = decode(encoded)
 
print("Original :", text)
print("Morse   :", encoded)
print("Decoded  :", decoded)
 
# Original : HELLO WORLD
# Morse   : .... . .-.. .-.. --- / .-- --- .-. .-.. -..
# Decoded  : HELLO WORLD
What happened here closely mirrors many real computer systems: input text is transformed by Encoding into its Morse representation, transmitted, and transformed back by Decoding into readable text at the destination — exactly what UTF-8, Base64, and thousands of other protocols do every day.

# Taking Morse Out of the Computer: LED and Arduino

We can go one step further. Suppose we've connected an LED to an Arduino. We can turn the same idea into light: a dot means the LED is on for 100ms, a dash means on for 300ms — and we honor the gaps with the same standard ratios:
morse_led.ino — Arduino
const int LED = 13;
const int UNIT = 100// ms
 
void dot() { digitalWrite(LED, HIGH); delay(UNIT);       digitalWrite(LED, LOW); }
void dash() { digitalWrite(LED, HIGH); delay(UNIT * 3); digitalWrite(LED, LOW); }
 
// SOS: ... --- ...
dot(); dot(); dot();   delay(UNIT * 3);
dash(); dash(); dash(); delay(UNIT * 3);
dot(); dot(); dot();   delay(UNIT * 7);
And suddenly something used for telegraphy in the nineteenth century comes alive again on a modern microcontroller — this time with an LED instead of a telegraph wire. The chain is the same: Python → Morse encoder → dots and dashes → Arduino → light.

# Morse Is Not a "Language" — and the Real Story of SOS

People sometimes say "Morse is a language," but technically it's better described as an encoding system. Morse itself isn't anything like English, Persian, or Japanese; it's a bridge between information and a transmittable signal. If your language is English, you convert HELLO using the English table; if it's Persian, you use the Persian Morse table (which has dedicated codes for letters like چ، گ، ژ، پ). The chain is always the same: Language → Characters → Morse Encoding → Signal.
And now the most famous Morse string in history: ... --- .... The fun fact is that SOS doesn't stand for anything; the pattern became famous mostly for its simplicity and recognizability. Three short signals, three long signals, three short signals — a pattern that's very hard to mistake for anything else, both audibly and visually. It was adopted as a maritime distress signal in the early twentieth century.

# From Morse to the Internet: An Idea That's Still Alive

Today, sending a simple sentence might traverse this chain: keyboard → operating system → encoding → TCP/IP → Wi-Fi/5G → router → internet → server → database. But nearly two centuries ago, the entire system boiled down to: letter → dot or dash → wire → signal → dot or dash → letter. Technologically, the distance between these two worlds is enormous — but in terms of the core idea, nothing has changed:
1
Complex information — text, audio, images
2
Simple representation — dots and dashes, or 0s and 1s
3
Transmission — wire, radio, fiber
Reconstruction — a readable message at the destination
Computers have bits: 0 and 1. Morse has: dot and dash. Across all these systems runs one shared principle: the sender and receiver must agree on the rules for representing and interpreting information. Morse demonstrates this concept in its simplest possible form.
takeaway.txt
You don't always need a complex system to deliver a complex message;
sometimes it's enough for two sides to agree, precisely,
on the meaning of a few simple symbols.