How to Shorten an IPv6 Address: RFC 5952, Prefix Maths and ip6.arpa
Last updated: · 8 min read
An IPv6 address is 128 bits long and is written as eight groups of four hexadecimal digits separated by colons. Because leading zeros can be dropped and runs of zero groups replaced by ::, the same address can be written in many different ways, which makes it awkward to search logs, compare two addresses or review configuration files. RFC 5952 therefore defines one recommended spelling. This guide walks through the compression rules, shows how a prefix length yields the network address and the number of addresses, explains how address types are recognised and how the reverse DNS name is put together. The values in the example are real output from the IPv6 Tools; everything is calculated in your browser and no address is contacted.
Formula
Compression (RFC 5952, Section 4): 1. Leading zeros in each group are dropped: 0db8 → db8, 0000 → 0 2. The longest run of zero groups becomes "::": at least 2 groups; the leftmost if tied 3. A single zero group is never shortened to "::" 4. The letters a–f are written in lower case Prefix /p: network address = address AND (mask with the first p bits set) last address = network address OR (last 128 − p bits set) address count = 2^(128 − p) /64 → 18,446,744,073,709,551,616 (2^64) Reverse DNS (RFC 3596): the 32 hex digits in reverse order, dot-separated, + ".ip6.arpa" IPv4-mapped: ::ffff:a.b.c.d 6to4 prefix: 2002:AABB:CCDD::/48 (a.b.c.d in hex)
The tool first expands the address into eight 16-bit groups. It reads all three notations from RFC 4291: the full form, the form compressed with ::, and the mixed form whose last 32 bits are written as a dotted-decimal IPv4 address. To compress, it applies the rules of RFC 5952: drop leading zeros, turn the longest run of zeros into ::, pick the leftmost run when two are equally long, and lower-case the letters. For prefix calculations the 128-bit address is treated as one integer; the first p bits are kept, and the rest are cleared to get the network address or set to get the last address of the block. The number of addresses can run to 39 digits, so it is computed with exact integer arithmetic rather than floating point and printed without rounding. The address type is determined by comparing the address with the blocks in RFC 4291 and in the IANA special-purpose address registry.
What the inputs mean
- IPv6 address, address with prefix, or IPv4
- Three kinds of input are accepted. A plain IPv6 address (2001:db8::1) is compressed, expanded and classified. Add a prefix from /0 to /128 (2001:db8::/32) and the block details are calculated too. Enter a dotted IPv4 address (192.0.2.1) to see its IPv6 equivalents; a prefix is not accepted with IPv4. Square brackets ([2001:db8::1]) and zone identifiers such as fe80::1%eth0 are stripped.
Worked example: Analysing 2001:db8::ff00:42:8329/64
- Input: 2001:db8::ff00:42:8329/64. The address part shows five groups; the :: stands for the three missing groups, all zero. In the fully expanded form each group is padded to four digits: Fully expanded form: 2001:0db8:0000:0000:0000:ff00:0042:8329
- Compressing turns 0db8 into db8 and 0042 into 42, and the three consecutive zero groups are written as ::. The tool gives: Compressed form (RFC 5952): 2001:db8::ff00:42:8329
- Type the same address in upper case and with nothing shortened, 2001:0DB8:0000:0000:0000:FF00:0042:8329, and the compressed form is again 2001:db8::ff00:42:8329. That is the point of a canonical form: every spelling of an address collapses to one string.
- Type and reverse DNS: Address type (RFC 4291 / IANA): documentation (2001:db8::/32) and Reverse DNS name (ip6.arpa): 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. In the reverse DNS name the 32 hex digits run from last to first; this is the name under which the address's PTR record lives.
- With a /64 prefix the first 64 bits identify the network and the last 64 the interface. The tool reports the block as: Network address (with prefix): 2001:db8::/64, First address in the block: 2001:db8::, Last address in the block: 2001:db8::ffff:ffff:ffff:ffff and Number of addresses in the block: 18,446,744,073,709,551,616 (2^64)
- Two zero runs of equal length: 2001:db8:0:0:1:0:0:1 contains two separate runs of two zero groups. RFC 5952 says the leftmost one is shortened, and the tool gives 2001:db8::1:0:0:1. Writing 2001:db8:0:0:1::1 instead denotes the same address but is not canonical.
- A prefix that does not fall on the network boundary: in 2001:db8:abcd:12::/56 the last 8 bits of the group 0012 belong to the host part. The tool clears them: Network address (with prefix): 2001:db8:abcd::/56; the block holds 4,722,366,482,869,645,213,696 (2^72) addresses.
- IPv4 input: for 192.0.2.1 the tool prints four lines: IPv4 address: 192.0.2.1, IPv4-mapped IPv6 (mixed notation): ::ffff:192.0.2.1, IPv4-mapped IPv6 (hex notation): ::ffff:c000:201 and 6to4 prefix (RFC 3056): 2002:c000:201::/48
- Invalid input: an address may contain :: only once. For 2001:db8::1::2 the tool answers: Invalid IP address: 2001:db8::1::2. Examples: 2001:db8::1, 2001:db8::/32 or 192.0.2.1.
Result: 2001:db8::ff00:42:8329/64 → Network address (with prefix): 2001:db8::/64; Number of addresses in the block: 18,446,744,073,709,551,616 (2^64)
🌍 IPv6 Tools: Compress, Expand, Prefix
Free, no sign-up; your data stays in your browser.
Open the calculator →How to read the result
A canonical spelling earns its keep wherever addresses are compared: access lists, log files, database columns and certificates. Normalising addresses before you store them stops one address from showing up as two different records. On the prefix side, habits from IPv4 are misleading. A /64 holds 2^64 addresses and nobody is meant to fill it; under RFC 4291 the interface identifier of a unicast address is 64 bits long, which is why a LAN normally gets a whole /64. IPv6 has no broadcast address either, so the first and last address of a block simply mark the ends of the range. The address type line is a quick way to tell where an address comes from: one starting with fe80:: is valid only on its own link, addresses in fc00::/7 are not routed on the internet, and 2001:db8::/32 is reserved for documentation. The tool does not check whether an address is reachable, who it belongs to or whether it has a DNS record. 6to4 is a legacy transition mechanism; the tool shows it so that you can make sense of the 2002:: addresses still found in older configurations.
Common mistakes
- Using :: twice in one address. It would be impossible to tell how many zero groups each one stands for, so such a spelling is invalid and the tool rejects it.
- Shortening a single zero group to ::. The address 2001:db8:0:1:1:1:1:1 stays as it is; RFC 5952 allows :: only for two or more consecutive zero groups.
- Dropping trailing zeros. Only leading zeros in a group may be removed: the group ff00 cannot be written as ff, because ff means 00ff, which is a different address.
- Comparing addresses as text. 2001:DB8::1 and 2001:0db8:0:0:0:0:0:1 are the same address with different spellings; convert both to canonical form before comparing.
- Writing a port without brackets. In 2001:db8::1:8080 the 8080 is read as the last group of the address; to add a port, put the address in square brackets: [2001:db8::1]:8080.
- Carving a /64 into small subnets the way you would in IPv4. Stateless address autoconfiguration expects a 64-bit interface identifier; if you need more networks, ask your provider for a shorter prefix such as a /56 or /48.
- Taking the zone identifier for part of the address. In fe80::1%eth0 the %eth0 only tells that machine which interface to use; the address itself is fe80::1, and the tool drops the zone identifier.
Frequently asked questions
How do I shorten an IPv6 address?
In three steps: drop the leading zeros in every group, replace the longest run of consecutive zero groups with :: once, and write the letters in lower case. For example, 2001:0db8:0000:0000:0000:ff00:0042:8329 becomes 2001:db8::ff00:42:8329. If two runs of zeros are equally long, the left one is shortened; a single zero group stays as 0.
How many addresses are in a /64?
2^64, which is 18,446,744,073,709,551,616 (2^64). That is about 4.3 billion times the number of addresses in the entire IPv4 internet (2^32). A /48 contains 65,536 /64 networks and a /56 contains 256.
How do I expand a compressed IPv6 address?
First replace the :: with as many 0000 groups as it takes to bring the total to eight, then pad every group with leading zeros to four digits. In 2001:db8::1 three groups are written, so the :: stands for five zero groups: 2001:0db8:0000:0000:0000:0000:0000:0001.
What is an address that starts with fe80?
A link-local address from the block fe80::/10. Every IPv6 interface has one automatically; it is valid only on its own network link and routers do not forward it. That is why it is often written with a zone identifier naming the interface when you connect to it.
How do I convert an IPv4 address to IPv6?
An IPv4 address has no single IPv6 equivalent; the notation depends on the purpose. An IPv4-mapped address (::ffff:192.0.2.1) is used by dual-stack software to represent IPv4 connections on an IPv6 socket and is not routed on the network as an IPv6 address. The 6to4 prefix (2002:c000:201::/48) is the network prefix derived from an IPv4 address in an older tunnelling method.
What is the ip6.arpa name for?
Reverse DNS lookups. To find the host name that goes with an IPv6 address, its 32 hex digits are looked up in reverse order, separated by dots, under the ip6.arpa domain. The tool generates that name so you can create or query the PTR record. It does not send any DNS query itself.
Is the address I enter sent anywhere?
No. Everything is calculated by JavaScript on the page, in your browser; the tool does not connect to the address, ping it or send DNS queries.
The result is not exact or binding and is for information only; it is not an official document and cannot be used in official procedures. Confirm it with the competent authority or a professional before acting; no liability is accepted for losses arising from its use.