Binary and hexadecimal for networking

Listen to this lesson

Episode 10 · 50:44

This episode is a study companion for CompTIA Network+ N10-009 and is not produced by or endorsed by CompTIA.

Supplementary

Why this matters

Nothing in N10-009 lists binary or hexadecimal as a sub-topic. The exam assumes them and then tests what is built on top: subnetting, masks, IPv6, MAC addresses.

That assumption is where candidates lose marks. People do not fail subnetting questions because they misunderstand networks — they fail because they cannot convert a number quickly enough under a running clock, run out of time, and lose the rest of the paper with it.

This lesson exists to remove that failure mode. It is short, and it is the highest return per minute in the whole course.

The lesson

Why networking uses binary

A subnet mask is not really 255.255.255.0. It is thirty-two bits, twenty-four ones followed by eight zeros, and the dotted decimal is a convenience for humans. The moment a mask is not all-255s-and-0s, the decimal form stops being readable and you have to see the bits.

255.255.255.192 means nothing obvious. 11111111.11111111.11111111.11000000 means "twenty-six network bits", which is the whole answer.

Bits, bytes and octets

A bit is one binary digit, 0 or 1. Eight bits make a byte, and in networking a byte is usually called an octet — an unambiguous word, since "byte" has not always meant exactly eight bits.

An IPv4 address is 32 bits, written as four octets. Each octet is 8 bits, so it holds 0 through 255 — 256 possible values, which is 2^8.

A MAC address is 48 bits, written as twelve hexadecimal digits.

An IPv6 address is 128 bits, written as thirty-two hexadecimal digits.

The powers of two to memorise

Eight numbers. This is the entire arithmetic foundation of the exam:

128, 64, 32, 16, 8, 4, 2, 1

Those are the place values of the eight bits in an octet, most significant first. They sum to 255, which is why an octet's maximum is 255 and not 256 — 256 values counting from zero.

Write them out before the exam starts if scratch paper is allowed. Every conversion below is just this row.

Converting binary to decimal

Write the bits under the place values and add up the ones.

11000000:

128 64 32 16 8 4 2 1
1 1 0 0 0 0 0 0

128 + 64 = 192.

10101100 → 128 + 32 + 8 + 4 = 172. (The first octet of the 172.16 private range.)

Converting decimal to binary

Go the other way: take each place value largest first, and ask "does it fit?" If yes, write 1 and subtract. If no, write 0.

Convert 200:

  • 128 fits → 1, remainder 72
  • 64 fits → 1, remainder 8
  • 32 no → 0
  • 16 no → 0
  • 8 fits → 1, remainder 0
  • 4, 2, 1 → 0, 0, 0

11001000. Check: 128 + 64 + 8 = 200. ✓

The masks, which are the only binary you really need

Subnet masks are always a run of ones then a run of zeros — never mixed. That means there are only nine possible octet values in a mask, and knowing them removes almost all conversion work:

Bits Binary Decimal
0 00000000 0
1 10000000 128
2 11000000 192
3 11100000 224
4 11110000 240
5 11111000 248
6 11111100 252
7 11111110 254
8 11111111 255

Learn this column and most subnetting becomes lookup rather than arithmetic.

Bitwise AND: how a device finds its own network

This is the operation every host performs, and understanding it explains the symptoms of a wrong mask.

AND compares two bits: the result is 1 only if both are 1. A host ANDs its address with its mask, bit by bit, to get its network address.

192.168.1.130 with mask 255.255.255.192, looking only at the last octet:

  130  =  1000 0010
  192  =  1100 0000
  AND  =  1000 0000  =  128

So the host is on network 192.168.1.128. Do the same for the destination. If the results match, the host sends directly; if not, it sends to the gateway.

That is the whole decision. A host with the wrong mask computes a different network for itself and for some destinations, which is why it can reach some hosts on its own LAN and not others — one of the most confusing symptoms in domain 5 until you have seen this operation.

Hexadecimal, and why IPv6 uses it

Hex is base 16, with digits 0–9 then A–F for ten through fifteen.

Its usefulness is exact: one hex digit is exactly four bits. So a 128-bit IPv6 address needs thirty-two hex digits, where decimal would need an unmemorable run of numbers and binary would need 128 characters.

The sixteen values, worth knowing cold:

Hex 0 1 2 3 4 5 6 7 8 9 A B C D E F
Dec 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Converting hex to binary and back

Because one hex digit is four bits, you convert digit by digit — never the whole number at once. Use the place values 8, 4, 2, 1 within each group.

A = 10 = 1010. F = 15 = 1111. 3 = 0011.

So hex A3 = 1010 0011. And binary 1100 1000 = C8, because 1100 is 12 (C) and 1000 is 8.

This is why a MAC address like 00:1A:2B:3C:4D:5E is 48 bits: twelve hex digits, four bits each.

Counting hosts without a calculator

The formula is 2^h − 2, where h is the number of host bits. The powers of two you already memorised give you it directly:

Host bits 2^h Usable
2 4 2
3 8 6
4 16 14
5 32 30
6 64 62
7 128 126
8 256 254

The −2 is the network address and the broadcast address, neither of which can be given to a host.

Shortcuts that are safe, and mistakes that are not

Safe: the block-size trick. Block size = 256 − mask value, and subnets start at multiples of it. That replaces most binary conversion and is covered fully in the subnetting lesson.

Safe: remembering the mask table above rather than deriving it each time.

The common mistakes:

  • Forgetting the −2. A /29 gives 8 addresses and 6 usable.
  • Converting a hex number as a whole instead of digit by digit.
  • Reversing the place values. Writing 128 64 32 16 8 4 2 1 left to right every single time prevents this; it is worth the four seconds.
  • Assuming 172.x is private. Only 172.16 through 172.31. That is a binary boundary — /12 — not a decimal-looking one, which is exactly why it catches people out.

Practise what you just read

1. A subnet mask is written as 255.255.255.192. How many network bits does that represent?

Select one

  1. 24 network bits, since three octets are set
  2. 25 network bits, with one bit in the last octet
  3. 27 network bits, with three bits in the last octet
  4. 26 network bits, with two bits in the last octet
Show answer

D. 192 in binary is 11000000, which is two ones followed by six zeros. Three full octets give 24 bits and the fourth contributes 2, so the mask is /26. Learning the nine possible mask octet values turns most subnetting from arithmetic into lookup.

2. A host is configured with address 192.168.1.130 and mask 255.255.255.192. Which network does it compute for itself?

Select one

  1. 192.168.1.0, because the third octet is unchanged
  2. 192.168.1.128, found by ANDing the address with the mask
  3. 192.168.1.130, because all of the host bits are significant
  4. 192.168.1.192, taken directly from the mask value
Show answer

B. The host ANDs its address with its mask bit by bit. In the last octet 130 is 10000010 and 192 is 11000000, and AND yields 10000000, which is 128. Every host performs this to decide whether a destination is local or must go to the gateway.

3. What is the hexadecimal value A3 expressed in binary?

Select one

  1. 10100010, converting the pair as one number
  2. 11000011, converting the pair as one number
  3. 10100011, converting each digit separately
  4. 01010011, converting each digit separately
Show answer

C. One hex digit is exactly four bits, so you convert digit by digit and never the whole number at once. A is 10, which is 1010, and 3 is 0011, giving 10100011. Converting the pair as a single number is the classic mistake this tests.

5 more questions on this objective are part of the full course.

Practise the full question bank in the exam simulator

Hands-on labs

All hands-on labs