Why You Can Only Compress 1 Run of Zero Groups In IPV6

Matthew Lui
2 min readApr 25, 2020

Take this example of an IPV6 address:

2001:0370:85a3:0000:0000:8a2e:0000:0000

We break it into eight 16-bit groups, each separated with a colon and written in hexadecimal.

To make addresses easier for us to read and write, we optionally represent addresses after it has gone through two compression steps.

Compression step 1: Remove leading zeroes in each group, preserving at least one digit.

2001:370:85a3:0:0:8a2e:370:0:0

Note here that the 0000 in groups 4 , 5, 7 and 8 have been grouped together into 0. We keep one 0 so we know that there’s still a group there.

The 0370 of group 2 had its first zero omitted and is now just 370.

Compression step 2: Remove at most one consecutive run of groups with only zeroes, keeping only the start and end colons.

2001:370:85a3::8a2e:0:0

Here, we’ve cut out groups 4 and 5 entirely, keeping only two colons. We can only compress one group, so groups 7 and 8 are preserved.

Why can we only compress one group?

Now attempt to convert the address back to it’s original state. We can see that there are only 6 groups visible in the address, but we know that there needs to be 8.

We can therefore tell that 8–6 = 2 groups of zeroes must have been replaced by the colons and add them back.

Had we substituted both groups of zeroes, we would be left with IPV6 address:

2001:370:85a3::8a2e:

We can tell that there are 8–4 = 4 groups missing, but we don’t know from which of the two places they have been cut out.

For all that the reader knows, the address could be any of:

2001:370:0000:0000:0000:85a3::8a2e:00002001:370:0000:0000:85a3::8a2e:0000:00002001:370:0000:85a3::8a2e:0000:0000:0000

It’s impossible to tell!

So we can only ever remove one run of groups with only zeroes.

--

--