Fun with IPv6 Subnetting
Here's a neat IPv6 subnetting method. Using any number of bits available in the subnet ID, it will allow you to calculate the number of remaining prefixes and enumerate each resulting prefix.
Note that the method is best for numbering and enumerating prefixes using non-nibble boundary bits. Recall that If we stick to the nibble boundary in the subnet ID we always get either 16, 256, 4096, or 65536 prefixes. Also, enumeration is simple as each hexadecimal character represents a nibble and prefixes will never "divide" a hex character.
Let's practice this subnetting method using a fictional IPv6 allocation. Say we've gotten an allocation of a /48 to use to number a campus LAN and we want to subnet it further.
The allocation we've received is 2001:db8:3eff::/48
Let's assume we're going to need 16 subnets for each building. This first group of prefixes will not require our method as we simply adhere to the 4 bits of the first nibble boundary.
This gives us 16 prefixes enumerated by the first character of our fourth block:
Now let's say for the sake of illustration that our typical campus building uses 20 VLANs. Since allocating 4 more bits to take us to the next nibble boundary only yields 16 additional prefixes, we'll need more than 4 bits. By standard IPv6 address planning principles we should be entirely comfortable simply allocating an additional 4 bits for a total of 8 bits. This would give us 256 additional prefixes (with 4 bits remaining for 16 /64s per prefix). But to demonstrate our method, let's get more granular and only use as many bits as gives us sufficient prefixes for the number of elements in this level of our design (i.e., 20 VLANs). Since the least number of bits that produces an integer value greater than 20 is 5 (2^5 = 32) we'll use 5 bits to subnet our /52 prefix.
a = p - 48 # where p = prefix length of the parent subnet and a = number of fixed bits in the subnet ID
From our example:
a = 52 - 48 = 4
a = 4
So we have 4 bits that are fixed (which we already knew but the value is used in later formulae).
s = 2 ^ b # where s = subnets created and b = bits used to subnet
s = 2 ^ 5 = 32
s = 32
As we outlined above, we'll create 32 subnets using 5 bits.
i = 2 ^ 16 - (a + b) # where i = the (decimal) increment value between the created subnets (which we must convert back to hexadecimal)
i = 2 ^ 16 - (4 + 5) = 2 ^ 16 - 9 = 2 ^ 7 = 128
i = 128
Converted to hexadecimal:
i = 0x80
p_1 = 48 + a + b # where p_1 = the prefix length of the created subnets
p_1 = 48 + 4 + 5 = 57
So now that we know the increment and prefix length value we can enumerate the new subnets:
Et voila: Our 32 new subnets.
We could of course subnet each of these /57s further in order to provide additional hierarchy for other organizational or operational requirements.
But assuming we don't, how many /64 interface subnets would each of these /57s provide?
n = 2 ^ (64 - p_1) # where n = number of /64 subnets provided by each new subnet
n = 2 ^ (64 - 57) = 2 ^ 7 = 128
So each /57 will provide us with 128 /64 interface subnets.
With enough practice, you'll eventually be able to do this in your head. Imagine impressing your friends and family at parties with your amazing IPv6 subnetting prowess!
For a more detailed description of this method, check out Joseph Davies excellent Understanding IPv6.