As mentioned in my previous post, IPv4 uses 32 bits (4-byte) addresses, and it is usually written in a dotted-decimal notation such as: 192.168.1.1
However, there are some characteristics and rules that you should remember:
- Each of the four decimal (each octet) range between 0 and 255
- Every IP address is composed of a Network component and a Host component, these components are defined by the subnet mask. The Network component, defines on what segment, in the network the, a device is located. The Host component, defines the specific device on a particular network segment. (explained below)
- IPv4 classification system is known as Classful Network Architecture and is broken down into five classes (explained below)
IPv4 classful network architecture
The IPv4 classification system, known as Classful Network Architecture is broken down into five classes: Class A, B, C, D, and E. The first octet of the IP address defines which the address is a member of, as each of this classes has a predefined network and host boundary.
Class A addresses
The first byte (8 bits) is a network number and the last 3 bytes (24 bits) are for host numbers. Class A addresses always begin with a 0 in the higher order bit.
00000001 to 01111110
Class A addresses range from 1 to 126, because 0 is reserved and represents all IP addresses, and 127 is a reserved address used for testing (Loopback address).
Class B addresses
The first 2 bytes (16 bits) are for network numbers and the last 2 bytes (16 bits) are for host numbers.
Class B addresses always begin with 10 in the higher order bits.
10000000 to 10111111
Class B addresses range from 128 to 191.
Class C addresses
The first 3 bytes (24 bits) are for network numbers and the last byte (8 bits) are for host numbers.
Class C addresses always begin with 110 in the higher order bits.
11000000 to 11011111
Class C addresses range from 192 to 223.
Class D addresses
This class is used for multicasting.
Class D addresses always begin with 1110 in the higher order bits.
11100000 to 11101111
Class D addresses range from 224 to 239.
Class E addresses
Class E addresses are reserved, they always begin with 11110 in the higher order bits.
11110000 to 11110111
Class E addresses range from 240 to 254, 255 is a reserved address used for local broadcasting purposes.
Each IP address actually has three components, a Network Component, a Host Component and a Subnet Mask. The function of the subnet mask is to differentiate between the network addresses, the host addresses and the directed broadcast address. In other words the subnet mask is a group of four numbers that define what IP network the computer is member of.
Like the IP address, the subnet mask is 32 bits long. When working with binary numbers, a 1 represents a network component and a 0 represents a host component. Because of this definition, in the subnet mask all 1s must be contiguous follow by all host bits (0s) that are contiguous.
Valid subnet mask
11111111.11111111.11110000.00000000 — (255.255.240.0) — Contiguous 1s follow by contiguous 0s
Invalid subnet mask
11110000.00000000.00000000.11111111 — (240.0.0.255) — All 1s are not contiguous
Two common methods to represent a subnet mask are:
Dotted-decimal: 220.127.116.11 255.255.255.0
Number of Network bits: 192.168.1.0/24
For a Class A network, the default subnet mask is 255.0.0.0, where the first byte is the network number and the last 3 bytes are the host numbers.
For a Class B network, the default subnet mask is 255.255.0.0, where the first 2 bytes are for the network numbers and the last 2 bytes are the host numbers.
For a Class C network, the default subnet mask is 255.255.255.0, where the first 3 bytes are for the network number and the last byte for the host numbers.
For a default subnet mask the network address would be the very first address, and the broadcast address would be the last address, the host are represented by addresses between the network and the broadcast address:
Network address: 10.0.0.0
Broadcast address: 10.255.255.255
Host addresses: 10.0.0.1 to 10.255.255.254
Because in a subnet mask all 1s must be contiguous and all 0s contiguous, not all values can be used, the following figure show valid subnet mask values.
One important point you should remember is that the subnet mask alone means nothing without the context of the IP address associated with it. Most people assumes that a subnet mask of 255.255.255.0 is associated with a Class C network. However, that is not true. Subnetting, allows you to take some higher-order bits from the host component and use them to create more networks, each network has a lesser number of host. These smaller networks are called subnets.
Let’s say we have an IP network address 192.168.1.0, by default the subnet mask of a Class C network would be 255.255.255.0. But what if we want to divide this network into 14 different subnets? Each subnet with a maximum of 14 host.
Therefore, if we add 4 subnet bits to the Class C default subnet mask we get a new subnet mask:
11111111.11111111.11111111.11110000 — 255.255.255.240
For this new subnet mask you can divide the original Network address into 16 subnets, each subnet will have a total of 14 host addresses, one network address, and one broadcast address for a total of 16 addresses per subnet.
Our new Network numbers would be:
The first network address
The second network address would be, the first network address plus 16 addresses (0+16=16)
The third network address would be the second network address plus 16 addresses (16+16=32)
And so on…
The last network address would be 256-16=240 (256= total # of addresses per octet; 0 to 255)
The Broadcast address for the first subnet would be the second network address minus 1 address (16-1=15)
Broadcast address for the second subnet would be the third network address minus 1 address (32-1=31)
And so on…
The last broadcast address is 255
The host addresses for the first subnet are the addresses between the network first number and the first broadcast address
192.168.1.1 to 192.168.1.14
As you can see there are a total of 14 host addresses.
Host addresses for the second subnet are the addresses between the second network number and the second broadcast address
192.168.1.16 to 192.168.1.30
And so on…
Another important point about subnetting is that originally you were not allowed to use the first a last subnet (subnets 192.168.1.0 and 192.168.1.240 in the example), usually referred to as subnet 0. However, nowadays is supported (assuming your TCP/IP protocol stack supports subnet 0), actually subnet 0 has been support since the mid-1990s so now this shouldn’t be an issue.
I tried to make the explanation as easy and short as possible, however should you have any doubts I recommend you to read “TCP/IP Illustrated, Vol. 1: The Protocols”
Subnetting IPv6 addresses works pretty much like IPv4 (even simpler).
An IPv6 address begins with the Global Routing Prefix which is the initial value that must be the same in all IPv6 addresses inside the enterprise, and it ends with the Interface ID which is the equivalent to the Host address in IPv4.
The Global Routing Prefix is assigned to the company by an organization such as IANA, ISP, etc. that can allocate the global routing prefix. This allocation includes both the Global Routing Prefix itself and the prefix length (the global routing prefix length is often between 32, 48 and 56 bits).
The Interface ID field which acts as the IPv4 Host field, is often (but not fixed to) 64bits in length.
The subnet field, sits between the Global Routing Prefix and the Interface ID field. The length of the subnet field will depend on the length of the Global Routing Prefix and the Interface ID.
For example, if we are assigned a Global Routing Prefix (P) 48 bits long, and we use the usual 64 bits Interface ID (I), the subnet field (S) would be S = 128-I-P bits; S=16 bits. Allowing to 216 possible IPv6 Subnets (65,536 subnets). Each subnet will support over 1018 addresses per subnet (264, minus some reserved values). Few companies would need that many subnets, and hosts, therefore IPv6 structure supports far more than needed. Additionally, the 64 bits prefix length makes the math simple, because it cuts the 128 bits IPv6 address in half.
Also called Classless Interdomain Routing, is a way to aggregate multiple network addresses of the same class. It was created to prevent Internet routers from becoming overwhelmed with routes (network addresses).
In simple words Supernetting is used to collapse multiple network addresses into a single entry corresponding to all of the network addresses of the same class allocated to an organization.
For example, let’s say we have 8 class C networks (default subnet mask 255.255.255.0)
The resulting Address would be
Once again, I tried to make the explanation as easy and short as possible, however should you have any doubts I recommend you to read “TCP/IP Illustrated, Vol. 1: The Protocols”