Back to basics #3 – IP
Today we will continue our short review of TCP/IP basics. In the previous article I have just scratched the surface. Today, let’s concentrate on some deeper concepts. All hail IP&CIDR!
Table of Contents
ToggleWhat are you doing exactly IP?
To start with – below I am posting again the layered model of the networking stack (thank you Wikipedia).
IP (Internet Protocol for those who don’t remember) has a couple of responsibilities in the TCP/IP stack. It defines the way messages from the application layer are being transformed into datagrams – which later will be translated by lower layers of the stack into frames and later – raw bits. The second responsibility is to define, how hosts within the network see each other. It does that introducing a separate, logical addressing layer, on top of the physical one.
Okay, that sounds complicated. Let’s make things easier. Imagine we got ten machines within our network, with single network interface for each. It could be possible to “remember” all the physical addresses (MACs of the network cards), and route the traffic accordingly. Unfortunately, that solution does not scale for larger networks (especially with the fact, that MAC addresses, are assigned during manufacturing process). Therefore, a simple idea was introduced to separate physical addresses, from the logical ones. It allowed for more flexible network topologies and simplified the whole thing. With the logical addresses, every machine is identified with a single numerical value, e.g. 168.78.2.0
The above identifier is a proud representation of IPv4 – protocol version that forms the backbone of today’s internet. Newer version of it – IPv6 – is still trying to make its way towards wider adoption, but it takes time. Anyway, what is important here, is the fact, that IP address allows for simple division of the IP address into two parts – network identifier and host identifier.
Gimme my IP identifier
The original idea behind IP was created, when the world looked a little bit different than today. Especially when it comes to the amount of network hardware. Everything started with a simple concept of 32bit number, that was design to identify every host in a unique way. For the simplicity of the usage, IPv4 address is usually presented in a form of four octets. Now, depending on the class we can have three “main” classes. They are depicted below.
Depending on the amount of bits designated for network identification part, we can have different amount of unique host IPs. How many? Here you go:
- Class A – 16 777 216
- Class B – 65 534
- Class C – 256
All righty. You may ask here – how do we know, which address class is being used with the IP like 5.189.23.11 ? Well – subnet mask to the rescue.
What is a subnet mask?
Subnet mask is another 4 octets identifier, that divides IPv4 address into network part, and host part. In general the mask specifies how many bits should be used as a network identifier. Therefore, we got lots of possibilities here, depending on the address class. 32 bits are used to identify which octet relates to network address, and which to the host part.
You can find how this “masking” works on the picture below:
Number of “1” in the bits is deciding, which IP octets are used as a network segment indicator, and which are identifiers for the host machine. Subnet mask is assigned automatically by DNS provider, although it can be also set manually.
How does this whole internet still work?
You can pause for a moment – because there should be something lingering at the back of your skull. Yup, with IPv4 addresses, there’s circa 4 billion possible unique identifiers to be used. So how is it, that almost every person on the planet owns smartphone with internet access? Not to count numerous other smart devices, data centers and stuff. Well, so far we did not fully embrace the benefits of IPv6 (which offers gazillion of unique IPs). The reason why everything still works is NAT – Network Address Translation. I will possibly create a separate blog post about it (including private networks and how that packet sending works). For the time being let’s just stay in the IPv4 for a moment. We got one last thing left to describe – CIDR.
CIDR to the rescue
In 2011 a new way of (re)using IPv4 emerged – CIDR (Classless Inter-Domain Routing). In short, it’s the extension of the concept of subnet mask, but not limited to specific classes. Right now any kind of number of bits can be specified as a network segment identifier. Let’s take an example from the book “TCP/IP in 24 hours”.
ISP has an IP range in their offer, starting from 204.21.128.0 to 204.21.255.255 – I have marked the common part of the address in bold. Those are 17 bits – and therefore, when we apply 17 bit mask to the address (in decimal – 255.255.128.0), we get IP address with the following value – 204.21.128.0/17 – which resulted in the simple fact that right now, for every router in the world, all those IP addresses that are in range between 204.21.128.0 to 204.21.255.255 can be now represented with a single entry in the routing tables.
You can find all the possible CIDR values in the table below. You can find numerous calculators online, that based on the IP address and subnet mask can provide all the necessary information.
What’s next?
If you’re a little bit lost – don’t worry. After reading next pieces in the series it should be easier to get a grasp of things. If you don’t want to wait for me to write the next pieces – here’s a short video that explains some stuff.
Leave a Reply
You must be logged in to post a comment.