IPv6 and Hexadecimal Addressing

May 28, 20266 min read

IPv6 addresses are 128 bits long, written as eight groups of four hexadecimal digits. That gives us 340 undecillion possible addresses — enough to assign trillions of addresses to every square meter of Earth's surface. The hexadecimal notation is not arbitrary; it compresses the 128-bit binary address into a human-parseable format. Understanding the hex representation and its shorthand rules is essential for network configuration, firewall rules, and debugging connectivity issues.

Structure of an IPv6 Address

An IPv6 address is 128 bits divided into eight 16-bit groups, each written as four hexadecimal digits and separated by colons:

2001:0db8:85a3:0000:0000:8a2e:0370:7334

Each group represents 16 bits (2 bytes), so four hex digits cover the range 0000 through ffff — which is 0 through 65535 in decimal.

Breaking this down:

ComponentBitsHex DigitsExample
Full address128322001:0db8:85a3:0000:0000:8a2e:0370:7334
One group1640db8
One hex digit41d

The address space is logically divided: the first 64 bits are the network prefix (assigned by your ISP or organization), and the last 64 bits are the interface identifier (usually derived from the MAC address via EUI-64 or randomly generated for privacy).

Shorthand Rules

Full IPv6 addresses are verbose. Two compression rules make them manageable:

Rule 1 — Drop leading zeros within each group:

2001:0db8:85a3:0000:0000:8a2e:0370:7334

becomes:

2001:db8:85a3:0:0:8a2e:370:7334

The 0db8 shortens to db8, 0000 becomes 0, and 0370 becomes 370.

Rule 2 — Replace one consecutive sequence of all-zero groups with :: :

2001:db8:85a3:0:0:8a2e:370:7334

becomes:

2001:db8:85a3::8a2e:370:7334

The :: replaces the two consecutive zero groups. You can only apply this rule once per address — otherwise, the parser cannot determine how many zero groups each :: represents. For example, 2001::1234::5678 is invalid because the position of the omitted zeros is ambiguous.

Some compressed examples:

Full FormCompressed
fe80:0000:0000:0000:0000:0000:0000:0001fe80::1
0000:0000:0000:0000:0000:0000:0000:0001::1
2001:0db8:0000:0000:0000:0000:0000:00002001:db8::
0000:0000:0000:0000:0000:0000:0000:0000::

The loopback address ::1 is IPv6's equivalent of 127.0.0.1. The unspecified address :: is used in binding to indicate "listen on all interfaces."

Prefix Notation

IPv6 uses CIDR notation for subnetting, identical to IPv4:

2001:db8::/32

This means the first 32 bits are the network prefix, and the remaining 96 bits are available for subnet and host addressing. Common prefix lengths:

PrefixPurpose
/128Single host address
/64Standard subnet (typical LAN)
/48Organization allocation
/32ISP or large organization block

A /64 is the smallest recommended subnet in IPv6. Unlike IPv4, where subnets are often /24 or smaller, IPv6 assumes a /64 as the baseline — even for a point-to-point link.

IPv6 and Hex Conversion

When configuring firewalls, writing route filters, or parsing packet captures, you often need to convert between hex groups and decimal or binary.

Each hex digit maps to 4 bits:

# Convert an IPv6 group to decimal
int('85a3', 16)  # 34211

# Convert decimal back to hex group
format(34211, '04x')  # '85a3'

For subnet calculations, you need to work with the full 128-bit value:

import ipaddress

# Parse and inspect
addr = ipaddress.ip_address('2001:db8::1')
net = ipaddress.ip_network('2001:db8::/32')

# Check membership
addr in net  # True

# List first few hosts in a /64 subnet
subnet = ipaddress.ip_network('2001:db8:1::/64')
list(subnet.hosts())[:5]  # First 5 host addresses

Special Address Ranges

RangePrefixPurpose
::1/128LoopbackLocal testing
fe80::/10Link-localAuto-configured, no routing
fc00::/7Unique localPrivate networks (like 10.x.x.x)
2001:db8::/32DocumentationReserved for examples (never routed)
ff00::/8MulticastOne-to-many communication

The documentation prefix 2001:db8::/32 is the IPv6 equivalent of the 192.0.2.0/24 documentation range in IPv4. Use it in examples and tutorials — it will never be assigned to a real network.

Understanding IPv6 addressing requires comfort with hexadecimal notation. Practice hex conversions with the number base tool at /tools/number-base, which handles bidirectional conversion between hex, decimal, binary, and octal with detailed step breakdowns.