Understanding the IPv6 address expander and compressor — concept and principle
An IPv6 address is 128 bits long, written as eight groups of four hexadecimal digits separated by colons. Because that is long, the standard allows shortcuts: leading zeros in a group can be dropped, and one run of all-zero groups can be replaced by "::". This tool converts between the full (expanded) form and the canonical short form recommended by RFC 5952, and also builds the reverse-DNS name under ip6.arpa. It helps when comparing addresses across logs, writing firewall rules or creating PTR records.
How it is calculated
- Expand: split the input at "::". Count the groups on each side; the missing groups (8 minus that count) are filled with 0000. Then pad every group with leading zeros to four digits.
- Compress (RFC 5952): remove leading zeros in each group, write hex in lowercase, and replace the longest run of two or more consecutive zero groups with "::". If two runs are equally long, the first is shortened. A single zero group stays as "0".
- Reverse DNS: take the 32 hex digits of the expanded form, reverse their order, separate each digit with a dot and append ".ip6.arpa".
The principle
"::" can appear only once, because the reader must be able to work out how many zero groups it stands for: 8 minus the groups that are written. RFC 4291 allows several spellings of one address; RFC 5952 picks one canonical spelling so text comparison and searching stay consistent. Reverse DNS works one hex digit (4 bits, a "nibble") at a time, which is why the ip6.arpa name has 32 labels.
Worked example
- Input: 2001:db8::ff00:42:8329.
- Left of "::" are 2 groups (2001, db8); right are 3 (ff00, 42, 8329). Missing: 8 − 5 = 3 zero groups.
- Pad each group: 2001:0db8:0000:0000:0000:ff00:0042:8329.
- Compressing again gives 2001:db8::ff00:42:8329, so the input was already canonical.
- Reverse the 32 digits: 9.2.3.8.2.4.0.0.0.0.f.f.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa.
How to read the result
Use the expanded form for fixed-width storage and sorting, and the compressed form for display and documentation. The prefix 2001:db8::/32 is reserved for documentation (RFC 3849), so addresses like the example never appear on the real internet.
Common mistakes
- Using "::" twice, which makes an address ambiguous and invalid.
- Shortening a single zero group to "::"; RFC 5952 says to write it as 0.
- Using uppercase hex in canonical text; RFC 5952 recommends lowercase.
Frequently asked questions
How many zeros does "::" represent?
As many full 16-bit zero groups as are needed to bring the total to eight.
Is 2001:0db8::1 the same address as 2001:db8::1?
Yes. Leading zeros inside a group do not change the value.
What is the ip6.arpa name used for?
It is the DNS name where a PTR record maps an IPv6 address back to a host name.
Sources: IETF RFC 4291, IP Version 6 Addressing Architecture · IETF RFC 5952, A Recommendation for IPv6 Address Text Representation · IETF RFC 3596, DNS Extensions to Support IP Version 6 · IETF RFC 3849, IPv6 Address Prefix Reserved for Documentation