IPv4 Addresses

 A review of IPv4 addressing



IP addresses can be either IPv4 or IPv6. IPv6 addressing is out of the scope of this post but will be in another post later. IPv4 addresses are 32-bits long and are represented in dotted decimal notation. There are two portions of IPv4 addresses: The network portion and the host portion. The network portion identifies a physical or logical link and is common to all devices attached to that link. The host portion identifies a unique device connected to the link. We distinguish between the network portion and the host portion with the subnet mask. We represent IP addresses in dotted decimal to make it easier for us to remember and work with. Each group of 8-bits is referred to as an "octet" and the "." separates each grouping of 8-bits. Since there are 4 groups of 8-bits that gives us a 32-bit address. We can change an IP address back to the binary equivalent to get a better idea of the the host and network portions. 

Dotted decimal
IP: 192.0.0.1
Subnet Mask: 255.255.255.0
binary format
11000000 . 00000000 . 00000000 . 00000001

We generally classify networks into, well, classes. There are three major classes(the others we won't talk about). The classes are A, B, C, and they are three different size networks. Basically, Class A is for very large networks. Because they are very large networks you have fewer networks. Class B is for medium sized networks that have smaller networks in relation to Class A but have much more of the networks. Class C is for small networks. These small networks can only have a small amount of hosts on them so there can be a lot more networks in relation to both Class A and B. These Classes are known as classful boundaries. If you want to visualize the difference in the classes we can take our IP address we saw above and represent it with each class.

Class A
192.0.0.1 
255.0.0.0

Class B
192.0.0.1
255.255.0.0

Class C(which is what it is above)
192.0.0.1
255.255.255.0

We use the subnet mask to tell us where the boundary is between the network portion and the host portion. Wherever there is a "255" we can just say that is part of the network portion and where there is a "0" we can say that is part of the host portion. Notice that these Classes are at an octet boundary. Okay, so now how can we tell how many hosts we can have on our network ? or what the network address is ?

We will start with the network address, which is the first address in a subnet and is used to identify the whole subnet. An example would be 192.0.0.0 being our network address for our class C subnet. The way we find the network address is to set all the host bits to zero. In our example, we had 3 octets as network portion and 1 octet as host portion. So if I write down the digits where I have a 255(which tells me that section is part of the network portion) we will get:
192.0.0.X
If we then set the host portion to zero that will give us our network address:
192.0.0.0
Now we have the subnet identifier(the network address), we need to find out how many addresses are available in our subnet. To calculate the number of host addresses in a subnet you use the following formula: 2^h - 2, where h is the number of host bits. In our example, we had the last octet(8-bits) for host bits. so to calculate how many hosts we would calculate 2^8 - 2 = 254 hosts. Why the (-2) ? We subtract the 2 because in each subnet there are two reserved addresses, one if the network address(the one we just showed) and the other is the broadcast address. The broadcast address is the address hosts use to communicate with all the hosts on the same subnet. 

So how does a router or other network devices know when another device is on the same network as itself ? 
The answer is that the router/device will perform a logical AND with its subnet mask. If the device has the same network address as itself then it knows that it's on the same network and if it doesn't then it knows it must reach out to the gateway address in order to reach this device. 

This was just a high level look at IP addresses and if you want to go even deeper then I suggest you look at Jeff Doyle's book Routing TCP/IP volume 1. 












Comments

Popular posts from this blog

AWS Identity and Access Management(IAM)

AWS Virtual Private Clouds(VPCs)

IPSec VPN - Fundamentals