ip
ipku.in

How to Calculate IPv6 Addresses

IPv6 looks hard because it is long, but the math is simpler than IPv4. There is no broadcast, and nearly every subnet boundary falls on a multiple of 4 bits.

Updated · Jetorbit

01 / summary

IPv6 formulas at a glance

Quick example: 2001:db8:abcd:12ab::1/56 has network 2001:db8:abcd:1200::/56 and holds 256 /64 subnets. Each step is explained below.

02 / basics

What an IPv6 address is made of

An IPv6 address is 128 bits written as eight hexadecimal groups separated by colons. Each group is 16 bits, or four hex digits (0–9 and a–f).

address2001:0db8:85a3:0000:0000:8a2e:0370:7334
groups8 × 16 bits = 128 bits
digits32 × 4 bits = 128 bits

One hex digit is 4 bits, called a nibble. That is the key to IPv6 math: every digit is worth 4 bits of prefix.

03 / notation

Rules for shortening IPv6 addresses

  1. Drop leading zeros in each group: 0db8 becomes db8, and 0000 becomes 0.
  2. Replace one run of consecutive zero groups with ::. It may appear only once per address.
  3. If there is more than one run of zeros, shorten the longest. On a tie, shorten the first.
  4. A single zero group stays 0, and letters are lowercase (RFC 5952).
full2001:0db8:85a3:0000:0000:8a2e:0370:7334
no leading zeros2001:db8:85a3:0:0:8a2e:370:7334
short2001:db8:85a3::8a2e:370:7334

Expanding back to the full form

Count the groups that are left, then fill :: with zero groups until there are eight. 2001:db8:85a3::8a2e:370:7334 has 6 groups, so :: stands for 2 groups of 0000.

shortfull
::10000:0000:0000:0000:0000:0000:0000:0001
2001:db8::2001:0db8:0000:0000:0000:0000:0000:0000
fe80::1:2fe80:0000:0000:0000:0000:0000:0001:0002
04 / prefix

IPv6 prefixes and subnet counts

As in IPv4, an IPv6 prefix says how many bits from the left belong to the network. The difference is that a LAN is almost always a /64. The first 64 bits are the network, and the last 64 are an interface ID the device picks itself (SLAAC).

prefixfixed digitstypically/64 subnets
/328RIR allocation to an ISP4,294,967,296
/4812one organization or site65,536
/5614home or small business customer256
/6015home customer at some ISPs16
/6416one LAN1
/12832a single address (one device)-

The formula: /64 subnets in a prefix = 2^(64 − prefix). A customer given a /56 can run 2⁸ = 256 separate /64 networks.

One /64 holds 2⁶⁴ = 18,446,744,073,709,551,616 addresses. That is why IPv6 planning counts subnets, not hosts.

05 / calculate

How to calculate an IPv6 prefix and network, step by step

Example: the address 2001:db8:abcd:12ab::1/56. Here is how to find its network and address range.

  1. Write the address in full: 2001:0db8:abcd:12ab:0000:0000:0000:0001.
  2. Divide the prefix by 4 to get the number of fixed digits: 56 ÷ 4 = 14 digits.
  3. Keep the first 14 digits: 2001:0db8:abcd:12. Set the rest to 0 for the network, or to f for the last address.
  4. The network is 2001:db8:abcd:1200::/56, and the last address is 2001:db8:abcd:12ff:ffff:ffff:ffff:ffff.
  5. The /64 subnets inside run from 2001:db8:abcd:1200::/64 to 2001:db8:abcd:12ff::/64, which is 2⁸ = 256 subnets.
address2001:db8:abcd:12ab::1/56
network2001:db8:abcd:1200::/56
first address2001:db8:abcd:1200::
last address2001:db8:abcd:12ff:ffff:ffff:ffff:ffff
/64 subnets256

When the prefix is not a multiple of 4

For prefixes like /50 or /62, one digit is split down the middle. Write that digit in binary, keep as many bits as the prefix still needs, and zero the rest. For /62 on the same address: 62 = 15 × 4 + 2, so the 16th digit (b = 1011) keeps only its first two bits and becomes 1000 = 8. The network is 2001:db8:abcd:12a8::/62, which holds 2² = 4 /64 subnets.

06 / ranges

Special IPv6 ranges

rangeused for
2000::/3global unicast: public internet addresses
fc00::/7unique local (ULA): private networks, like 192.168.x.x
fe80::/10link-local: valid on one network segment only
ff00::/8multicast, which replaces broadcast
::1/128loopback, like 127.0.0.1
::/128unspecified, used before a device has an address
::ffff:0:0/96IPv4 addresses written inside IPv6
2001:db8::/32documentation and examples

IPv6 has no broadcast address. Multicast does that job, so no addresses are set aside for network and broadcast the way they are in IPv4.

07 / jetorbit

Further reading on Jetorbit

These articles are in Indonesian.