# Why does "ping X" work, where "X" is an arbtrary whole number?

So, I discovered a strange quirk of the Windows 10 ping utility. If you ping a whole number instead of an IP address, it will "convert" that number to an IPv4 address. The conversion is such that the first octet is your 256^3 spot, second octet is 256^2, third is 256^1, and the last octet being the "ones" place or 256^0.

For example "ping 200" will ping 0.0.0.200, but "ping 400" will ping 0.0.1.144, where the "1" in the third octet represents 256 (256 + 144 = 400).

A quick Google search (although I couldn't think of a great search term) didn't bring anything.

My only two theories are this:

1. It may be the case that in an earlier iteration of the IP schema (i.e. the unused v1, v2, or v3), the plan was to just use single whole numbers. Microsoft, in its' obsession with backwards compatibility wrote a translation algorithm into the ping utility to handle this way way back when ping was first coded.
2. It may be the case that due to the way the ping utility is coded, it normally takes a valid IPv4 address and translates it to a single whole number before doing something with that data. Thus, as a check in the code, if it sees that the user entered a single whole number, it just skips that initial translation step.

Any ideas? It definitely intrigued my co-workers, but they were just as clueless as I am.

EDIT: Just tested it on my Arch Linux machine, and I can confirm that the behavior exists there as well, so that likely discredits my first theory.

The answer is documented in Wikipedia:

Other address representations were in common use when classful networking was practiced. For example, the loopback address 127.0.0.1 is commonly written as 127.1, given that it belongs to a class-A network with eight bits for the network mask and 24 bits for the host number. When fewer than four numbers are specified in the address in dotted notation, the last value is treated as an integer of as many bytes as are required to fill out the address to four octets. Thus, the address 127.65530 is equivalent to 127.0.255.250.

• Huh, surprised that never got covered in my college networking classes lol. Also, -1, really? I asked our Sr. engineer at work who has nearly 15 years IT experience and he had no idea. It's not like it's a well-known fact that you can ping numbers like that. Dec 4, 2020 at 1:00

It's not a quirk. It's a feature.

Remember that the dot notation of an IPv4 address is merely a way to represent the four-byte (i.e 32 bit) integer that is an IPv4 address (and that goes in the 32-bit destination field in an IP packet). Different utilities will accept different formats for this integer.

I know that in the past some browsers accepted decimal integers like this as an address in the address bar. (I was surprised that my two current browsers, Firefox and Chrome, no longer do this.)

".0" can be omitted conditionally

You often use the "ping 127.0.0.1" command to do a loop test on the machine to verify whether the TCP/IP protocol suite of the machine is correctly installed. But did you find it? The same test result can be obtained by using the command "ping 127.1". In fact, the two commands "ping 127.1" and "ping 127.0.0.1" are the same, both of which are performing loop tests.

Why is this so? This is the skill of using IP address in Ping command application. Everyone knows that the IP address is composed of 32 binary digits. In order to make it easier for everyone to remember, every 8 binary digits are converted into decimal digits. Therefore, an easy-to-remember IP address consisting of four-part decimal digits (such as 127.0.0.1 ). Since the Windows operating system has the function of automatically filling ".0", I can change "127.0.0.1" to "127.1".

However, the omission of this ".0" is conditionally restricted and cannot be omitted arbitrarily. In the application of the Ping command, you can only omit one or more ".0"s that appear before the last decimal number of the IP address, such as rewriting the "ping 127.0.0.1" command to "ping 127.1".

If the one or more ".0" is not next to the last part of the decimal number, but in other positions, then this ".0" cannot be omitted, such as "ping 202.0.96.1" cannot be written as "ping 202.96.1" ". This is because the result returned by "ping 202.96.1" is the response message of "202.96.0.1" instead of the response message of "202.0.96.1".