In order to find network id (NID) of a Subnet, one must be fully acquainted with the Subnet mask.
It is used to find which IP address belongs to which Subnet. It is a 32 bit number, containing 0’s and 1’s. Here network id part and Subnet ID part is represented by all 1’s and host ID part is represented by all 0’s.
If Network id of a entire network = 188.8.131.52 (it is class C IP). For more about class C IP see Classful Addressing.
In the above diagram entire network is divided into four parts, which means there are four subnets each having two bits for Subnet ID part.
Subnet-1: 184.108.40.206 to 220.127.116.11 Subnet-2: 18.104.22.168 to 22.214.171.124 Subnet-3: 126.96.36.199 to 188.8.131.52 Subnet-4: 184.108.40.206 to 220.127.116.11
The above IP is class C, so it has 24 bits in network id part and 8 bits in host id part but you choose two bits for subnet id from host id part, so now there are two bits in subnet id part and six bits in host id part, i.e.,
24 bits in network id + 2 bits in subnet id = 26 (1's) and 6 bits in host id = 6 (0's)
Subnet Mask = 11111111.11111111.11111111.11000000 = 255.255.255.192
If any given IP address performs bit wise AND operation with the subnet mask, then you get the network id of the subnet to which the given IP belongs.
If IP address = 18.104.22.168 (convert it into binary form) = 11000001.00000001.00000010.10000001 Subnet mask = 11111111.11111111.11111111.11000000 Bit Wise AND = 11000001.00000001.00000010.10000000 Therefore, Nid = 22.214.171.124
Hence, this IP address belongs to subnet:3 which has Nid = 126.96.36.199
If IP address = 188.8.131.52 (convert it into binary form) = 11000001.00000001.00000010.01000011 Subnet Mask = 11111111.11111111.11111111.11000000 Bit Wise AND = 11000001.00000001.00000010.01000000 Therefore, Nid = 184.108.40.206
Hence, this IP address belongs to subnet:2 which has Nid = 220.127.116.11
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
- C Program to find IP Address, Subnet Mask & Default Gateway
- Introduction of Variable Length Subnet Mask (VLSM)
- Role of Subnet Mask
- Fixed Length and Variable Length Subnet Mask Numericals
- IPv4 Classless Subnet equation
- Basic Network Attacks in Computer Network
- Difference between Storage Area Network (SAN) and Network Attached Storage (NAS)
- Differences between Wireless Adhoc Network and Wireless Sensor Network
- Difference between Next Generation Network and Traditional Network
- Difference between Software Defined Network and Traditional Network
- Finding the candidate keys for Sub relations using Functional Dependencies
- Create your own secure Home Network using Pi-hole and Docker
- Setting up a Basic Home Network using Packet Tracer
- Finding IP address of a URL in Java
- Finding DBA from given IP address
- Finding Additional functional dependencies in a relation
- Network Devices (Hub, Repeater, Bridge, Switch, Router, Gateways and Brouter)
- Traceroute in Network Layer
- Types of Network Topology
- Computer Network | Leaky bucket algorithm
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.