- Practice
- About 14 min
- 5 practice questions
IP address problems: validity, classes and binary form
Judge whether an IPv4 address is valid, find its class and whether it is private, and convert between dotted decimal and binary.
If something looks wrong, please tell us.
IP addresses appear in almost every networking paper. The questions are of three kinds: is this address valid, which class or range does it belong to, and what is its binary form. A short checklist answers all three.
Validity
An IPv4 address is four numbers separated by dots, and each number (an octet) is a whole number from 0 to 255 because it is stored in 8 bits. Any octet above 255, any letter, a negative number or a missing part makes the address invalid. Leading and trailing dots also make it invalid. Because there are 32 bits in all, there are 2^32 = 4,294,967,296 possible addresses.
Classes by first octet
| Class | First octet | Default mask | Notes |
|---|---|---|---|
| A | 1 to 126 | 255.0.0.0 | Very large networks |
| B | 128 to 191 | 255.255.0.0 | Medium networks |
| C | 192 to 223 | 255.255.255.0 | Small networks |
| D | 224 to 239 | None | Multicast |
| E | 240 to 255 | None | Reserved for experiments |
The first octet 127 is kept for loopback. The address 127.0.0.1 always refers to the computer itself and is used for testing.
Private ranges
- 10.0.0.0 to 10.255.255.255
- 172.16.0.0 to 172.31.255.255
- 192.168.0.0 to 192.168.255.255
These addresses are used inside homes and offices and are not routed on the public Internet. Notice that 172.16 to 172.31 is private, but 172.32 is not.
Dotted decimal to binary
Convert each octet to 8 bits. The place values in an octet are 128, 64, 32, 16, 8, 4, 2, 1.
Worked examples
Example 1. Convert 192.168.1.10 to binary. 192 = 128 + 64 = 11000000. 168 = 128 + 32 + 8 = 10101000. 1 = 00000001. 10 = 8 + 2 = 00001010. The result is 11000000.10101000.00000001.00001010.
Example 2. Convert 10101100.00010000.00000001.00000001 to dotted decimal. 10101100 = 128 + 32 + 8 + 4 = 172. 00010000 = 16. The last two octets are 1 and 1. The address is 172.16.1.1. It is class B, and it is private because it lies within 172.16 to 172.31.
Example 3. Which of these is valid: 192.168.1.256, 10.0.0.1, 172.16.5, 1.1.1.a? The first has 256, which is above 255. The third has only three parts. The fourth contains a letter. Only 10.0.0.1 is valid; it is class A and private.
Example 4. How many hosts are possible on a class C network by default? The mask 255.255.255.0 leaves 8 host bits, so 2^8 minus 2 = 254 usable hosts. For class B there are 16 host bits: 2^16 minus 2 = 65,534.
Example 5. A user types the address 127.0.0.1 in a browser on the same computer. Which computer answers? The computer itself, because 127.0.0.1 is the loopback address. This is often used by developers and technicians to test whether the network software on a machine is working, without needing any other computer or cable.
Octet 0 to 255. Class by first octet: A 1-126, B 128-191, C 192-223. 127 is loopback.
Key takeaways. Check the four octets, find the class from the first octet and use the private ranges to recognise internal addresses. Convert to binary one octet at a time using the place values 128 to 1.
Check your understanding
-
1. Which of these is a valid IPv4 address?
- 10.0.0.1
- 192.168.1.256
- 172.16.5
- 1.1.1.a
Show answer
Answer: A. Each octet must be 0 to 255 and there must be four parts. Only 10.0.0.1 satisfies both.
-
2. To which class does the address 150.20.4.1 belong?
- Class A
- Class C
- Class B
- Class D
Show answer
Answer: C. The first octet 150 is in the range 128 to 191, so it is class B.
-
3. What is the binary form of the octet 168?
- 10101000
- 10100100
- 11000100
- 10001010
Show answer
Answer: A. 168 = 128 + 32 + 8, which is 10101000.
-
4. Which address is a private address?
- 172.32.0.1
- 192.169.1.1
- 11.1.1.1
- 172.16.5.9
Show answer
Answer: D. The private block 172.16.0.0 to 172.31.255.255 includes 172.16.5.9. The others are public.
-
5. How many usable hosts does a default class C network have?
- 256
- 255
- 254
- 253
Show answer
Answer: C. There are 8 host bits, so 2^8 = 256 addresses, minus the network and broadcast addresses, leaves 254.
Sign in to keep track of the lessons you finish.