How to Shorten IPv6 Addresses: Compression Rules and Examples
IPv6 addresses are long, but two simple rules make them easier to read and type. Learn how to remove leading zeros, compress one zero run, and expand a shortened address safely.
How to Shorten IPv6 Addresses: Compression Rules: Quick Summary
Rule 1: Remove leading zeros
000A becomes A, and 0000 becomes 0.
Rule 2: Compress one zero run
Replace one consecutive run of zero hextets with ::. Never use :: twice.
How to Shorten IPv6 Addresses: Compression Rules: Table of Contents
1. IPv6 Address Structure
An IPv6 address contains 128 bits arranged as eight 16-bit hextets. Each hextet contains four hexadecimal digits and is separated by a colon.
Shortening changes only how the value is written. The underlying 128-bit address stays exactly the same.
2. Removing Leading Zeros
Within each hextet, remove zeros from the left side until the first non-zero digit appears. Never remove a trailing zero because that changes the value.
| Original hextet | Valid short form |
|---|---|
0000 | 0 |
000A | A |
00F0 | F0 |
0A00 | A00 |
3. Using Double-Colon Compression
One consecutive run of all-zero hextets can be replaced with ::. The double colon tells a device to restore enough zero hextets to reach eight total hextets.
:: only once. If two zero runs were compressed, the receiver could not determine how many hextets belong in each location.For a consistent canonical representation, compress the longest zero run. If two runs are the same length, compress the leftmost one. A single zero hextet may be written as 0; using :: for only one zero is generally avoided when a longer run exists.
4. Complete Worked Example
The second hextet remains 0. The three later zero hextets become ::.
5. How to Expand a Short IPv6 Address
Count the visible hextets, subtract that number from eight, and replace :: with the required number of 0000 hextets. Then pad every hextet to four digits.
6. Common Mistakes
- Using two double colons:
2001::10::25is invalid. - Removing trailing zeros:
1200cannot become12. - Compressing non-zero hextets: only complete
0000hextets participate in a zero run. - Forgetting eight hextets when expanding: the full address must contain exactly eight 16-bit fields.
- Confusing prefix length with compression:
/64identifies network bits; it does not state how many hextets::replaces.
7. Practice Examples
| Expanded | Shortened |
|---|---|
2001:0DB8:0000:0000:0000:0000:0000:0001 | 2001:DB8::1 |
FE80:0000:0000:0000:0212:34FF:FE56:7890 | FE80::212:34FF:FE56:7890 |
FD12:3456:789A:0001:0000:0000:0000:0042 | FD12:3456:789A:1::42 |
0000:0000:0000:0000:0000:0000:0000:0001 | ::1 |
How to Shorten IPv6 Addresses: Compression Rules: Frequently Asked Questions
How many times can double colon appear in an IPv6 address?
The :: symbol can appear only once because the missing hextets must be unambiguous when the address is expanded.
Can leading zeros be removed from every hextet?
Yes. Leading zeros may be removed from each hextet, but at least one hexadecimal digit must remain unless a zero run is represented by ::.
Which zero run should be compressed?
Compress the longest consecutive run of all-zero hextets. If equal-length runs exist, using the leftmost run produces the recommended canonical form.
Does shortening change the IPv6 address?
No. Short and expanded forms represent the same 128-bit value.
Standard Reference
The text representation rules are defined in RFC 4291, Section 2.2. Canonical formatting recommendations are described in RFC 5952.