49

Is there a maximum allowed subdomain depth supported by webservers or browsers?

For example, could a domain like foo.bar.baz.monkey.pirate.google.com cause problems?

braveterry
  • 897
  • 2
  • 7
  • 13

3 Answers3

43

I believe the DNS itself can have up to 127 levels of label, each label can be up to 63 characters and the maximum length of the whole record is limited to 253 characters as you have to encode the length and a terminating 0.

user9517
  • 115,471
  • 20
  • 215
  • 297
  • 11
    The 127 levels is just a consequence of the 255 character limit (which includes the length and a trailing dot, but not a terminating 0). – Chris S Mar 06 '14 at 14:52
  • 2
    wikipedia also mentiones the 127 level limit. http://en.wikipedia.org/wiki/Subdomain#Overview regarding webservers and browsers they must be analyzed and tested individually – weberik Mar 06 '14 at 17:58
  • 1
    With the caveat that just using the IP address becomes easier to remember if the name gets too long and ridiculously convoluted, so there's a practical user-patience-for-nonsense limit. – milli Mar 08 '14 at 20:45
  • 2
    @milli Well, that depends on the domain. A random 32-bit number, to me, is harder to remember than now.is.the.time.for.all.good.men.to.come.to.the.aid.of.their.country. Because I don't know how your memory works, but mine's definitely a graph database. – Parthian Shot Aug 01 '14 at 14:53
15

There is no defined maximum in terms of the number of dot-delimited subdomains, but DNS does limit the maximum overall length of a hostname (including the dots) to 255 characters.

James Sneeringer
  • 6,835
  • 24
  • 27
5

Due to rfc1035:

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.

Also

Each label is represented as a one octet length field followed by that number of octets. Since every domain name ends with the null label of the root, a domain name is terminated by a length byte of zero

So, maximum valid length is 255-2 symbols (tested in DIG). Whole UDP message also should be less or equal 512 bytes. But that's not too small and makes IPoverDNS possible.

loadaverage
  • 151
  • 1
  • 4