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
IPv6 formulas at a glance
- One hex digit = 4 bits, one group = 16 bits
- Fixed (network) digits = prefix ÷ 4
- /64 subnets in a prefix =
2^(64 − prefix) - Addresses in a prefix =
2^(128 − prefix) - No broadcast, so no addresses are subtracted
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.
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).
One hex digit is 4 bits, called a nibble. That is the key to IPv6 math: every digit is worth 4 bits of prefix.
Rules for shortening IPv6 addresses
- Drop leading zeros in each group:
0db8becomesdb8, and0000becomes0. - Replace one run of consecutive zero groups with
::. It may appear only once per address. - If there is more than one run of zeros, shorten the longest. On a tie, shorten the first.
- A single zero group stays
0, and letters are lowercase (RFC 5952).
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.
| short | full |
|---|---|
| ::1 | 0000:0000:0000:0000:0000:0000:0000:0001 |
| 2001:db8:: | 2001:0db8:0000:0000:0000:0000:0000:0000 |
| fe80::1:2 | fe80:0000:0000:0000:0000:0000:0001:0002 |
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).
| prefix | fixed digits | typically | /64 subnets |
|---|---|---|---|
| /32 | 8 | RIR allocation to an ISP | 4,294,967,296 |
| /48 | 12 | one organization or site | 65,536 |
| /56 | 14 | home or small business customer | 256 |
| /60 | 15 | home customer at some ISPs | 16 |
| /64 | 16 | one LAN | 1 |
| /128 | 32 | a 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.
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.
- Write the address in full:
2001:0db8:abcd:12ab:0000:0000:0000:0001. - Divide the prefix by 4 to get the number of fixed digits: 56 ÷ 4 = 14 digits.
- Keep the first 14 digits:
2001:0db8:abcd:12. Set the rest to 0 for the network, or to f for the last address. - The network is
2001:db8:abcd:1200::/56, and the last address is2001:db8:abcd:12ff:ffff:ffff:ffff:ffff. - The /64 subnets inside run from
2001:db8:abcd:1200::/64to2001:db8:abcd:12ff::/64, which is 2⁸ = 256 subnets.
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.
Special IPv6 ranges
| range | used for |
|---|---|
| 2000::/3 | global unicast: public internet addresses |
| fc00::/7 | unique local (ULA): private networks, like 192.168.x.x |
| fe80::/10 | link-local: valid on one network segment only |
| ff00::/8 | multicast, which replaces broadcast |
| ::1/128 | loopback, like 127.0.0.1 |
| ::/128 | unspecified, used before a device has an address |
| ::ffff:0:0/96 | IPv4 addresses written inside IPv6 |
| 2001:db8::/32 | documentation 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.
Further reading on Jetorbit
These articles are in Indonesian.