What is the maximum length of a DNS name

With your way of counting, the domain name a.b.c.d.e. would be considered to be five characters long. It suspect that not many people will find that way of counting useful. That way of counting also makes the maximum length vary with the number of labels, so when you have four labels the maximum length is 250 characters, but if you have 127 labels the maximum length is only 127 characters.

Think of it this way: when we print a domain name for human use, we do print the length bytes, it’s just that we print them as periods (all of them but the first length byte). If we didn’t, we wouldn’t be able to tell the difference between a.b.c. and abc.. Since we print them, they should be included when we count the length. And with that way of counting, the maximum length is always 253 characters (including the final period, and the non-printed zero octet for root makes 255).

In other words, if you have a maximum of 250 ASCII characters (letters, numbers, dash), considering that the minimum number of label is 4, you will need to also add 3 printable dots between them which sums up to 253 printable characters (ommited the first length byte and the null label).

Example below (bold are printable characters, and LLs are printed as dots):

LL (1) + LN (63) + LL (1) + LN (63) + LL (1) + LN (63) + LL (1) + LN (61) + NL (1) = 255 bytes

So the new calculation including dots will become:

63 + 1 + 63 + 1 + 63 + 1 + 61 = 253 characters maximum.

Leave a Comment