9/17/08

Subnet Mask ,Netmask and Default Gateway Explained

Subnet(subnetwork) is a part of a network(devices in a LAN or in a building) that shares a common I address.All the devices whose IP addresses have the same prefix belong to the same subnet.For example, all the devices whose IP addresses starts with 192.168.1 would be a part of the same subnet(255.255.255.0).By knowing the subnet you can easily identify whether the devices are in a particular and same network or not.

Subnet Mask - Just like an ip address a subnet mask also consists of 4 parts each of 8 bits(1 byte) which equals 32 bits(4 bytes).For example:-255.0.0.0 is a subnet mask whose binary is 11111111.00000000.00000000.00000000.

Ip addresses of Class A implicitly uses subnet mask 255.0.0.0.
Ip addresses of Class B implicitly uses subnet mask 255.255.0.0 .
Ip addresses of Class C implicitly uses subnet mask 255.255.255.0.

The binary form of a subnet mask must have its leftmost bits set to 1 and rightmost bits set to 0.
Thus,
Case 1 - 00000000.11111111.11111111.00000000 is an invalid subnet mask but 11111111.11111111.11111111.00000000 is a valid subnet mask.
Case 2 - 11111111.00000000.00000000.11111111 is an invalid subnet mask but 11111111.11111111.11111111.00000000 is a valid subnet mask.

Subnet Mask helps you to identify the Netid and the Hostid by demarcating them.

Calculation of netid and hostid of an ip address of Class B by its subnet mask:-


Calculation of netid and hostid of an ip address of Class C by its subnet mask:-


In both of the above calculations , bitwise AND operation occurs between the IP Address and the Subnet Mask.Bitwise AND operation has the following rules :-
0 AND 0 gives the result 0
0 AND 1 gives the result 0
1 AND 0 gives the result 0
1 AND 1 gives the result 1

Example to understand SubnetId
Ip address - 192.168.1.1
Netid - 192.168
Hostid - 1.1
Now Ip address = netid+subnet id+hostid (since subnetid demarcating the netid and hostid)
Therefore,in the above example if subnet id is alocatted a space of 8 bits then the subnet id will be 1.
Thus,
Netid-192.168
Subnetid - 1
Hostid - 1

Subnet Masking prevents the wastage of IP Addresses.

Netmask - It is a 32-bit value used to divide an IP address into its Netid and Hostid by determining the bits reserved by them and hence the Class of the Ip address.In a netmask one bit is reserved for 0 and another for 255 ,by default.


Default Gateway - It is a device(router) on a network through which a device(source point) on one network can access or send data packets to another device(destination point) on a different network.Technically,a default gateway allows the data packets to pass from one local subnet to other subnets.

Note - The default gateway is not your IP address.

Checking your default gateway in windows is simple.Follow these steps :
1.Click the Start menu and then run. (or simply press the windows button with r)
2.In the box write cmd and hit enter.
3.In the command prompt write the command ipconfig and hit enter again.

The Ip address next to the default gateway is the address of your router(i.e.,that address is the default gateway).


To check your default gateway in Linux try these commands:-
  • route -n

  • ip route show

0 comments: