Determining Network and Broadcast Address Using IP Address and Subnet Mask | Baeldung on Computer Science
Mục Lục
1. Overview
An IP address is a combination of the host and network address. Along with an IP address, we also need the subnet mask to get the exact network address and different logical addresses from a specific network.
Subnetting is one of the most important methods used by classful IP addressing, and it saves lots of IP addresses from being wasted.
In this tutorial, we’ll discuss IP address, broadcast address, network address, and subnet mask in detail. We’ll also present and explain how to determine network and broadcast addresses using an IP address and a subnet mask with numerical examples.
2. IP Address
The term IP address alludes to the Internet Protocol address. In order to transmit data from one computer to another, we require an address or identification for both devices. However, there’re distinctive ways to communicate, but commonly, computers far from each other communicate using the internet and IP address.
Moreover, it’s an address uniquely assigned to each device connected to the network. Therefore, we use an IP address to identify a specific device in a network for communication. Additionally, it’s also called logical address. There’re two categories of IP addresses: global and local IP addresses.
Global IP addresses are accessible for every device connected to the internet. In contrast, local IP addresses aren’t accessible out of that network. Additionally, the network router can assign it manually or dynamically to a host device.
Now, based on the addressing scheme, we can divide IP addresses into two categories: IPv4 and IPv6. An IPv4 has a bit long address and has octets. Additionally, an IP address can range from to :
In IPv4, there’re two kinds of addressing: classful and classless. Classful IP addressing is divided further into classes: A, B, C, D, and E. Moreover, we can perceive the class of an IP address using the first few bits in binary form notation.
Furthermore, we can divide the IP addresses into classes based on the requirement. Specifically, Class A is designed for substantial organizations. Furthermore, we generally use classes B, C, D, E for mid-size organizations, small organizations, multicasting, and experimental uses:
Furthermore, as we connect more devices to the internet or network, there might be a situation when we don’t have any free unique IP address to assign to new devices. Hence, to overcome this situation, IPv6 is introduced.
IPv6 is the most recent version of the Internet Protocol. Moreover, we express it in hexadecimal format. This newest version was developed by the Internet Engineering Task Force in 1994 to fulfill the exploding needs of Internet users and devices.
Moreover, IPv6 uses a 128-bits addressing scheme and offers many features not present in IPv4. Next, let’s take a look at an IPv6 address:
Some of the features in IPv6 are built-in security, scoped addresses, auto-configuration, Quality of Service (QoS), new header format, and larger address space. Most importantly, most operating systems released since 2000 supports IPv6 either directly or indirectly.
3. Network Address
We know that an IP address combines a network and broadcast address. Therefore, the IP address class determines the network ID, often known as the network address.
In general, we use the first bits of the IP address for the network address in class A. Similarly, we specify the first and bits for the network address in classes B and C.
Moreover, as class A uses bits of IP address for the network address, there can be a maximum of network addresses possible. Similarly, Class B uses bits, but the first bits are always . Hence, we use the remaining bits to assign network addresses. With the remaining bits, there can be network addresses.
Similarly, class C uses bits, but bits are always . Hence, we use the remaining bits to assign network addresses, which means there can be network addresses:
4. Broadcast Address
In any network, when we need to send data to a host device connected to the network, a router uses a broadcast address. Additionally, every network has one unique broadcast address.
The process of sending data to every device or node connected to a network is known as broadcasting. Moreover, there’s only one source in broadcasting, and other host devices are the destinations.
Next, we can simply replace the last bits of a network address by , and that would turn into a broadcast address. Therefore, we can determine the broadcast address of any network using the subnet mask and the IP address of that network.
Let’s take an example. Let’s take a class C IP address: . It’s a network address. Accordingly, the broadcast address for the given network address would be .
5. Subnet Mask
A subnet mask is used in a process known as subnetting, in which a large network is divided into smaller networks. More specifically, it’s like dividing a network into several contiguous network groups, and each group is known as a subnet. Furthermore, this process is implemented to reduce the wastage of IP addresses due to classful addressing.
A subnet mask is used to determine the network address and host address:
6. Determining Network and Broadcast Address
Let’s take an example for calculating network and broadcast addresses using a subnet mask. Now, in order to calculate network and broadcast addresses, we need two pieces of information: the IP address of the device and the subnet mask of the network.
Let’s assume the IP address is and the subnet mask is .
The first step is to write down the IP address and subnet mask in binary:
Bits in the subnet mask which are denotes the network address. Similarly, the bits which are will be used for the broadcast address:
In this example, we can see that the last bits of the subnet mask are . Hence, this means we can connect devices and the broadcast IP address will be . Therefore, the network address will be :
Hence, we can also rewrite the above IP address: . Here, refers to the 28 bits of the subnet mask, which are .
There might be some confusion on how we derive network addresses from a subnet mask. From the above example, it’s clear that bits which are in the subnet represent a network address.
Moreover, the IP address belongs to class C. Hence, we know that in class C, the first bits of the IP address is used for the network address, and the rest is used for the host address. In contrast, there’s a case in subnet mask where network addresses can exceed bits.
In general, the division of the first bits for network and host addresses is the default configuration for the class C IP address. Hence, we can change that by changing the number of in the subnet mask. Moreover, we know that the default subnet mask for class C is .
Therefore, for example, we can change some bits of the subnet mask:
Let’s change a bit of the subnet mask:
Hence, the IP address with this subnet mask will be in a different network. This is the way we can divide a network using the subnet mask. Therefore, now we can rewrite the IP address as .
7. Conclusion
In this tutorial, we discussed IP address, broadcast address, network address, and subnet mask thoroughly. We also presented numerical examples explaining how to determine network and broadcast addresses using an IP address and a subnet mask.