Kahibaro
Discord Login Register

8.2 IPv6 Address Format

Overview

IPv6 addresses look very different from IPv4 addresses. Instead of four decimal numbers separated by dots, IPv6 uses hexadecimal numbers separated by colons. This format allows IPv6 to represent a much larger address space while still being readable and writable by humans.

This chapter focuses only on how an IPv6 address is written, read, and shortened. It does not cover how addresses are used or what the different types of IPv6 addresses mean, because those topics belong to other chapters.

Basic Structure of an IPv6 Address

An IPv6 address is 128 bits long. It is written as 8 groups, each group representing 16 bits. Each 16 bit group is written as 4 hexadecimal digits. The groups are separated by colons.

A full IPv6 address looks like this:

$$
2001:0db8:0000:0000:0000:ff00:0042:8329
$$

Each group such as 2001 or 0db8 represents 16 bits, which equals 4 hex digits. In total:

$$8 \text{ groups} \times 16 \text{ bits per group} = 128 \text{ bits}$$

Hexadecimal digits can be:

The letters represent values 10 to 15.

For example, the group 0db8 is a 16 bit chunk. Written in binary, it would be 16 bits long, but IPv6 hides that complexity by using hexadecimal.

IPv6 addresses are always 128 bits long, written as 8 groups of 4 hexadecimal digits, separated by colons.

Hexadecimal Digits and Groups

To understand the format, you only need to know the mapping between hex and decimal values for one digit:

HexDecimal
00
11
22
33
44
55
66
77
88
99
a10
b11
c12
d13
e14
f15

A single hex digit represents 4 bits. So a group of 4 hex digits is 16 bits.

You do not need to convert values manually in daily work, but it helps to recognize that each group is a fixed size, and there must always be exactly 8 groups in the address, even if some are written in a shortened form.

Full (Uncompressed) IPv6 Notation

The most complete way to write an IPv6 address is called the full or uncompressed form. All 8 groups are present and each group has exactly 4 hex digits, including leading zeros.

Example of a full IPv6 address:

$$
2001:0db8:0000:0000:0000:ff00:0042:8329
$$

In this form:

Sometimes you will need to expand an address to this full form, for example when doing calculations or comparisons.

In full notation, an IPv6 address has 8 groups, each group must have 4 hexadecimal digits, and there are 7 colons in total.

Shortening IPv6 Addresses: General Idea

Writing all the zeros in full IPv6 addresses would be inconvenient. For this reason, IPv6 defines two main rules to shorten addresses while keeping them unambiguous:

  1. Removing leading zeros in each 16 bit group
  2. Compressing consecutive all zero groups with ::

These rules only change how the address looks. The underlying 128 bit value does not change.

Any valid IPv6 address can:

You must be able to recognize that all such forms represent the same address.

Rule 1: Omitting Leading Zeros

Within each 16 bit group, you may remove leading zeros. You must leave at least one digit in the group.

For example:

So this address:

$$
2001:0db8:0000:0000:0000:ff00:0042:8329
$$

After applying Rule 1 to each group becomes:

$$
2001:db8:0:0:0:ff00:42:8329
$$

Only zeros at the beginning of a group may be removed. Zeros inside or at the end of the group must stay. For example:

Rule 1: Inside a group, you may remove leading zeros, but each group must keep at least one hex digit.

Rule 2: Using `::` to Compress Zero Groups

If you have one or more consecutive groups that are all 0000, you may replace that entire sequence with a double colon ::.

For example:

From the earlier example in full form:

$$
2001:0db8:0000:0000:0000:ff00:0042:8329
$$

First, the three 0000 groups are already identified. Then you can compress them with :::

$$
2001:0db8::ff00:0042:8329
$$

If you also apply Rule 1 for leading zeros in the remaining groups, you can write:

$$
2001:db8::ff00:42:8329
$$

This is a much shorter and standard way to represent the same address.

Rule 2: One sequence of one or more all zero groups may be replaced by :: in an IPv6 address.

Important Restriction: `::` Only Once

You are allowed to use :: at most one time in a single IPv6 address. This is because :: hides an unknown number of 0000 groups, and using it more than once would make the address ambiguous.

For example, the following is invalid:

There is no way to know how many zero groups are hidden in each :: and therefore you could not reliably expand it back to 8 groups.

Valid examples with a single :::

An IPv6 address may contain at most one ::. More than one :: in a single address is never valid.

Location of `::` in the Address

:: can appear:

Depending on where the groups of zero are.

Examples:

