## Contents

- How to: Convert a Decimal Number to a Base-256 dotted-decimal / dotted-quad
- How to: Convert an IPv4 Address to a Decimal Number

## How to: Convert a Decimal Number to a Base-256 dotted-decimal

This is useful to determine a high subnet address when the Block Size increment is not practical. e.g. What’s the subnet address of the 4096th subnet?

- If you start counting subnets from zero, then multiply the target Subnet # by the number of addresses per subnet, to determine how many addresses to add to the 1st subnet/subnet-zero, to jump to the target subnet.
- Note: If you start counting subnets from 1, e.g. 1st, 2nd, 3rd, etc., then multiply the (target Subnet – 1) by the number of addresses per subnet.

- Convert the result to the Base-256 dotted-decimal equivalent.
- Add that Base-256 dotted-decimal equivalent to the 1st subnet, to get the IP address of the target subnet.

Step | |

1 | Evaluate the number: If the decimal number is >= 256, then continue to step 2.If the decimal number is less than 256, then use that decimal number for the 4th octet, and pad the rest with zeros so that the result is in dotted-decimal form, with four octets. |

2 | Divide the decimal number by 256 |

3 | Multiply the decimal portion of the result from step 2 by 256 |

4 | Subtract the result of step 3 from the original decimal number to yield the Base-256 octet |

5 | Examine the decimal portion of the result from step 2. If that decimal portion of the number is less than 256, then use that number for the next octet. Use zeroes for any remaining octets, so that the number is in dotted-decimal form. If that number is larger than, or equal to 256, then continue from step 2, using that number. |

### Example 1

What is the IPv4 network address of the last subnet, for the classless network 16.0.0.0 /17, with a total of 512 subnets?

- 2
^{<bits borrowed>}= # of subnets: 512 subnets = 2^{9}(9 bits borrowed) - /17 + 9 bits borrowed = a new mask of /26
- Since we start counting from zero, the subnet # range is 0 – 511. So the the last, and target, subnet is Subnet # 511
- 32 IPv4 bits – 26 network bits = 6 host bits. 2
^{6}= 64 addresses per subnet - Subnet #511 x 64 addresses per subnet = 32,704 addresses that must be added to subnet zero to jump to the target subnet.

#### Convert 32,704 to Base-256 (dotted decimal)

Forth Octet

- Evaluate the number: The number is larger than 256, so we can process the number
- 32,704 / 256 = 127.75
- 127 x 256 = 32,512
- 32,704 – 32,512 = 192 (is the 4th octet of the dotted decimal)

Third Octet

- We start with the integer from Part 1, 127. Evaluate the number: The number is not larger than 256, so we cannot process the number.
- 127 (Is the 3rd octet)

The Base-256 dotted equivalent of 32,704, is 0.0.127.192, which is what we add to subnet zero to determine the 512th subnet

16.0.0.0 + 0.0.127.192 = 16.0.127.192

### Example 2

#### Convert 32,767 to Base-256 (dotted decimal):

- Evaluate the number: The number is larger than 256, so we can process the number
- 32,767 / 256 =
**127**.996 **127**x 256 = 32,512- 32,767 β 32,512 =
**255**(this is the 4th octet of the dotted decimal) - Since 127 is smaller than 256 you’re done dividing and the value for the 3rd octet is 127

Using zeroes for the remaining octets yields a Base-256 value of: **0.0.127.255**

- The 255 is from step 4, and the 127 is what was left over, and the 0’s fills out the dotted-decimal.

## Examples

## How to: Convert an IPv4 Address to a Decimal Number

256^{3} | 256^{2} | 256^{1} | 256^{0} |

16,777,216 | 65,536 | 256 | 1 |

w | x | y | z |

An IPv4 address is a 32-bit number. It is generally written in the “dotted-decimal” notation: w.x.y.z. To convert an IP address to base 10, use the following:

w * 16,777,216 + x * 65,536 + y * 256 + z = Decimal IP Address