IPv6 Compression and Expansion
Shorten an IPv6 address to its one canonical form or expand it to all 32 digits, and see which zeros go, why one run became :: and which RFC 5952 rule your typing broke. Lists work too.
Read as IPv6
One address, or a list with one per line (up to 100). Converted in your browser; nothing is sent.
2001:db8::1:0:0:1
RFC 5952, rule by rule
- Compressed (RFC 5952)
- Expanded (full)
- In a URL
- As a number
- Decimal · hex · binary
- Reverse DNS name
How do you compress an IPv6 address?
Lowercase it, drop the leading zeros in each group, then replace the longest run of two or more all-zero groups with ::, the first run if two are equally long.
That gives the one canonical form RFC 5952 asks software to print. Programs must still accept every other valid spelling as input, so compressing never changes the address, only how it is written.
2001:0DB8:0000:0000:0000:FF00:0042:8329392001:0db8:0000:0000:0000:ff00:0042:8329392001:db8:0:0:0:ff00:42:8329272001:db8::ff00:42:83292239 → 22 characters

What you typedUppercase, leading zeros and all: any valid spelling is read.Dropped zerosLeading zeros struck out, group by group.The run that becomes ::The longest run of zero groups; on a tie, the first.Runs that stayOther zero runs keep their 0s, with the reason.Rule by ruleHow many RFC 5952 rules the typing broke; the checklist under it names each one and what changed.What are the IPv6 compression rules?
RFC 5952 sets five rules: drop leading zeros, make :: as long as possible, never use :: for a single zero group, compress the longest run (the first on a tie), and write hex letters in lowercase.
A sixth recommendation covers addresses that carry IPv4: after a prefix such as ::ffff:, write the last 32 bits as a dotted IPv4 address. The tool checks each rule against what you typed and names the ones it fixed.
1Leading zeros dropped§4.1
Right: 2001:db8::1
Wrong: 2001:0db8::0001
2:: as long as possible§4.2.1
Right: 2001:db8::2:1
Wrong: 2001:db8:0:0:0:0:2:1
3No :: for one group§4.2.2
Right: 2001:db8:0:1:1:1:1:1
Wrong: 2001:db8::1:1:1:1:1
4Longest run, first on a tie§4.2.3
Right: 2001:db8::1:0:0:1
Wrong: 2001:db8:0:0:1::1
5Lowercase§4.3
Right: 2001:db8::a
Wrong: 2001:DB8::A
+Dotted IPv4 tail§5
Right: ::ffff:192.0.2.1
Wrong: 0:0:0:0:0:ffff:192.0.2.1
How do you expand an IPv6 address?
Count the groups that are written, let :: stand for as many zero groups as it takes to reach eight, and pad every group to four digits: 2001:db8::1 has three groups, so :: is five.
The expanded form is what reverse DNS uses, nibble by nibble, and what many logs and spreadsheets need for sorting as text. Python calls it .exploded and Go StringExpanded.
2001db8::13 written2001db8000001+ 5 zero groups that :: stands for20010db8000000000000000000000001padded to 4 digitsHow many ways can one IPv6 address be written?
Many: leading zeros, letter case and the place of :: can all change, so one address has many valid spellings, and RFC 5952 lists eight for 2001:db8:0:0:1:0:0:1 before fixing one canonical form.
That is why comparing addresses as text fails: two spellings of the same address don't match. Compare them as 128-bit numbers instead, or compress both first.
2001:db8:0:0:1:0:0:12001:0db8:0:0:1:0:0:12001:db8::1:0:0:12001:db8::0:1:0:0:12001:0db8::1:0:0:12001:db8:0:0:1::12001:db8:0000:0:1::12001:DB8:0:0:1::12001:db8::1:0:0:1canonical · RFC 5952How do you write an IPv6 address in a URL, with a port or a zone?
Put the address in square brackets, http://[2001:db8::1]:8443/, so the port can't be mistaken for a group; a zone such as %eth0 can't go in a browser URL at all.
RFC 5952 says to bracket an address that has a port, and calls 2001:db8::1:8443 not recommended. Brackets are used for nothing else in a URL. Browsers print the address in hex even after ::ffff:, so [::ffff:192.0.2.1] shows as [::ffff:c000:201].
Zones name an interface on one machine, as in fe80::1%eth0. RFC 9844 took them back out of URLs in 2025 and browsers refuse them, though programs should still let you type one.
A zone (%eth0) · fe80::1%eth0
| Typed in a program's field | allowed |
| In a browser URL | refused |
| inet_pton() | can't parse it |
| Global addresses | never have one |
How do I compress or expand IPv6 in code?
Parse the address and print it: Python's .compressed, Go's netip.Addr.String() and MySQL's INET6_NTOA(INET6_ATON(…)) give the canonical text, and .exploded and StringExpanded() the full form.
Python's str() is the compressed form too, and Python accepts a %zone suffix. MySQL prints lowercase, at most 39 characters, the same on every platform.
› import ipaddress a = ipaddress.ip_address('2001:0DB8::0001') a.compressed, a.exploded ('2001:db8::1', '2001:0db8:0000:0000:0000:0000:0000:0001')
Python ipaddress
› a := netip.MustParseAddr("2001:0DB8::0001") fmt.Println(a.String(), a.StringExpanded()) 2001:db8::1 2001:0db8:0000:0000:0000:0000:0000:0001
Go net/netip
› SELECT INET6_NTOA(INET6_ATON('2001:0DB8::0001')); 2001:db8::1
MySQL 8.4
Frequently asked questions
What is the compressed form of 2001:0db8:0000:0000:0000:ff00:0042:8329?
Can :: be used twice in an IPv6 address?
Why doesn't 2001:db8:0:1:1:1:1:1 compress to 2001:db8::1:1:1:1:1?
Should IPv6 addresses be uppercase or lowercase?
How do I expand :: in an IPv6 address?
How many characters is the longest IPv6 address?
Why does ::ffff:c000:280 become ::ffff:192.0.2.128?
How do I put an IPv6 address with a port in a URL?
How do I compress an IPv6 address in Python?
Can I compress a list of IPv6 addresses at once?
Missing something?Suggest a feature or a new tool
Related tools
IPv6 to IPv4
Find the IPv4 address inside an IPv6 one: mapped, NAT64, 6to4, Teredo and ISATAP, bit by bit
IPv4 to IPv6
Every IPv6 form of an IPv4 address: mapped, NAT64 and 6to4, each marked in use or rare
IP to Decimal Converter
IP address to decimal, hex, binary and octal and back, with each octet's place values
What Is My IP
Your public IPv4 and IPv6 at once, with the network, location and a VPN check
IPv6 Test
Test if your IPv6 works, which family your browser picks and if a site has IPv6
Subnet Calculator
Network, broadcast, usable hosts and masks for any IPv4 or IPv6 block, plus VLSM, splits and cloud subnets
Reverse DNS Lookup
Find hostnames associated with any IP address via PTR records
DNS Lookup
Every DNS record from the domain's own nameservers, beside Google's and Cloudflare's cache