Full formShortened formComment
0000:0000:0000:0000:0000:0000:0000:0001::1:: at start
fe80:0000:0000:0000:abcd:0000:0000:0001fe80::abcd:0:0:1:: in middle
2001:0db8:abcd:1234:0000:0000:0000:00002001:db8:abcd:1234:::: at end

In each case, the rule is the same. :: stands for as many 0000 groups as needed so the total count becomes 8 groups when expanded.

Reconstructing the Full Address from a Short Form

A common task is to take a shortened IPv6 address and expand it back to the full 8 group form with all leading zeros.

The steps are:

  1. Count how many groups are visible.
  2. You know the total must be 8 groups.
  3. The missing groups (if any) are 0000, and they are in the place of ::.
  4. Add leading zeros inside each group until each group has 4 hex digits.

Example 1: 2001:db8::ff00:42:8329

Step by step:

  1. Visible groups: 2001, db8, ff00, 42, 8329
    That is 5 groups.
  2. Total must be 8, so missing groups: $8 - 5 = 3$.
  3. Replace :: with 0000:0000:0000.
  4. Now you have:
    • 2001
    • db8
    • 0000
    • 0000
    • 0000
    • ff00
    • 42
    • 8329
  5. Add leading zeros:
    • 2001 stays 2001
    • db8 becomes 0db8
    • 0000 stays 0000
    • 0000 stays 0000
    • 0000 stays 0000
    • ff00 stays ff00
    • 42 becomes 0042
    • 8329 stays 8329

Final full form:

$$
2001:0db8:0000:0000:0000:ff00:0042:8329
$$

Example 2: ::1

  1. Visible groups: 1
  2. Total must be 8, so missing groups: $8 - 1 = 7$.
  3. :: means 0000:0000:0000:0000:0000:0000:0000.
  4. Full address:

$$
0000:0000:0000:0000:0000:0000:0000:0001
$$

To expand an IPv6 address: ensure you end with exactly 8 groups, each with 4 hex digits. All missing groups are 0000 inserted where :: appears.

Canonical vs Preferred Short Form

In practice, IPv6 addresses may be written with small variations. However, many systems follow a consistent preferred form to avoid confusion.

Common preferences include:

For example, the full address:

$$
2001:0db8:0000:0000:0001:0000:0000:0001
$$

Has two runs of 0000:0000:

Both have the same length, but many tools compress the first occurrence, so the standard shortened form is:

$$
2001:db8::1:0:0:1
$$

Exact formatting rules may differ between tools or standards, but the important point is that all such representations describe the same binary address.

Special Examples of IPv6 Formats

Some specific IPv6 addresses have very typical shortened forms. These are useful as examples of the format rules in action.

  1. Unspecified address (all bits zero) in full form:

$$
0000:0000:0000:0000:0000:0000:0000:0000
$$

Short form:

$$
::
$$

Every group is zero, so the entire address is compressed into a single ::.

  1. Loopback address (like IPv4 127.0.0.1) in full form:

$$
0000:0000:0000:0000:0000:0000:0000:0001
$$

Short form:

$$
::1
$$

Here, 7 zero groups are compressed and only the last group remains visible.

  1. Link local address, typical router output:
    • Full: fe80:0000:0000:0000:02aa:00ff:fe9a:4ca2
    • Short: fe80::2aa:ff:fe9a:4ca2

The three all zero groups after fe80 become ::, and leading zeros in other groups are removed.

Each of these examples follows exactly the same formatting rules you have learned. Their meaning and use will be covered in later chapters that deal with IPv6 address types.

IPv6 Prefix Notation

You will often see an IPv6 address followed by a slash and a number, such as:

$$
2001:db8::/32
$$

The part before the slash is an IPv6 address written in the standard format. The number after the slash indicates how many of the leftmost bits form the network prefix. The detailed meaning of prefixes belongs to addressing and routing topics, but the formatting rule is simple:

Examples:

From a format perspective, you treat the address part on the left using all the same shortening rules you already know.

In IPv6 prefix notation, an IPv6 address is followed by / and a decimal prefix length from 0 to 128, for example 2001:db8::/32.

Summary

IPv6 addresses use a consistent and flexible text format to represent 128 bit values. Each address has 8 groups of 4 hexadecimal digits in full form. You can shorten addresses by removing leading zeros within each group and by compressing exactly one sequence of all zero groups into ::. You must always be able to expand any shortened address back to exactly 8 groups with 4 hex digits each. These simple rules make IPv6 addresses readable while still accurately representing very large binary values.

Views: 41

Comments

Please login to add a comment.

Don't have an account? Register now!