I saw several mentions that the maximum string length of a DNS name (domain name) is 253 characters. Wikipedia seems to be referring this old blog post:
https://en.wikipedia.org/wiki/Hostname http://blogs.msdn.com/b/oldnewthing/archive/2012/04/12/10292868.aspx
On the other hand, if I understood the RFC, this article is wrong. DNS name maximum string length should be 250 ASCII characters instead of 253 based on the following byte sequence which as per RFC1035 is maxed to 255 bytes:
To simplify implementations, the total length of a domain name (i.e., label octets and label length octets) is restricted to 255 octets or less.
As per RFC1035, the domain names is composed as follows:
a domain name represented as a sequence of labels, where each label consists of a length octet followed by that number of octets. The domain name terminates with the zero length octet for the null label of the root. Note that this field may be an odd number of octets; no padding is used.
Which means that the following fields make up domain names:
- Label Length (LL): 1 byte
- Label Name (LN) : 63 bytes (maximum) because the label length maximum value can only be 00111111 (since the two first bits are reserved for special functionalities like pointers)
- Null Label (NL) : 1 byte (representing the root domain)
The format should always be (unlike the blog post):
LL + LN [ LL + LN ... ] + NL
Which means the maximum length should be (1 byte = 1 character = 1 octet):
LL (1) + LN (63) + LL (1) + LN (63) + LL (1) + LN (63) LL (1) + LN (61) + NL (1) = 255 bytes
So if we calculate the string part only (LNs), we get:
63 + 63 + 63 + 61 = 250 characters maximum.
Did I miss anything or we should be updating a few Wikipedia references? The only part I'm unsure is about the Null Label being part of the 255 bytes.