Computer Networks #5: ICMP - How the Network Tells You When Something Goes Wrong

Imagine you send a letter to your friend.You put their address on it and send it.
But somewhere along the way, something goes wrong.
Maybe the address does not exist. Maybe a road is unavailable.
Maybe the letter keeps getting redirected between two places.
You would want someone to tell you:
"Hey, your letter couldn't reach the destination."
Computer networks need the same kind of mechanism.
This is where ICMP comes in.
What is ICMP?
ICMP stands for:
Internet Control Message Protocol
It is a Network Layer, or Layer 3, protocol used by network devices to communicate information about network conditions, errors, and diagnostics.
The important thing to understand is:
ICMP is not used to carry application data like HTTP or database queries.
Instead, it helps the network communicate things like:
A destination cannot be reached
A packet's TTL expired
A packet is too large for the next network
A network or host is unreachable
A diagnostic request was received
So think of ICMP as the network's error and diagnostic messaging system.
ICMP Does Not Have Ports
This is an important difference between ICMP and TCP/UDP.
TCP and UDP operate at the Transport Layer and use:
Source Port
Destination Port
For example:
Client
Source Port: 52341
Destination Port: 443
↓
HTTPS
ICMP does not work this way.
It does not have source and destination ports.
Instead, ICMP messages have their own:
Type
Code
Checksum
along with additional fields depending on the ICMP message type.
So remember:
TCP / UDP
↓
Ports
ICMP
↓
No ports
Why Do We Need ICMP?
Let's say your computer wants to communicate with a server:
Your Computer
│
▼
Router
│
▼
Router
│
▼
Server
You send an IP packet.
But what happens if the server cannot be reached?
Your computer needs some way to know that.
For example:
Your Computer
│
│ IP Packet
▼
Router
│
X
│
Destination unreachable
The router can generate an ICMP error message and send it back toward the source.
Conceptually:
Your Computer
│
│ IP Packet
▼
Router
│
X
│
│ ICMP Error
▼
Your Computer
The message might effectively communicate:
"I couldn't deliver your packet."
This is one of the main jobs of ICMP.
ICMP Error Messages
ICMP can communicate different kinds of network problems.
For example, a device might tell the sender:
Destination Unreachable
There are different reasons why a destination might be unreachable.
For example:
Network unreachable
Host unreachable
Port unreachable
The exact ICMP message and code depend on what went wrong.
The important idea is:
ICMP allows network devices to report problems back to the source of an IP packet.
What About a Port Being Unreachable?
Here is an interesting case.
Suppose you send a UDP packet to a server:
Destination IP = 10.0.0.5
Destination Port = 9999
The server exists.
The host is reachable.
But nothing is listening on port 9999.
The destination can respond with an ICMP error indicating:
Destination Unreachable
↓
Port Unreachable
This is different from saying:
"The server doesn't exist."
The host can be reachable while the requested service or port is unavailable.
So:
Host unreachable
≠
Port unreachable
That's an important distinction.
The Strange Problem of Packets Getting Lost Forever
Now let's look at one of the most interesting problems in networking.
Imagine two routers accidentally create a loop:
┌─────────────┐
│ ▼
Router A ───→ Router B
▲ │
└─────────────┘
A packet enters this loop.
Router A sends it to Router B.
Router B sends it back to Router A.
Router A sends it to Router B again.
And this could continue forever.
Imagine thousands of packets doing this.
That would be terrible for the network.
So IP has a mechanism to prevent packets from living forever.
It is called: TTL
What is TTL?
TTL stands for:
Time To Live
TTL is a field in the IP header.
For example:
┌──────────────────────┐
│ IP Header │
│ │
│ TTL = 5 │
└──────────────────────┘
Every time the packet passes through a router, the router decreases the TTL.
For example:
Sender
TTL = 5
│
▼
Router A
TTL = 4
│
▼
Router B
TTL = 3
│
▼
Router C
TTL = 2
│
▼
Router D
TTL = 1
Eventually:
TTL = 0
The router cannot keep forwarding the packet.
It discards it.
But now we have another question:
How does the sender know what happened?
This is where ICMP comes back into the story.
ICMP Time Exceeded
When a router receives a packet whose TTL has expired, it discards the packet.
Then it can send an ICMP message back to the original sender.
The message is:
ICMP Time Exceeded
The idea is essentially:
Router:
"I received your packet,
but it's TTL reached zero
before it reached the destination."
The flow looks like this:
Sender
│
│ IP Packet
│ TTL = 1
▼
Router
│
│ TTL becomes 0
│
X Packet discarded
│
│ ICMP Time Exceeded
▼
Sender
This is why TTL is so useful.
It prevents packets from endlessly circulating through the network.
And ICMP tells the sender that the packet was discarded because its TTL expired.
A Small but Important Detail
Do not say:
"ICMP uses TTL to detect packet loops."
That's not quite correct.
The better way to say it is:
IP uses TTL to limit how many router hops a packet can survive. When the TTL expires, the router generates an ICMP Time Exceeded message.
The responsibilities are:
IP
↓
TTL prevents packets from living forever
ICMP
↓
Reports that the TTL expired
This distinction is small, but it shows strong networking fundamentals.
Ping: "Are You There?"
Now let's use ICMP for something practical.
You have probably used:
ping google.com
What is actually happening?
Your computer sends an:
ICMP Echo Request
to the destination.
The destination responds with:
ICMP Echo Reply
So:
Your Computer
│
│ ICMP Echo Request
▼
Server
│
│ ICMP Echo Reply
▼
Your Computer
It's basically your computer asking:
"Are you reachable?"
And the destination responding:
"Yes, I received your request."
What Does Ping Actually Tell Us?
Suppose you run:
ping google.com
and get a response.
That tells you that an ICMP Echo Request reached the destination and an Echo Reply came back.
It can also help measure:
Round Trip Time, or RTT
For example:
Request sent
│
▼
Server
│
▼
Reply received
RTT = 25 ms
So ping is useful for basic network reachability and latency testing.
But remember:
A successful ping does not prove that an application such as HTTPS is working.
A server can block ICMP while still serving HTTPS traffic perfectly.
What Happens With TTL During Ping?
You can also use TTL to understand how packets travel.
Suppose you send a packet with:
TTL = 1
The packet reaches the first router.
The router decrements TTL:
1 → 0
The router discards the packet.
Then it sends:
ICMP Time Exceeded
back to you.
So you might see an error similar to:
Time to live exceeded
This is exactly what happens when you deliberately use a very small TTL.
For example, on systems that support the relevant option:
ping google.com -m 1
can be used to send packets with a TTL of 1.
The exact command-line option varies by operating system, so the important concept is not the command itself.
The important concept is:
TTL = 1
↓
First router
↓
TTL becomes 0
↓
Packet discarded
↓
ICMP Time Exceeded
Now We Can Understand Traceroute
And this leads us to one of the coolest uses of ICMP:
Traceroute
Suppose you want to know:
"What routers does my packet pass through before reaching the server?"
You normally don't have direct visibility into every router along the path.
But TTL gives us a clever trick.
Let's say the path looks like this:
Your Computer
│
▼
Router A
│
▼
Router B
│
▼
Router C
│
▼
Server
We start with:
TTL = 1
Traceroute Step 1
The packet leaves your computer:
TTL = 1
It reaches Router A.
Router A decrements:
1 → 0
The packet is discarded.
Router A sends:
ICMP Time Exceeded
back to your computer.
Your computer now learns:
"The first router on the path is Router A."
You
│
├──── TTL = 1 ────→ Router A
│ │
│ X
│ │
└── ICMP Time Exceeded ─┘
Traceroute Step 2
Now the sender increases the TTL:
TTL = 2
The packet reaches Router A:
2 → 1
Router A forwards it.
Then it reaches Router B:
1 → 0
Router B discards it.
Router B sends an ICMP Time Exceeded message back.
Now we know:
"Router B is the second hop."
You
│
│ TTL = 2
▼
Router A
│
▼
Router B
│
X
│
└──── ICMP Time Exceeded ────→ You
Traceroute Step 3
Now:
TTL = 3
The packet travels:
You
↓
Router A
↓
Router B
↓
Router C
X
Router C's TTL becomes zero.
So Router C sends:
ICMP Time Exceeded
back to you.
Now you know the third hop.
Eventually We Reach the Destination
The process continues:
TTL = 1
↓
Router A
TTL = 2
↓
Router B
TTL = 3
↓
Router C
TTL = 4
↓
Destination
When the probe finally reaches the destination, the destination responds according to the traceroute mechanism being used.
This allows traceroute to construct something like:
1 Router A 2 ms
2 Router B 8 ms
3 Router C 15 ms
4 Server 22 ms
Now you can see the path your packets are taking.
The Clever Idea Behind Traceroute
Traceroute is not magically asking every router:
"What's your IP address?"
Instead, it deliberately causes intermediate routers to generate ICMP error messages by manipulating the packet's TTL.
The trick is:
TTL = 1
↓
First router responds
TTL = 2
↓
Second router responds
TTL = 3
↓
Third router responds
...
So traceroute turns:
TTL expiration
into a way of discovering:
The routers along the path.
This is one of the best examples of how two seemingly unrelated networking concepts, TTL and ICMP, work together.
Conclusion
Don't think of ICMP as another protocol that carries your application's data.
Think of it as:
The network's way of reporting what happened to your IP packet.
Your application might say:
"Send this request to the server."
IP tries to deliver it.
Something might go wrong.
Then ICMP can come back and say:
"Destination unreachable."
"Port unreachable."
"Time exceeded."
"Network problem."
And ICMP can also be used for diagnostics:
Ping
↓
Echo Request / Echo Reply
Traceroute
↓
TTL + ICMP Time Exceeded
The entire picture is:
ICMP
│
┌──────────┴──────────┐
│ │
Error Reporting Diagnostics
│ │
▼ ▼
Destination Unreachable Ping
Port Unreachable Traceroute
Time Exceeded
And remember the most important relationship:
IP
↓
TTL prevents a packet from surviving
forever in the network
ICMP
↓
Reports when that TTL expires
That simple relationship is the key to understanding both ICMP Time Exceeded and Traceroute.
About the author
- I am a third-year undergrad student at Chandigarh University. I am into building backend and applied AI stuff using the modern technologies. I loves to document my learning through the blogs so that I can contribute to the community.
Comments
Join the discussionNo comments yet. Be the first to comment.
Computer Networks, One Packet at a Time
A practical journey through computer networks, understanding how data moves, how protocols communicate, and what really happens behind the internet.






