IPv6 abbreviation rules: :: compression and expansion, explained

PublishedToolIP Address Converter (IPv4 ↔ IPv6)

Contents
  1. Why It's Confusing: Compressed and Expanded Forms Both Show Up
  2. How to Work It Out by Hand, Without a Tool: The Four IPv6 Omission Rules
  3. Common Misconceptions and Mistakes
  4. Summary
  5. Frequently Asked Questions

This post is for anyone who's wondered why the IPv6 address 2001:db8:0:0:0:0:0:1 shrinks down to 2001:db8::1 — and how to read a compressed address back into its original eight blocks.

The rules aren't complicated. Drop the leading zeros in each block, collapse a run of consecutive zero blocks into :: exactly once, and if there's more than one run of zero blocks, only the longest one gets compressed. This post goes through the four IPv6 omission rules in order.

Summary ① Leading zeros in each block are simply dropped (0db8 → db8) ② A run of consecutive zero blocks is compressed into ::, but :: can appear only once per address ③ If there's more than one run of zero blocks, only the longest run is compressed

Why It's Confusing: Compressed and Expanded Forms Both Show Up

When you work with IPv6 addresses, you often run into the same address showing up in different shapes. A server log shows fe80::1, while a firewall config file spells out fe80:0000:0000:0000:0000:0000:0000:0001.

It's hard to tell by eye whether two notations are the same address. And when zero blocks are scattered across several runs, it's a common mistake to compress the wrong run while trimming by hand and end up writing something that means a completely different address.

The problem comes from the fact that an IPv6 address is 128 bits, split into eight 16-bit blocks, so the notation itself is long. You need to know both the shortening rule and the expanding rule exactly to clear up the confusion.

How to Work It Out by Hand, Without a Tool: The Four IPv6 Omission Rules

The rules for writing IPv6 addresses are laid out in IETF standards documents. The basic framework comes from RFC 4291 (IP Version 6 Addressing Architecture).

Finer points — like which run to compress when there are several runs of zero blocks — are filled in by RFC 5952 (A Recommendation for IPv6 Address Text Representation).

An IPv6 address breaks 128 bits into eight 16-bit blocks, each written as four hex digits and separated by colons (:). The 2001:0db8:0000:0000:0000:0000:0000:0001 form — eight blocks, seven colons — is the full expanded form.

Rules 1–2: Dropping Leading Zeros and :: Compression

Rule 1 — Drop the leading zeros in each block. Just delete the zeros at the front of every block. 0db8 becomes db8, and 0000 keeps only a single 0. This rule always applies, whether or not :: is involved.

Rule 2 — Collapse a run of consecutive zero blocks into ::, but only once per address. If blocks are zero in an unbroken run, you can replace that whole run with ::.

But :: must appear exactly once in an address. If you use it twice, there's no way to tell how many zero blocks each :: stands for, so the math back to the original eight blocks becomes impossible.

Rules 3–4: When There's More Than One Run of Zero Blocks

Rule 3 — If there's more than one run of zero blocks, compress only the longest run. For example, 2001:db8:0:0:1:0:0:1 has zero blocks in two places (the 3rd–4th and the 6th–7th), and both runs are two blocks long.

RFC 5952 says that when lengths tie, you compress the left (front) run. The result is 2001:db8::1:0:0:1. If the runs are different lengths, only the longer one gets compressed, and the shorter one keeps its 0s.

Rule 4 — A run with just one zero block isn't compressed. With 2001:db8:1:0:1:1:1:1, there's only a single zero block, so it isn't collapsed into :: and stays as 0. RFC 5952 explicitly excludes this case from compression.

How to Expand a Compressed Address Back Out

Going the other way works the same way, with the rules applied in reverse. Take 2001:db8::1: the explicit blocks separated by colons are only 2001, db8, and 1 — three of them.

You need eight blocks, so five are missing. Insert five zero blocks where the :: is. Then pad each block to four digits, and you get 2001:0db8:0000:0000:0000:0000:0000:0001.

Addresses with an IPv4 Part Mixed In

The same logic applies when an IPv4 notation is mixed in at the end (something like ::ffff:192.168.1.1). First convert the trailing IPv4 part (192.168.1.1) into two 16-bit blocks (c0a8, 0101), then expand the leading :: into the remaining zero blocks.

It's faster to plug in a handful of addresses yourself and watch how the expanded and compressed forms change than to memorize the rules. Check it with our free IP Address Converter (IPv4 ↔ IPv6).

