DEV Community

Tomislav Kraljic
Tomislav Kraljic

Posted on • Edited on

How IP Addresses Work

In this article, I will go over what IP addresses are, types of addresses, class-full vs class-less addresses, classes of networks, subnets and CIDR (Classless Inter-Domain Routing) notation.

What is an IP Address?

In the most simplest terms, an IP (Internet Protocol) Address is a unique local address used to locate a computer/device via a network.

There are two types of IP Addresses:

1) IPV4 (32 bit)

192.168.0.100 
Enter fullscreen mode Exit fullscreen mode

2) IPV6 (128 bit)

FD3B:F15C:C672:34B8::100
Enter fullscreen mode Exit fullscreen mode

In this article, we will focus on IPV4 addresses as they are the ones most commonly used.

Let's take a look at an example of an IPV4 address

192.168.0.100
Enter fullscreen mode Exit fullscreen mode

Each number is called an octet because it is an 8 bit value.

192: 1100 0000
168: 1010 1000
0: 0000 0000
100: 0110 0100

8 bits means these number can range from 0-255.

0: 0000 0000
255: 1111 1111

This means an IP address starts at 0.0.0.0 and ends at 255.255.255.255.

This range of IP addresses is called the IP Space.

IP Addresses are actually comprised of 2 addresses in one.

  • Network Address
  • Host Address

Let's take a look at an example:

176.16.0.1

172.16: Network Address
0.1: Host Address

Is it always the first two as the network address and last two as the host address?

No. It is dependent on the class of address. We will take a look at them in the following section.


Class-full Networking and Classes of IP Addresses

There are a total of 5 classes: A, B, C, D, E

For this article, I will only go over classes A, B, and C because they pertain to devices and are the ones most commonly used.

Class A: Large Networks

Range: 1.0.0.1 - 126.255.255.254

Example:
1.2.3.4

  • The first number (octet) is for the network and the remaining three are for hosts.

1: Network
2.3.4: Hosts

Class B: Medium Networks

Range: 128.1.0.1 - 191.255.255.254

Example:
129.2.3.4

  • The first two numbers (octets) are for the network and the last two are for hosts.

Class C: Small Networks:

Range: 192.0.0.1 - 223.255.254.254

Example:
130.2.3.4

  • The first three numbers (octets) are for the network and the last number is for the hosts.

Note: You may notice that 127 is not included in these ranges. The reason is because that is a special one reserved for localhost.

This was called "class-full networking". This was the architecture used from 1981 until 1993. In 1993, CIDR(Class-less Inter-Domain Routing) was invented and we switched over.

Why?

Well, let's take a closer look at an IP Address.

172.16.0.0.

This allows for 65,000 hosts per network. If we have a bunch of small offices, we don't need to reserve 65,000 hosts per office. That is over-kill. Thus, we switched over to class-less networking.


Class-less Networking

Class-less networking relies on sub-netting and sub-net masks instead of classes now. We abandoned class-full networking and use class-less networking instead.

What is sub-netting?

  • Sub-netting is breaking up a large network into smaller ones.

What is a sub-net mask?

  • A sub-net mask tells us which part of the IP Address is for the network and host.

Example 1:4.3.2.1 -> 255.0.0.0

The 0's are reserved for hosts and the 255 (1) is reserved for the network.

Example 2: 183.6.22.9 -> 255.255.0.0

Example 3: 203.4.9.6 -> 255.255.255.0

With sub-netting, let's take a look at a previous IP Address used: 172.15.0.0

172.15.0.0 would be 255.255.0.0

This would allow for about 65,000 hosts in our network as mentioned previously.

We can break our network class into something smaller using our subnet mask.

So, instead of 255.255.0.0, it could be 255.255.255.0.

This would now only allocate 256 hosts per network. That is a lot better, and more manageable than 65,000.


CIDR Notation

CIDR Notation is a way for us to include the IP Address and the subnet mask.

172.16.1.0/24

/24 is the same as 255.255.255.0

This just means the first 24 bits of the subnet mask are turned on.

24 / 8 = 3 (first three octets of IP Address).

Top comments (1)

Collapse
 
david_adam profile image
David Adam

IP version 6 is 128 bits