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.

IPv6Address CompressionCCNAAddressing
IPv6 shortening example using leading-zero suppression and double-colon compression
How to Shorten IPv6 Addresses: Compression Rules and cheat sheet: use this quick map before reading the detailed sections.

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
  2. Removing Leading Zeros
  3. Using Double-Colon Compression
  4. Complete Worked Example
  5. How to Expand a Short Address
  6. Common Mistakes
  7. Practice Examples
  8. Frequently Asked Questions

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.

2041:0000:140F:0000:0000:0000:875B:131B ^1 ^2 ^3 ^4 ^5 ^6 ^7 ^8

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.

2001:0001:0002:0003:0004:0005:0006:0007 2001:1:2:3:4:5:6:7
Original hextetValid short form
00000
000AA
00F0F0
0A00A00

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.

Before: 2041:0:140F:0:0:0:875B:131B After: 2041:0:140F::875B:131B
Use :: 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

Original:
2041:0000:140F:0000:0000:0000:875B:131B
Remove leading zeros:
2041:0:140F:0:0:0:875B:131B
Compress the longest zero run:
2041:0:140F::875B:131B

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.

Short: 2001:DB8::25 Visible: 3 hextets Missing: 8 - 3 = 5 zero hextets Expanded: 2001:0DB8:0000:0000:0000:0000:0000:0025

6. Common Mistakes

  • Using two double colons: 2001::10::25 is invalid.
  • Removing trailing zeros: 1200 cannot become 12.
  • Compressing non-zero hextets: only complete 0000 hextets 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: /64 identifies network bits; it does not state how many hextets :: replaces.

7. Practice Examples

ExpandedShortened
2001:0DB8:0000:0000:0000:0000:0000:00012001:DB8::1
FE80:0000:0000:0000:0212:34FF:FE56:7890FE80::212:34FF:FE56:7890
FD12:3456:789A:0001:0000:0000:0000:0042FD12: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.