On the way to become a senior Ruby developer

network tcpip ipv4 ip basic – It costs 9 mins to read

IP is a type of logical address that belongs to the Network layer of the OSI model (and is an important component of the TCP/IP protocol suite), providing us with a convenient and flexible addressing scheme for use in following routing protocols. Most computers and network devices today are using the IPv4 version, so within the scope of this article we only mention IPv4.

Viewing: What is a network id

What is an IP address?

To send mail to each other, we must know the address of the other party, so do packets, always have a type of address to determine the location, thereby exchanging accurate information between the source machine and the destination machine. . So, in the Internet IP addresses are unique.

See also the article The journey of a packet

Structure of IP address

An IP address is a 32-bit binary string divided into four sets of eight bits called octets, consisting of a net-id part that identifies the network the device is connected to and a host-id part that identifies the device’s device. that network.

For simplicity, people rewrite IP addresses as 4 decimal numbers separated by periods.

For example, the corresponding decimal address for 11000000 10100000 00000001 00000001 would be – a familiar address.

To see the computer’s IP address simply, we can use the Command Prompt with the ipconfig command (or ifconfig if it’s a Unix system).

Subnet mask

So how to distinguish which bit belongs to the net-id part, which bit belongs to the host-id part, that is thanks to the Subnet Mask, Each IP address comes with a subnet mask, to identify the net-id part. of that address. The subnet mask is also a binary string 32 bits long and divided into 4 sets of 8 bits like the IP address.

The subnet mask consists of 1 bits and the rest are 0 bits, how many 1s the subnet mask has, the corresponding IP address will have as many net-id bits.

