IPv4 Addressing/ Subnetting

Understanding Binary/ Hexadecimal

In order to understand IP addressing and network subnetting, the binary and hexadecimal numeral systems must first be understood. A numeral system is a system of expressing numbers using a set of unique digits or symbols with consistency.

The binary(base2) numeral system uses only the symbols "1" and "0", decimal(base10) uses the familiar symbols "0123456789", and hexadecimal(base16) extends the decimal symbol space to "0123456789ABCDEF". With a numeral system of base n, where n is equal to the length of a symbol space of unique characters, the maximum value expressed by a string of symbols of length x is equal to nx - 1. For example, the maximum value expressed with 3 symbols in base2 is 23 - 1 or 7(base10)!

Decimal Binary Hexadecimal
100 + 0 = 0 20 + 0 = 0 160 + 0 = 0
100 + 1 = 1 20 + 1 = 1 160 + 1 = 1
100 + 2 = 2 21 + 0 = 10 160 + 2 = 2
100 + 3 = 3 21 + 1 = 11 160 + 3 = 3
100 + 4 = 4 22 + 0 = 100 160 + 4 = 4
100 + 5 = 5 22 + 1 = 101 160 + 5 = 5
100 + 6 = 6 22 + 21 = 110 160 + 6 = 6
100 + 7 = 7 22 + 21 + 1 = 111 160 + 7 = 7
100 + 8 = 8 23 + 0 = 1000 160 + 8 = 8
100 + 9 = 9 23 + 1 = 1001 160 + 9 = 9
101 + 0 = 10 23 + 21 = 1010 160 + A = A
101 + 1 = 11 23 + 21 + 1 = 1011 160 + B = B
102 + 2 = 12 23 + 22 = 1100 160 + C = C
101 + 3 = 13 23 + 22 + 1 = 1101 160 + D = D
101 + 4 = 14 23 + 22 + 21 = 1110 160 + E = E
101 + 5 = 15 23 + 22 + 21 + 1 = 1111 160 + F = F
101 + 6 = 16 24 + 0 = 10000 161 + 0 = 10

An IPv4 address is made up of 4 "octets", or 4 binary strings of length 8(32 in total). Each positional value, or bit, can hold the value of either "1" or "0". With a length of 8(bits), 28, or 256 unique values(0 - 255 in base10) can be expressed. With an entire 32-bit IPv4 address, 232, or 4,294,967,296 unique values can be expressed!

base10 192.168.255.1
base2 11000000.10101000.11111111.00000001

For a better understanding of numeral systems, clone this repository.


Converting Between Binary and Decimal By Hand

Converting between binary and decimal by hand can be difficult and time consuming. Below is a simple method of converting between base10 and base2.

Decimal Value: 163

  1. Outline base conversion right to left: 20 - 27
  2. 128 64 32 16 8 4 2 1
  3. From left to right, subtract table values until decimal value == 0. If decimal value >= table value: insert 1, else: insert 0
  4. 128 64 32 16 8 4 2 1
    1 0 1 0 0 0 1 1
  5. base10: 163, base2: 10100011


Why Subnet?

Subnetting is the process of splitting a broad network segment into multiple smaller portions. In doing so, a minimal amount of IPv4 address space is wasted. A network which only requires 250 hosts, sould not receive 16,777,214 hosts(/8), rather 254 hosts(/24).

Each network has two portions: a host portion, and network portion. The length(in bits) of the network portion is specified with a subnet mask(ex. /8, /12, /24). The host portion can then be used to assign addresses to individual host interfaces.

network | host
base10 10.0.0.0 /8
base2 00001010.0000000.00000000.0000000 /8
network | host
base10 172.16.0.0 /12
base2 10101100.00010000.00000000.0000000 /12
network | host
base10 192.168.1.0 /24
base2 11000000.10101000.00000001.0000000 /24

How To Subnet By Hand

After numeral systems and binary are understood, subnetting becomes simple!

Subnetting a broad network into multiple smaller networks involves simply dividing networks in half repeatedly until the desired subnet count/ size is reached. However, each network division consumes an additional 2 hosts within the network (network and broadcast addresses).

Subnetting 192.168.1.0 /24

  1. Find the bit that needs to be split: 24 + 1 = 25
  2. 1-8 9-16 17-24 25 26 27 28 29 30 31 32
    octet1 octet2 octet3 128 64 32 16 8 4 2 1
    192 168 1 0 0 0 0 0 0 0 0
  3. Create 2 subnets: one with the 25th bit="0", and the other with the 25th bit="1"
    Subnet 1 192 168 1 0 0 0 0 0 0 0 0 /25
    Subnet 2 192 168 1 1 0 0 0 0 0 0 0 /25
  4. Now, the /24 network has been split into 2 /25 networks: 192.168.1.0 /25 and 192.168.1.128 /25. This process can be continued until /30, which can no longer be divided as there will be no available hosts in a /31 network.


For a better understanding of subnetting watch this video.

More on IPv4 addressing.