About the IPv6 Expand & Compress
This IPv6 expand and compress tool converts any IPv6 address between its full form — eight groups of four hexadecimal digits — and its shortest canonical form. Leading zeros are dropped and the longest run of zero groups is replaced by "::", following the RFC 5952 rules that most operating systems, routers and log tools use, so the output is safe to compare or store.
Add a prefix length such as /48 or /64 and it also works as an IPv6 subnet calculator: you get the network address, first and last address, the exact number of addresses in the block and how many /64 subnets it contains. The address type (global unicast, link-local, unique local, multicast, documentation and so on) is identified from the IANA special-purpose registry, and the ip6.arpa reverse DNS name is generated for PTR records.
Network engineers, sysadmins writing firewall rules and developers normalising addresses in a database will find it useful. Embedded IPv4 notation (::ffff:192.0.2.1) and zone IDs (fe80::1%eth0) are accepted.
How to use the ipv6 expand & compress
- 1Paste an IPv6 address, in full or shortened form.
- 2Optionally add a prefix length such as /48 or /64.
- 3Copy the expanded or compressed form you need.
- 4Use the network, first and last address to write routes or firewall rules.
- 5Copy the ip6.arpa name to create a reverse DNS (PTR) record.
Formula and method
An IPv6 address is a 128-bit number written as eight 16-bit groups in hexadecimal. Expanding pads every group to four digits and replaces "::" with as many 0000 groups as are needed to reach eight. Compressing follows RFC 5952: lowercase hex, leading zeros removed in each group, and the longest run of two or more all-zero groups replaced by "::" (the first run wins a tie); a single zero group is written as 0, not "::".
For a prefix length p, the mask has p one-bits followed by 128 − p zero-bits. AND-ing the address with the mask gives the network address, OR-ing the network with the inverted mask gives the last address, and the block contains 2^(128 − p) addresses. The reverse DNS name lists all 32 nibbles in reverse order under ip6.arpa.
- p
- Prefix length in bits (0–128)
- mask
- p one-bits followed by (128 − p) zero-bits
Worked examples
Documentation address in a /64
The "::" stands for three zero groups, so the full form is 2001:0db8:0000:0000:0000:ff00:0042:8329. Masking to /64 keeps the first four groups, giving the network 2001:db8::/64, which spans 2^64 addresses ending at 2001:db8::ffff:ffff:ffff:ffff.
Compress a fully written address
There are two runs of two zero groups. RFC 5952 compresses only one, and when runs tie the first one is shortened, giving 2001:db8::1:0:0:1 in lowercase.
A /48 site prefix
A /48 keeps the first three groups (2a00:1450:4001) and leaves 80 host bits. It contains 2^16 = 65,536 /64 subnets, from 2a00:1450:4001:0::/64 to 2a00:1450:4001:ffff::/64.
Loopback address and its reverse DNS name
::1 is seven zero groups followed by 0001, the IPv6 loopback address. Its reverse DNS name lists all 32 nibbles backwards, starting with the final 1.
Frequently asked questions
How do you expand a shortened IPv6 address?+
Pad each group to four hex digits with leading zeros, then replace "::" with enough 0000 groups to make eight in total. For example 2001:db8::1 becomes 2001:0db8:0000:0000:0000:0000:0000:0001.
What are the rules for compressing an IPv6 address?+
RFC 5952 says: use lowercase, drop leading zeros in every group, replace the longest run of two or more zero groups with "::" (the first one if there is a tie), and never use "::" for a single zero group. "::" may appear only once.
How many addresses are in a /64?+
A /64 contains 2^64 = 18,446,744,073,709,551,616 addresses. It is the standard subnet size for a LAN because stateless address autoconfiguration (SLAAC) uses the 64-bit interface identifier.
What is the 2001:db8:: prefix?+
2001:db8::/32 is reserved for documentation and examples by RFC 3849 and is never routed on the internet, much like 192.0.2.0/24 for IPv4. RFC 9637 added 3fff::/20 as a larger documentation block.
What does fe80:: mean in an IPv6 address?+
Addresses in fe80::/10 are link-local: every IPv6 interface creates one automatically and it is only valid on the local network segment. Because it is ambiguous across interfaces, it is often written with a zone ID such as fe80::1%eth0.