IP Address Converter (IPv4 ↔ IPv6)

Enter an IP address and the converter instantly calculates the IPv4 decimal, hex, and binary forms plus the expanded and compressed IPv6 notation. Free, no sign-up.

Common Misconceptions and Mistakes

Here are the spots people most often get wrong with the compression rules.

SituationWrong exampleRule
Using :: twice2001:db8::1::2:: is allowed only once per address. If you use it twice, you can't tell how many zero blocks each :: replaces
Two runs of zero blocks, equal length, but compressing the later one2001:db8:0:0:1::1When lengths tie, compress the left (front) run. The correct notation is 2001:db8::1:0:0:1
Compressing a run with only one zero block2001:db8:1::1:1:1:1Runs of length 1 aren't eligible. Leave the 0 in place
Leaving the leading zeros in a blockKeeping 2001:0db8:... as isNot technically wrong, but it isn't the compressed form. Dropping leading zeros always applies

The most common mistake in this table is the second row. When there are two or more runs of zero blocks, people often compress whichever run catches their eye first or is easier to count. The rule is the longest run, not the first one you see.

Summary

IPv6 omission (compression) notation comes down to four rules.

  1. Drop the leading zeros in each block. This always applies, regardless of ::.
  2. Collapse a run of consecutive zero blocks into ::, but only once per address. Use it twice and you can't restore the original address.
  3. If there's more than one run of zero blocks, only the longest run is compressed. When lengths tie, compress the left (front) run.
  4. A run with only one zero block isn't compressed. Leave the 0 as it is.

Follow these four rules and you can expand or shrink any IPv6 address by hand. That said, with eight blocks to keep track of, it's easy to miscount. Put several example addresses into the tool and compare the expanded and compressed forms side by side, and the rules will stick much faster.

IP Address Converter (IPv4 ↔ IPv6)

Enter an IP address and the converter instantly calculates the IPv4 decimal, hex, and binary forms plus the expanded and compressed IPv6 notation. Free, no sign-up.

Frequently Asked Questions

Can I use :: twice?

No. You can use :: only once per address. If you use it twice, there's no way to tell how many zero blocks each :: stands for, and expanding back to 8 blocks splits into multiple possible answers. Since you can't pin down which one is the correct address, it's treated as invalid notation.

Can I shorten a single zero block with ::?

It's not recommended. RFC 5952 says to leave zero runs of length 1 out of compression. Compressing them barely shortens the text, while it only adds confusion about which notation counts as the standard form. For these runs, write the 0 as is.

Are the compressed and expanded forms really the same address?

Yes, they are the same address. Wrapping with :: and dropping leading zeros are both rules that shorten notation without changing the value. When you're not sure whether two notations are the same address, expand the compressed one to 8 blocks and compare them block by block — that settles it.

Why does the IPv4-Mapped address (::ffff:a.b.c.d) exist?

It's a notation for accepting both IPv4 and IPv6 clients on a single IPv6-only socket. You put the IPv4 address directly into the last 32 bits and add the ffff block in front, so connections that come in over IPv4 are also expressed in IPv6 address format.

The similar-looking IPv4-Compatible address (::a.b.c.d, without ffff) was created for an older automatic tunneling method, and RFC 4291 classifies it as a deprecated format that is no longer used.

This article was adapted from our Korean original. Read the Korean original

Related articles

  1. JS Minifier Compression Rate: How It's CalculatedSee how a JS minifier calculates compression rate from input and output bytes, why results differ by tool, and how to verify the number yourself.
  2. JSON Array to Table: How Columns, Sorting, and Search WorkSee how a JSON array of objects becomes a table: where column headers come from, how sorting and search compare values, and why non-array JSON errors out.
  3. JSON Array to HTML List: How Items Become li TextSee how JSON array strings and objects turn into li text, how ul/ol and class names map to markup, and why parse errors and key typos happen.
  4. JSON Auto-Fix and Parse Errors: How to Read and Fix ThemStandard JSON has no comments, trailing commas, or unquoted keys. Learn how JSON.parse errors point to a line and position, and what Auto-Fix does.
  5. JSON Escape Explained: Turn Multi-line JSON Into One LineSee why pasting JSON into CLI args or .env values breaks, which escape sequences replace quotes, backslashes, and newlines, and how JSON vs Raw mode differ.
  6. How to Flatten Nested JSON: Key-Merging Rules ExplainedSee how nested JSON keys merge into parent + delimiter + child, why arrays stay intact, and how a bad delimiter choice splits keys by mistake.

Related tools