IPv6 addressing basics
There are quite a few differences between IPv4 and IPv6; I recommend researching those differences by studying the structure of an IPv6 packet. Probably the most obvious difference is the address. At first glance, IPv6 addresses are bewildering to look at. Aside from being longer than IPv4 addresses, they're represented (in text form) with hexadecimal characters instead of decimal. These scary-looking addresses are part of one of the improvements over IPv4: address space. An IPv4 address is four groups of 8 bits each (an octet), for a total of 32 bits.
Therefore, the total number of available IPv4 addresses is 232 = 4.294967296 billion, to be exact. Back in the 1970s, this big-sounding number seemed like plenty, but IPv4 address exhaustion became a legitimate threat and then, starting in the past decade, a reality. Consider, on the other hand, the IPv6 address: eight groups of four hexadecimal characters each (a single hex character takes up 4 bits); therefore, eight groups of 16 bits each (a hextet) for a total of 128 bits. The total address space is thus 2128 = 340,282 decillion addresses. That's enough for every grain of sand on Earth to have 45,000 quadrillion IP addresses each. In layman's terms, quite the handful. When working with IPv6 addresses, you may see something as long as 2052:dfb8:85a3:7291:8c5e:0370:aa34:3920, down through something like 2001:db8:85ad::2:3, and even all the way down to the IPv6 zero address (unspecified address), which is literally just two colons – ::. So, the easiest way to understand them is to start with the core, uncompressed address, and then check out the IETF convention for simplifying them.
As we just learned, the raw IPv6 address is eight groups of four (lowercase) hexadecimal characters, and the groups are separated by colons. Here's an example:
2001:007f:28aa:0d3a:0000:0000:2e87:0bcb
There are two main compression rules. The first is the omission of initial zeroes (not entire groups of zero; that's next) within a hextet. 00aa becomes aa, 05f4 becomes 5f4, 000e becomes e. In our example, there are three groups with initial zeroes, so thus our address becomes:
2001:7f:28aa:d3a:0000:0000:2e87:bcb
The second rule is the conversion of all-zero groups into double colons (::). This rule applies to adjacent groups of all zero; if there are two or more adjacent groups of all zeroes, they are all replaced with a single double colon. Single groups of all zero are not suppressed and instead are represented with a single 0. If there happen to be more than one multiple-group runs of zero, then the leftmost run of zeroes is suppressed and the others are turned into single-zero groups.
In our example, there is a single multiple-group run of zero (two groups), so those eight adjacent zero become a double colon:
2001:7f:28aa:d3a::2e87:bcb
Looks quite a bit more manageable than the uncompressed address, right? By following those compression rules, the end result is the exact same address as the first.
Before we move on, let's take a look at a few more examples: