Problem: DNS Name Length Limits
DNS names have character length limits. Knowing these limits helps create valid domain names and hostnames in a network. The maximum length of a DNS name is important for domain management and network setup.
The Answer: DNS Name Length Explained
DNS Name Components
DNS names have these parts:
- Label Length (LL): 1 byte
- Label Name (LN): Up to 63 bytes
- Null Label (NL): 1 byte
Each part of a domain name, split by dots, is a label. The Label Length (LL) shows the size of the Label Name. The Label Name (LN) can be up to 63 bytes long. The Null Label (NL) marks the end of the domain name.
Example: DNS Name Structure
For the domain "www.example.com":
- www (LL: 1 byte, LN: 3 bytes)
- example (LL: 1 byte, LN: 7 bytes)
- com (LL: 1 byte, LN: 3 bytes)
- NL: 1 byte Total: 17 bytes
Maximum Length Calculation
DNS names can be up to 255 bytes long, as set by the DNS protocol. This affects character count:
- You can have 3 full labels (63 characters each).
- The fourth label can have up to 61 characters.
- Each label has a 1-byte length indicator before it.
- The name ends with a 1-byte null label.
The maximum byte count is:
(1 + 63) + (1 + 63) + (1 + 63) + (1 + 61) + 1 = 255 bytes
For printable characters, we count the dots between labels but not the length indicators or null label. This gives:
63 + 1 + 63 + 1 + 63 + 1 + 61 = 253 characters
So, while the total byte limit is 255, you can use up to 253 printable characters in a DNS name.
Tip: Avoid Long DNS Names
Keep DNS names short and simple. Long names can cause issues with some systems and are harder to remember. Aim for names under 40 characters when possible.
The 253-Character Rule
Why 253 Characters?
The 253-character rule for DNS names stems from the way printable characters and total bytes are counted in the DNS protocol. The total byte limit is 255, but not all bytes are visible when writing a domain name.
Printable characters include letters, numbers, hyphens, and dots that separate labels. The byte count includes extra information not displayed, such as label length indicators and the null label at the end.
Here's how it works:
- Printable characters: The parts of the domain name you see and type.
- Total bytes: Printable characters plus the "invisible" bytes used for structure.
Dots between labels are counted as printable characters but represent label length bytes in the total byte count. This is why the maximum printable character count is 253, while the total byte limit stays at 255.
Tip: Understanding Label Length Bytes
Each label in a DNS name is preceded by a byte indicating its length. For example, in "example.com", the first label "example" would be preceded by a byte with the value 7 (the length of "example"), and "com" would be preceded by a byte with the value 3. These length bytes contribute to the total byte count but are not visible in the printed domain name.
Practical Examples
Let's look at examples showing how different label combinations affect the total length of a DNS name:
-
Maximum length example: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc.dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd
This name uses 3 labels of 63 characters each, plus one label of 61 characters, with 3 dots. It totals 253 printable characters.
-
Fewer, longer labels: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
This name uses 2 labels of 63 characters and 1 label of 125 characters, with 2 dots. It also totals 253 printable characters.
-
More, shorter labels: a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.0.1.2.3.4.5.6.7.8.9.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.0.1.2.3.4.5.6.7.8.9.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.0.1.2.3.4.5.6.7.8.9.a.b.c.d.e.f.g.h.i.j
This name uses 126 labels of 1 character each, with 125 dots. It totals 251 printable characters, which is the maximum possible with this many labels.
These examples show that while you can have up to 253 printable characters, the mix of label lengths and number of labels can affect the total length. Longer labels allow for fewer separating dots, while more numerous, shorter labels need more dots, reducing the available characters for the actual domain name parts.