given an ip v6 prefix, find the valid ip range,next network

Aug 28th, 2010

Hi  every body.

In ipv4  i used the following  steps to find  valid ip range, subnet,next subnet

Example:

10.10.10.0/24

subnet:

256-255=1

10.10.10.0  is the subnet

next subnet  :

should be the multiple of 1

so  10.10.11.0   is  next  subnet after subnet 10.10.10.0

valid  ip range:

10.10.10.1--10.10.10.254

=============================

Let say we have ipv6  prefix  i.e  2001:0000::/23

our goal is to find  valid ip address range, network number, next network number.  Here i am stumped.

thanks and have a great weekend.

Hello Sarah and Giuseppe,

Giuseppe is of course right. However, if taking this purely technically, a similar method (although not so straightforward) can be used to compute networks and their multiples in IPv6 addresses.

`Let say we have ipv6  prefix  i.e  2001:0000::/23our goal is to find  valid ip address range, network number, next network number.  Here i am stumped.`

Okay but let's take a more appropriate example, say: 2001:4118:ABCD::/46.

So the /46 prefix means that the "mask" (which is not used in this format in IPv6) is 16+16+8+6 bits long, translating into FFFF:FFFF:FFFC. How did I calculate that? Well, it is worth memorizing the following table of translation from decimal to hexadecimal mask byte:

Number of bits (CIDR)
Decimal value
/000x0
/11280x80
/21920xC0
/32240xE0
/42400xF0
/52480xF8
/62520xFC
/72540xFE
/82550xFF

Now note that each hexadecimal digit (0-9, A-F) is a direct expression of a 4-bit value. In hexadecimal notation, we can perform the binary AND on individual hexadecimal digits. Also note that for sake of easiness, we can translate each nibble to a value between 0 and 15 and compute the AND in decimal, then reconvert the result back to hexadecimal if that suits you better. Let's call this one hexadecimal digit (a group of 4 bits) a nibble.

So, to compute the address of the network, we have:

`2001:4118:ABCD::&&FFFF:FFFF:FFFC::`

The only "interesting" nibble here is the last one where the mask nibble is set to C (all other nibbles are uninteresting because any nibble bitwise ANDed with 0xF yields the same value again, and all other nibbles ANDed with 0 yield 0). All we have to do now is compute the binary AND of 0xD in the address and of the 0xC in the mask. Let's do it in decimal and in the very similar way to how we compute it for IPv4 addresses but here, we are in the scope of a single nibble so instead of subtracting the mask from 256, now we subtract the mask from 16:

`0xD = 14 (nibble in the address)0xC = 12 (nibble in the mask)16 - 0xC = 16 - 12 = 4 - the networks are multiples of 4 on the interesting nibble0xD = 14 rounded down to a multiple of 4 is 12 which is 0xC in hexadecimal`

Thus, the network number in this case would be 2001:4118:ABCC::, and the next network would be 4 "steps" further at the interesting nibble and above: 2001:4118:ABC(C+4):: yielding 2001:4118:ABD0:: (note that 0xC + 4 = 0x10 so the predecessing nibble had to be incremented as well).

So the general process is:

2. Find the (only) interesting nibble in mask whose value is neither 0x0 nor 0xF
3. Convert the interesting nibble from hexadecimal to decimal.
4. In decimal, subtract the value of this interesting nibble from 16, and call this resulting difference M.
5. Convert the corresponding nibble in the IPv6 address from hexadecimal to decimal. Let us call this value A.
6. Round down the decimal value A to the nearest integer multiple of M, and convert it back to hexadecimal.

I guess that after a longer practice the converting between decimal and hexadecimal will not be necessary anymore. This can be computed directly in hexadecimal, however, a care must be then taken to not to mix decimal and hexadecimal notations.

Best regards,

Peter

Hello Sarah,

for IPv6 given the ultra big space no one cares of the number of hosts in a subnet.

The typical IPv6 subnet is an EUI-64 that has a 64 bit network portion and a 64 bit host portion.

