Binary where it helps
On this page
The boundary for /24 falls on a dot. The boundary for /26 does not: it splits the fourth octet inside. Decimal numbers hide that split. You need a way to see individual positions before deciding which belong to the network.
Before you start
Section titled “Before you start”Finish Practice: Understanding IPv4 Addresses. Keep the lab up in its starting state, with modes off. Begin at learner@rootvolt:~$. These address reads change no settings. Answer the password question if it appears.
Eight places, eight values
Section titled “Eight places, eight values”Recall that a bit is a single 0 or 1. Binary is the base-2 way of writing numbers. Each place is worth twice the place to its right. For one octet, the values from left to right are 128, 64, 32, 16, 8, 4, 2 and 1. A 1 includes that place’s value; a 0 leaves it out.
The figure uses 77, laptop’s second octet. Read each bit under its place value. The included values add up to the decimal number below the row.
Predict: what is the largest number eight bits can hold? Work it out from the place values before reading the answer.
Check your answer
Choose every place: 11111111 represents 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255. No place remains for a larger value within eight bits.
From decimal to binary
Section titled “From decimal to binary”Start with 77. Ask whether 128 fits into the amount remaining. It does not, so write 0. The next value, 64, fits: write 1 and subtract it, leaving 13. Neither 32 nor 16 fits into 13, so write two zeros.
Eight fits, leaving 5. Four fits, leaving 1. Two does not fit. One does. Reading those choices from the left gives 01001101. When you finish, check that you have written exactly eight bits and the remainder is 0.
Try the same process slowly before trying to recognize familiar patterns. At each place, compare with the remainder, rather than with the original number.
From binary to decimal
Section titled “From binary to decimal”For 10100000, include 128 and 32. Leave out every other place. Their sum is 160. Start the place values at the left even when the string begins with zero. The zeros hold positions; they do not move the other bits.
Check a conversion by reversing it. If adding gives a different number, line up the eight places again. Writing the place values above the bits makes an error easier to find than looking only at the final answer.
Compare from the left
Section titled “Compare from the left”Compare 01001101 with 01001100. Their first seven bits match; the last differs. Now compare 11000000 with 11100000: the first difference is the third place. A prefix comparison stops after its stated number of bits. Differences after that boundary belong to the host part.
For /26, the first three octets are whole network octets. Only two bits of the fourth octet join them. Compare those two leading bits when the first three octets already match. You do not need to rewrite every earlier octet in binary.
Mistakes to recognize
Section titled “Mistakes to recognize”“I must convert whole addresses.” Only the octet where the prefix ends needs binary. Whole network octets can be compared as decimal numbers; /26 leaves the first three whole.
Good to know
Section titled “Good to know”The next lesson builds masks from octets whose ones all sit on the left, such as 11000000. Recognizing that shape will help you read the boundary between network and host bits.
Try it yourself
Section titled “Try it yourself”Convert these eight decimal values to eight-bit binary: 192, 224, 240, 248, 252, 128, 64, 80. Convert these eight binary values to decimal: 00000001, 00000010, 00000100, 00001000, 00010000, 00100000, 01100000, 10100000. Write your answers first. Then repeat the replay below, read phone’s and web’s last IPv4 octets, convert them, and compare by adding the included place values.
learner@rootvolt:~$ netlab shell phone -- ip -br address[sudo] password for learner: lo UNKNOWN 127.0.0.1/8 ::1/128
eth0@if5 UP 10.77.10.11/24 fe80::77:10ff:fe00:11/64 learner@rootvolt:~$ netlab shell web -- ip -br addresslo UNKNOWN 127.0.0.1/8 ::1/128
eth0@if11 UP 10.77.20.80/24 fe80::77:20ff:fe00:80/64 learner@rootvolt:~$ Steps (9)
- Type
netlab shell phone -- ip -br address - Press Enter
- Output:
[sudo] password for learner: - Type the password (the terminal shows nothing)
- Press Enter
- Output:
lo UNKNOWN 127.0.0.1/8 ::1/128 eth0@if5 UP 10.77.10.11/24 fe80::77:10ff:fe00:11/64 - Type
netlab shell web -- ip -br address - Press Enter
- Output:
lo UNKNOWN 127.0.0.1/8 ::1/128 eth0@if11 UP 10.77.20.80/24 fe80::77:20ff:fe00:80/64
Solution
In order, the first set gives 11000000, 11100000, 11110000, 11111000, 11111100, 10000000, 01000000, 01010000. The second gives 1, 2, 4, 8, 16, 32, 96, 160. Phone has 10.77.10.11/24: 11 becomes 00001011. Web has 10.77.20.80/24: 80 becomes 01010000. Adding gives 8 + 2 + 1 and 64 + 16 respectively.
- Write one bit per place value.
- Subtract to convert to binary; add to return to decimal.
- Compare only the positions selected by the prefix.
Next, Masks and CIDR notation writes the boundary another way.