For example, with the following subnet mask: 11111111 11111111 11111111 00000000 ( consisting of 24 1s, the IP address carrying this subnet mask will also have 24 bits of the net-id part.

It can be written directly as follows: – or using prefix length:

Note, an IP address can belong to different networks if different subnet masks are used. To determine which network the IP address belongs to, we just need to get the IP address AND (bitwise) with the corresponding subnet mask.

READ MORE  Sửa Lỗi Reallocated Sectors Count, Hỏi Hdd Bị Reallocated Sectors Count

For example: AND = so the address belongs to the network

IP address classifier

The number of IP addresses is very large, so for the convenience of management, people divide the entire IP address into 5 different classes.

Class A

Class A addresses use the first 1 octet as the net-id, the rest as the host-id. The first bit of a class A address is always 0, so

Octet min value 1: 00000000 or 0 Octet max value 1: 01111111 or 127 Default subnet mask:

However, the value 0 (smallest octet) is not used and the value 127 (maximum octet) is reserved for Loopback and diagnostic and error checking, so the class A address range will be 1. .x.x.x to 126.x.x.x

Grade B

Class B addresses use the first 2 octets as the net-id, the remaining 2 octets as the host-id. The first 2 bits of a class B address are always 10 so

Octet min value 1: 10000000 or 128 Octet max value 1: 10111111 or 191 Default subnet mask:

So class B address range will be from 128.x.x.x to 191.x.x.x


Class C addresses use first 3 octets as net-id, octet 4 as host-id. The first 3 bits of a class C address are always 110 so:

Octet min value 1: 11000000 or 192 Octet max value 1: 11011111 or 223 Default subnet mask:

So class C address range starts from 192.x.x.x to 223.x.x.x

There is also a class D address (224.x.x.x – 239.x.x.x) which will be discussed later and class E (240.x.x.x – 254.x.x.x) used for experiments and research.

Types of IP addresses Unicast addresses

When you want to send packets to a specific computer, then the address for you to send to will be a unicast address. This is simply the IP address of a device on the same or different local network.

Multicast address

In case we want to send a packet to many computers, we cannot send it to all computers in turn. Therefore, the address you need to send to in this case will be a Multicast address, which represents a group of devices.

This multicast address is the address in the class D address range.

Broadcast address

When we want to send a message to all machines on the local network, that’s when we need to use the Broadcast address. Broadcast address is an address where all host-id part bits are 1. When the packet is sent to Broadcast address, it will be sent to all hosts on the same network, ie the same net-id part. Because it represents all devices in the network, the Broadcast address cannot be set to any device.

READ MORE  Who is the Expatriate?

For example, is the Broadcast address of the network

Network address

Not only new devices have IP addresses, but component networks of The Internet or local area network also has an address to precisely identify that network. When all the Host part bits of an IP address are 0, the address is called the network address of that network. Because it represents the network, the network address cannot be set to any device.

See also: What is Vue Js – Introduction — Vue

For example, is the network address of the network

Default Gateway

As an exit gateway, when a packet needs to be sent to an address that is not on the same network as the current network, or simply does not know where to send it, the packet will be sent to the Default gateway address, which is usually an interface of the connecting router. directly to that network. Here, the router will use routing functions to forward packets in different directions.

The Default Gateway is usually the first usable IP address of that network.

For example: The default gateway of the network is

Limitation of IP addresses

The number of IP addresses is huge, but not infinite. So to preserve IP addresses, people divide IP addresses into 2 types: public addresses and private addresses.

Public address

These are unique addresses that can be used in the Internet environment.

Private address

Only usable in the local area network, can be reused in other local area networks, but within a network must still carry a unique value.

For each IP address class, there is a range of addresses to use as private addresses for that class:

Class A: From to, subnet mask Class B: From to, subnet mask Class C: From to, subnet mask 255.255. 0.0

When devices using private IP addresses in the local network want to access the Internet – the environment does not use private addresses, NAT (Network Address Translation) technology is installed on router devices (assigned 1 Public IP address) is used to convert private IP to public IP and vice versa, making it possible for devices in the local network to still access the Internet.

Method of dividing IP and Subnet mask

READ MORE  Dan Tri In Social Development

Give the address Determine the network address, broadcast address, address range that can be used for the host?

Calculation method

Prefix length = 27, so the corresponding subnet mask is 11111111 11111111 11111111 11100000 – from which we determine the number of bits of the net-id part of the IP address.

IP =, the corresponding binary form is: 11000000 10101000 10011011 11110101

Keep the net-id part, the host-id part set to all bits 0: 11000000 10101000 10011011 11100000

We get the network address, rewritten in decimal form will be:

With Broadcast address, host-id will be set to full bit 1: 11000000 10101000 10011011 11111111

We get the Broadcast address, rewritten in decimal will be:

Since network addresses and broadcast addresses are not used for hosts, the range of addresses that can be used here is from to

For the network 24. Divide this network into subnets for the following departments: Room A: 80 computers, Room B: 60 computers, 2 rooms C, D: 25 computers each.

Calculation method

First we have the IP address and the net-id part: 11000000 10101000 10011011 00000000 minus the network and broadcast addresses, this network has a maximum of 254 machines.

We borrow part of the host-id and convert it to net-id, and get 2 subnets as follows:

11000000 10101000 10011011 00000000 or 11000000 10101000 10011011 10000000 or

We see, network has 7 bits of host-id part, representing 127 machines, enough for room A, so we assign this network to room A.

With the address, we borrowed a part of the host-id to convert to net-id, and got 2 subnets as follows:

11000000 10101000 10011011 10000000 or 11000000 10101000 10011011 11000000 or

Continuing, the network has 6 bits of host-id part, representing 63 machines, so we assign this network to room B.

See also: What is Psychology – Meaning of the word Psychology

Do the same with network, get 2 subnets:

11000000 10101000 10011011 11000000 or 11000000 10101000 10011011 11100000 or 192.168.155,224/27

These 2 subnets have 5 bits of host-id part, representing 31 machines, we assign them to rooms C and D respectively.

Thus, we have divided the network into subnets of different sizes, in accordance with the requirements of the problem:

Room A: Room B: Room C: Room D:

The article is taken from the source http://www.stdio.vn/articles/read/122-so-luoc-ve-dia-chi-ip

riclix.com is published by Duong Vi Phat. Using Jekyll and Cayman theme.