Leading zeros in IPv4 address; is that a no-no by convention or standard?

Solution 1:

There is no standard that demands an IPv4 address be expressed a certain way. That is, the RFC doesn't specify one and multiple formats are in widespread use. Most commonly, you'll see four octets as decimal numbers, but you may also see a single 8-digit hexadecimal number or even a single decimal number used instead. Though octal numbers are uncommon, many implementations accept those too.

This is the reason leading zeroes are usually avoided; the address could be ambiguous. '010.010.010.010' could be in a private range, but could also be Google's famous DNS server at '8.8.8.8'. Numbers that start with one leading zero and do not contain the digits 8 or 9 are often interpreted as octal.

Solution 2:

Ideally it shouldn't matter, as when it breaks down to binary/hex/whatever, the leading zeros shouldn't affect the end result.

Example: 192.168.1.1 to binary
192 = 11000000
168 = 10101000
1 = 00000001
1 = 00000001

Is the exact same as 192.168.001.001
192 = 11000000
168 = 10101000
001 = 00000001
001 = 00000001

See a previous SU answer here.

Solution 3:

Let's go way back when some of us were pioneering the Internet world and look at this from an actual historical standpoint.

Historical Fact: Many if not most of the early routers required (again: required) this exact format for IP address inputs: xxx.xxx.xxx.xxx

What this means: Most folks who were around in the 1980s - 1990s configuring routers never gave a second thought to seeing IP addresses shown as: 192.168.001.010 After all, the padding with leading zeros was most often mandatory and never, ever, have I and I doubt most anyone else encountered a router, firewall, IP host of any kind really, that asked for Octal numbers.

And so...

001.001.001.001 = 1.1.1.1
10.001.1.010 = 10.1.1.10  (inconsistently padding only some octets makes me sad)

Why use padding now when almost year 2020 when most systems accept 1-3 base 10 characters in each octet rather than the old school 3? I can think of a reason that I encounter frequently:

A sorted list of IP addresses in Excel.

10.1.1.1
10.100.254.50
10.16.2.3
10.3.129.44
10.3.2.50

^ thats how Excel would sort these addresses (not numerically ordered!)

But if you have a large list of IPs and wish to sort them: use padding zeros so that Excel provides this sorted list:

010.001.001.001
010.003.002.050
010.003.129.044
010.016.002.003
010.100.254.050

Now, if this list were 300+ addresses, lets say, and you wanted to view them in order, padding is your friend.

Also, if these are in a database and a string sort was used to sort the list, padding is also you friend.