title: What is the maximum length of a DNS name
body: <p>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:</p>
  
  <p><a href="https://en.wikipedia.org/wiki/Hostname" rel="noreferrer">https://en.wikipedia.org/wiki/Hostname</a>
  <a href="http://blogs.msdn.com/b/oldnewthing/archive/2012/04/12/10292868.aspx" rel="noreferrer">http://blogs.msdn.com/b/oldnewthing/archive/2012/04/12/10292868.aspx</a></p>
  
  <p>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 <a href="https://www.ietf.org/rfc/rfc1035.txt" rel="noreferrer">RFC1035</a> is maxed to 255 bytes:</p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p>As per RFC1035, the domain names is composed as follows:</p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p>Which means that the following fields make up domain names:</p>
  
  <ol>
  <li>Label Length (<strong>LL</strong>): 1 byte </li>
  <li>Label Name (<strong>LN</strong>) : 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)</li>
  <li>Null Label (<strong>NL</strong>) : 1 byte (representing the root domain)</li>
  </ol>
  
  <p>The format should always be (unlike the blog post):</p>
  
  <p><strong>LL</strong> + <strong>LN</strong> [ <strong>LL</strong> + <strong>LN</strong> ... ] + <strong>NL</strong></p>
  
  <p>Which means the maximum length should be (1 byte = 1 character = 1 octet):</p>
  
  <p><strong>LL</strong> (1) + <strong>LN</strong> (63) + <strong>LL</strong> (1) + <strong>LN</strong> (63) + <strong>LL</strong> (1) + <strong>LN</strong> (63) <strong>LL</strong> (1) + <strong>LN</strong> (61) + <strong>NL</strong> (1) = 255 bytes</p>
  
  <p>So if we calculate the string part only (<strong>LN</strong>s), we get:</p>
  
  <p>63 + 63 + 63 + 61 = 250 characters maximum.</p>
  
  <p>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.</p>