Preface
This document is simply a logical algorithm, and how to compute network bits, host bits, and broadcast addresses in the case of known IP addresses and subnet masks. All steps are far from the most primitive binary way, the direct hit principle, please read carefully.
1. Logic algorithm
Logic and operations and logic or operations are used when computing network bits, host addresses, broadcast addresses, so it is necessary to understand their algorithms. Detailed chapters please Baidu, here only to do a brief introduction.
&& is the logic and operator, | | is a logical OR operator
Logic and operations: when two binary numbers 1 and 0 do the logic and the operation, All is true (1) that is the result is true (1), one is false that is all false (0)
Logic or operation: When two binary numbers 1 and 0 do the logic or operation, all are false (0) i.e. the result is False (0), a true is all true (1)
2, known IP and subnet mask, for network bit, host bit, broadcast address:
I P Address: 121.40.81.200
Subnet Mask: 255.255.252.0
2.1. First convert IP address and subnet mask to binary
I P Address: 121.40.81.200 convert binary 01111001.00101000.01010001.11001000
Subnet mask: 255.255.252.0 convert binary 11111111.11111111.11111100.00000000
2.2. Ask for network bit
Binary IP address and binary subnet mask for "logic and operations" to derive network bit
Binary I P Address: 01111001.00101000.01010001.11001000
Binary Subnet Mask: 11111111.11111111.11111100.00000000
The result after the logic and operation is: 01111001.00101000.01010000.00000000
Convert result to decimal: 121.40.80.0
Network bit is: 121.40.80.0
2.3. Request the address of the broadcast
Invert the subnet mask and binary IP address to make a "logic or operation" to derive the broadcast address
Invert front subnet mask: 11111111.11111111.11111100.00000000
Subnet mask after inversion: 00000000.00000000.00000011.11111111 (must invert mask when calculating broadcast address)
Binary I P Address: 01111001.00101000.01010001.11001000
The result after the logical OR operation is: 01111001.00101000.01010011.11111111
Convert result to decimal: 192.168.83.255
Broadcast address is: 192.168.83.255
2.4. Request the host bit
Invert front subnet mask: 11111111.11111111.11111100.00000000
Inverted subnet Mask: 00000000.00000000.00000011.11111111 (The inverted subnet mask is the host bit)
Remove the excess 0:11,111,111
Converted to 10 binary: 1023 + 1 (because both binary and IP are calculated from 0, 0 is also counted as an IP, so + 1)
Host bit is: 1024, this IP segment can accommodate 1024 hosts
2.5. Final Result
I P Address: 121.40.81.200 binary IP Address: 01111001.00101000.01010001.11001000
Subnet mask: 255.255.252.0 binary subnet Mask: 11111111.11111111.11111100.00000000
Network bit is: 121.40.80.0 binary network bit: 01111001.00101000.01010000.00000000
Broadcast address: 121.40.83.255 binary broadcast address: 01111001.00101000.01010011.11111111
Host bit is: 0.0.3.255 two system host bit: 00000000.00000000.00000011.11111111 (can accommodate 1023+1 host)
Its network segment: 121.40.80.0 to 121.40.83.255
Appendix
3. What is the IP address?
The IP address is English: an abbreviation for the Internet Protocol address, meaning "the interconnection between networks", which is the protocol designed to communicate with each other in connection with the computer network. The IP address is a 32-bit binary number, which is typically divided into 4 "8-bit binary" (that is, 4 bytes), but in everyday applications it is converted to 10 notation.
Example: 100.4.5.6, which is actually a 32-bit binary number (01100100.00000100.00000101.00000110).
4. What is a subnet mask?
The Subnet mask (English: subnet mask abbreviation) is also called netmask, address mask, subnet mask. The subnet mask cannot exist alone, it must be used in conjunction with an IP address. The subnet mask has only one function, which is to divide an IP address into two parts: network address and host address. If you do not specify, you do not know which bits are the network number, which are the host number, and the broadcast address. As with the binary IP address, the subnet mask consists of 1 and 0, and 1 and 0 are contiguous respectively. The length of the subnet mask is also 32 bits, the left is the network bit, with the binary number "1", the number of 1 is equal to the length of the network bit, the right is the host bit, with the binary number "0" means that the number of 0 equals the length of the host bit.
Example: 255.255.252.0 is actually a 32-bit binary number (11111111.11111111.11111100.00000000)
5. What is the network segment?
Network segment, is a section of the net. Network segment generally refers to a computer network using the same physical layer device direct communication (ARP) of those IP collectively referred to as the network segment. Example: 192.168.1.118/255.255.255.0 its network segment is 192.168.1.0-192.168.1.255, the network segment of the IP direct communication (through ARP communication), do not need to forward the gateway.
6. What is the broadcast address?
Broadcast addresses (broadcast address) are an address that is designed to be sent to all workstations in the network at the same time. In a network that uses the TCP/IP protocol, the host ID segment has a full 1 IP address as the broadcast address, and the broadcast packet is routed to all computers involved in the host ID segment. For example, for a 10.1.1.0 (255.255.255.0) segment, its broadcast address is 10.1.1.255 (255 is 2 binary 11111111), and when a packet (packet) with a destination address of 10.1.1.255 is emitted, It will be distributed to all computers on that network segment.
7, the host bit (number) and network bit (number) is what?
The host bit is the inverse of the subnet mask or subnet mask. Composed of 1 and 0, the length of the subnet mask is also 32 bits, the left is the network bit, with the binary number "1", the number of 1 equals the length of the network bit, the right is the host bit, with the binary number "0", the number of 0 equals the length of the host bit.
This article is from the "Operations Development" blog, please be sure to keep this source http://linuxserver.blog.51cto.com/1854325/1602542
Known IP, subnet mask, seek network bit, host bit, broadcast address