IPv6 Address Compression Calculator

RFC 5952 defines one canonical way to write each IPv6 address: lowercase, no leading zeros, and “::” replacing the longest run of two or more zero groups (the first, if two runs tie). Paste any valid form to get it.

Also called: IPv6 shortener · IPv6 expander

  • Last updated
  • Formula tested against reference values

Your numbers

Any valid form, optionally with a /prefix. Embedded IPv4 such as ::ffff:192.0.2.1 is accepted.

Result

Canonical (RFC 5952) form
—

Calculating…

Fully expanded form
—
Address type
—
Zero groups
—
Characters saved
—

How to use this calculator

  1. Enter or choose iPv6 address.
  2. The canonical (RFC 5952) form updates as you type. Use Copy result or Share to keep it.

Method

Parse to eight 16-bit groups (RFC 4291 §2.2), then: drop leading zeros; replace the longest run of ≥ 2 all-zero groups with “::” (first run on a tie, never a single group); write a–f in lowercase (RFC 5952 §4). IPv4-mapped addresses are written ::ffff:a.b.c.d (RFC 5952 §5).

Group
16 bits written as 1–4 hex digits

Worked example

  1. Drop leading zeros: 2001:db8:0:0:1:0:0:1.
  2. There are two runs of two zero groups; they tie, so the first is replaced.
  3. Result: 2001:db8::1:0:0:1.

2001:0db8:0000:0000:0001:0000:0000:0001 is written 2001:db8::1:0:0:1 in canonical form.

What the result means

Use the canonical form in logs, configs and documentation so the same address is always written the same way and text searches find it.

Assumptions and limits

  • Zone indexes (such as %eth0) are not part of the address and must be removed.
  • Address type is based on the well-known prefixes only; it does not check whether a prefix is actually allocated or routed.

Questions

Why not compress a single zero group?

RFC 5952 forbids using “::” for a single 16-bit zero field, so 2001:db8:0:1:1:1:1:1 stays as it is.

Are uppercase letters wrong?

They are valid input, but RFC 5952 recommends lowercase for output, so tools and people produce identical text.

Sources