Typical IPv6 prefix is a /48  that allows you to have 65535 /64 IPv6 subnets.

to be noted EUI-64 is taken from MAC address and 16 bits have a fixed value so in this case only 2^48 -2 are the possible hosts.

Hope to help

Giuseppe

Overall Rating: 5 (2 ratings)

Replies

Giuseppe Larosa Sun, 08/29/2010 - 13:05

Hello Sarah,

for IPv6 given the ultra big space no one cares of the number of hosts in a subnet.

The typical IPv6 subnet is an EUI-64 that has a 64 bit network portion and a 64 bit host portion.

Typical IPv6 prefix is a /48  that allows you to have 65535 /64 IPv6 subnets.

to be noted EUI-64 is taken from MAC address and 16 bits have a fixed value so in this case only 2^48 -2 are the possible hosts.

Hope to help

Giuseppe

Peter Paluch Mon, 08/30/2010 - 01:56

Hello Sarah and Giuseppe,

Giuseppe is of course right. However, if taking this purely technically, a similar method (although not so straightforward) can be used to compute networks and their multiples in IPv6 addresses.

`Let say we have ipv6  prefix  i.e  2001:0000::/23our goal is to find  valid ip address range, network number, next network number.  Here i am stumped.`

Okay but let's take a more appropriate example, say: 2001:4118:ABCD::/46.

So the /46 prefix means that the "mask" (which is not used in this format in IPv6) is 16+16+8+6 bits long, translating into FFFF:FFFF:FFFC. How did I calculate that? Well, it is worth memorizing the following table of translation from decimal to hexadecimal mask byte:

Number of bits (CIDR)
Decimal value
/000x0
/11280x80
/21920xC0
/32240xE0
/42400xF0
/52480xF8
/62520xFC
/72540xFE
/82550xFF

Now note that each hexadecimal digit (0-9, A-F) is a direct expression of a 4-bit value. In hexadecimal notation, we can perform the binary AND on individual hexadecimal digits. Also note that for sake of easiness, we can translate each nibble to a value between 0 and 15 and compute the AND in decimal, then reconvert the result back to hexadecimal if that suits you better. Let's call this one hexadecimal digit (a group of 4 bits) a nibble.

So, to compute the address of the network, we have:

`2001:4118:ABCD::&&FFFF:FFFF:FFFC::`

The only "interesting" nibble here is the last one where the mask nibble is set to C (all other nibbles are uninteresting because any nibble bitwise ANDed with 0xF yields the same value again, and all other nibbles ANDed with 0 yield 0). All we have to do now is compute the binary AND of 0xD in the address and of the 0xC in the mask. Let's do it in decimal and in the very similar way to how we compute it for IPv4 addresses but here, we are in the scope of a single nibble so instead of subtracting the mask from 256, now we subtract the mask from 16:

`0xD = 14 (nibble in the address)0xC = 12 (nibble in the mask)16 - 0xC = 16 - 12 = 4 - the networks are multiples of 4 on the interesting nibble0xD = 14 rounded down to a multiple of 4 is 12 which is 0xC in hexadecimal`

Thus, the network number in this case would be 2001:4118:ABCC::, and the next network would be 4 "steps" further at the interesting nibble and above: 2001:4118:ABC(C+4):: yielding 2001:4118:ABD0:: (note that 0xC + 4 = 0x10 so the predecessing nibble had to be incremented as well).

So the general process is:

2. Find the (only) interesting nibble in mask whose value is neither 0x0 nor 0xF
3. Convert the interesting nibble from hexadecimal to decimal.
4. In decimal, subtract the value of this interesting nibble from 16, and call this resulting difference M.
5. Convert the corresponding nibble in the IPv6 address from hexadecimal to decimal. Let us call this value A.
6. Round down the decimal value A to the nearest integer multiple of M, and convert it back to hexadecimal.

I guess that after a longer practice the converting between decimal and hexadecimal will not be necessary anymore. This can be computed directly in hexadecimal, however, a care must be then taken to not to mix decimal and hexadecimal notations.