Table of Contents
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:
- Numbers: 0 to 9
- Letters: a to f (or A to F)
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:
| Hex | Decimal |
|---|---|
| 0 | 0 |
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
| 4 | 4 |
| 5 | 5 |
| 6 | 6 |
| 7 | 7 |
| 8 | 8 |
| 9 | 9 |
| a | 10 |
| b | 11 |
| c | 12 |
| d | 13 |
| e | 14 |
| f | 15 |
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:
- There are exactly 7 colons
- Every group has 4 hex characters
- Leading zeros are kept, even if they look unnecessary
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:
- Removing leading zeros in each 16 bit group
- 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:
- Be written in a long full form
- Be written in one or more shortened forms using these rules
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:
0db8becomesdb80042becomes420000becomes00100becomes100
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:
0f0abecomesf0a(the first zero is removed, the middle one stays)1200stays1200(the zero at the end is not a leading zero)
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:
...:0000:0000:0000:...can be written as...::...
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:
2001::db8::1is not allowed
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 :::
2001:db8::1::1fe80::abcd:1234
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:
- At the beginning of the address
- In the middle of the address
- At the end of the address
Depending on where the groups of zero are.
Examples:
| Full form | Shortened form | Comment |
|---|---|---|
0000:0000:0000:0000:0000:0000:0000:0001 | ::1 | :: at start |
fe80:0000:0000:0000:abcd:0000:0000:0001 | fe80::abcd:0:0:1 | :: in middle |
2001:0db8:abcd:1234:0000:0000:0000:0000 | 2001: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:
- Count how many groups are visible.
- You know the total must be 8 groups.
- The missing groups (if any) are
0000, and they are in the place of::. - Add leading zeros inside each group until each group has 4 hex digits.
Example 1: 2001:db8::ff00:42:8329
Step by step:
- Visible groups:
2001,db8,ff00,42,8329
That is 5 groups. - Total must be 8, so missing groups: $8 - 5 = 3$.
- Replace
::with0000:0000:0000. - Now you have:
2001db8000000000000ff00428329- Add leading zeros:
2001stays2001db8becomes0db80000stays00000000stays00000000stays0000ff00staysff0042becomes00428329stays8329
Final full form:
$$
2001:0db8:0000:0000:0000:ff00:0042:8329
$$
Example 2: ::1
- Visible groups:
1 - Total must be 8, so missing groups: $8 - 1 = 7$.
::means0000:0000:0000:0000:0000:0000:0000.- 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:
- Use lowercase letters
atof. - Remove all possible leading zeros inside groups (Rule 1).
- Use
::(Rule 2) only for the longest run of0000groups. - If there are multiple runs of equal length, compress the leftmost run.
For example, the full address:
$$
2001:0db8:0000:0000:0001:0000:0000:0001
$$
Has two runs of 0000:0000:
0000:0000after0db80000:0000before the final0001
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.
- 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 ::.
- 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.
- 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:
- Address in IPv6 format
/- Prefix length in decimal, from 0 to 128
Examples:
2001:db8::/322001:db8:1234::/48fe80::/64
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.