7

I teach a class on a software product my company makes and I find that students frequently add leading zeros to a configuration page to have the software connect to our hardware. Leading zeros are problematic in our software, that's how and why this comes up.

I always explained that leading zeros were against "the standard" thinking that's what I had been taught. As I was submitting the bug report up the chain to my engineering department, I was unable to find an authoritative source for this (i.e. "The Standard"), but I did find some interesting and related information.

Are leading zeros bad because of convention, or do they go against the standard?

This was the closest I could find to a standard to not use leading zeros, but it's an expired draft of some kind:

Textual Representation of IPv4 and IPv6 Addresses

In the relevant section, it says:

3 Syntax and Semantics

3.1 IPv4 Dotted Octet Format

   A 32-bit IPv4 address is divided into four octets.  Each octet is
   represented numerically in decimal, using the minimum possible number
   of digits (leading zeroes are not used, except in the case of 0
   itself).  The four encoded octets are given most-significant first,
   separated by period characters.

        IPv4address = d8 "." d8 "." d8 "." d8

        d8          = DIGIT               ; 0-9
                    / %x31-39 DIGIT       ; 10-99
                    / "1" 2DIGIT          ; 100-199
                    / "2" %x30-34 DIGIT   ; 200-249
                    / "25" %x30-35        ; 250-255

I also found the following articles discussing the phenomenon:

Ping and FTP Resolve IP Address with Leading Zero as Octal

Leading zeros in IP address can result in incorrect routing

Are IP addresses with and without leading zeroes the same?

Is there any documentation for omitting zeroes in dot-decimal notation of IPV4 addresses?

2
  • Thanks for the link edits. Normally I prefer to have the full text of the URL below the title, but I couldn't get that done, and then I couldn't have more than 2 links, so that really cleaned up the question. Jun 17, 2015 at 16:29
  • In the end, it all comes down to the parser implementation, so most systems should like it fine, but some may not.... standards implementations are always like that. Jun 17, 2015 at 16:45

4 Answers 4

8

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.

3
  • Which RFC are you referring to? Jun 17, 2015 at 17:49
  • 1
    @allanonmage - In the context used. The only possability would be the RFC that cover IPv4
    – Ramhound
    Jun 17, 2015 at 18:23
  • 1
    RFC 791, to be exact. Jun 17, 2015 at 20:48
1

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.

1
1

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.

-1

0.0.0.0/8 is reserved for the local network (see RFC 6890 or for an easier read https://en.wikipedia.org/wiki/IPv4#Special-use_addresses).

Thus any address starting with 0 is valid but it's not the ip address of a particular machine.

1
  • I'm afraid, you're talking about something different. The OP is asking about zero-padded octets, not about zero octet(s). He's trying to find a standard describing if, for example, an IP address written as 001.002.003.004 (which is the same as 1.2.3.4.) is valid. Aug 25, 2020 at 14:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .