How to ping if you've never pinged before
Nothing is instant
Networks are fast. No doubt about it.
In a race from Exmouth to Hyderabad, even a slow network packet is going to kick my ass.
But when every millisecond matters, understanding the latency – the delay between a user clicking a button and something happening – can be enlightening.
Wi-Fi, cell and satellite communications are fast. Cabled connections are blinding. Routers make more decisions per-second than most of us do in a lifetime. But none of these are instant.
Thanks to the laws of physics, the latency inherent to waiting for an electron to arrive, for a wave to propogate or for a routing decision to be made is inevitable.
Measuring network latency with ping
ping is a tool that we can use to measure network latency. If you’re running Linux, macOS or Windows then you’ve got it installed already.
If you ever hear someone say they’re going to “ping the server”, this is what they’re talking about.
When we ping a device on a network, the tool behind-the-scenes will:
- Make a note of the time.
- Send an “echo request” message to the destination device.
- Wait for the destination device to echo the message back to us.
- Calculate the difference between the start and current time.
In the end, the time difference tells us how long it took for the message – a single network packet – to travel from our device to the destination then back again. This is known as a round-trip.
The name “ping” is apparently taken from the sonar technology used by submarines and the like, which broadcasts “pings” and listens for their echoes to determine how far away the reflecting object is.
That’s fine, but I also like the ping pong analogy; we “ping” the ball to our opponent, then wait for the ball to be volleyed back.
It’s just a bit more fun than the thought of being caught underwater by a stealth nuclear platform literally pulverising my frail human body with 235 decibels of navigational soundwaves, y’know?
Time for a demo
Let’s try it out by pinging the hardware hosting this blog!
If you’re in Windows, open a Command Prompt by searching for
cmd. In macOS, search for
ping getcodelove.com -c 3
ping to send echo requests to getcodelove.com, and
-c 3 tells
ping to do it three times (as in “
You should see something like this:
PING getcodelove.com (22.214.171.124): 56 data bytes 64 bytes from 126.96.36.199: icmp_seq=0 ttl=244 time=14.678 ms 64 bytes from 188.8.131.52: icmp_seq=1 ttl=244 time=15.687 ms 64 bytes from 184.108.40.206: icmp_seq=2 ttl=244 time=15.734 ms --- getcodelove.com ping statistics --- 3 packets transmitted, 3 packets received, 0.0% packet loss round-trip min/avg/max/stddev = 14.678/15.366/15.734/0.487 ms
There’s a lot of information there, but the relevant summary is in the final line.
round-trip min/avg/max/stddev = 14.678/15.366/15.734/0.487 ms
This tells us:
- The fastest of the three round-trips took 14.678 milliseconds.
- The mean average of the three round-trip durations is 15.366 milliseconds.
- The slowest of the three round-trips took 15.734 milliseconds.
- The standard deviation of the three round-trip durations is 0.487 milliseconds.
So, it takes about 15 milliseconds for my laptop to send a request to the blog’s host and for the first bit of the response to arrive.
Naturally it takes more than 15 milliseconds for all the content to download, but the latency is 15 milliseconds.
What if ping doesn’t return any results?
ping won’t be able to return any results.
For example, here I tried to ping cartoonnetwork.co.uk:
PING cartoonnetwork.co.uk (220.127.116.11): 56 data bytes Request timeout for icmp_seq 0 Request timeout for icmp_seq 1 --- cartoonnetwork.co.uk ping statistics --- 3 packets transmitted, 0 packets received, 100.0% packet loss
There’s no guarantee that a ping will ever reach its destination, nor any guarantee that the destination will echo it back. In this case, the owner of cartoonnetwork.co.uk has either disabled request echos, or maybe a firewall is preventing the packet getting to the server.
What can you do about it? Not much, I’m afraid.
ping vs ping pong
Just for fun, how does
ping compare to ping pong? I’m guessing a ping is pretty fast, but how fast?
The fastest ping pong serve I could find was 15 metres per second.
Now, to record the speed of a ping, I need to know how far away a server is and how long a round-trip ping takes. The Reserve Bank of India’s website is registered in Mumbai, and it seems a safe assumption that it would be hosted within the country. So for the sake of a rough distance, let’s assume it’s in Mumbai. That’s about 7,425 kilometres from my home in sunny Exmouth. A round-trip then would be 14,850 kilometres.
Let’s ping it.
PING rbi.org.in (18.104.22.168): 56 data bytes 64 bytes from 22.214.171.124: icmp_seq=0 ttl=240 time=136.445 ms 64 bytes from 126.96.36.199: icmp_seq=1 ttl=240 time=137.595 ms 64 bytes from 188.8.131.52: icmp_seq=2 ttl=240 time=138.237 ms --- rbi.org.in ping statistics --- 3 packets transmitted, 3 packets received, 0.0% packet loss round-trip min/avg/max/stddev = 136.445/137.426/138.237/0.741 ms
Taking the average, the
ping took 137.426 milliseconds to travel 14,850 kilometres.
That’s 0.137426 seconds to travel 14,850,000 metres.
That’s 108,058,155 metres per second. So yeah, faster than a ping pong serve, but not quite touching the speed of light at 299,792,458 metres per second.
I’m not sure what I was trying to prove here. Oh well. Mathematics is its own reward, and
ping is cool.