Showing raw Markdown: the renderer could not load.
## Why this matters Open the settings of your home router and you will see numbers like `192.168.1.10`. Look up the details of your Wi-Fi card and you will find something like `00:00:5e:00:53:01`. Pick a colour on a web page and it is written `#FF8800`. These look like secret codes, but they are all the same thing: ordinary numbers written in a way that is easy for a computer to work with. You don't need to be good at maths to read them. You only need one skill: knowing how to count in a different way. In this lesson you learn that skill step by step. Later modules on IP addressing and subnetting build directly on it, so a few minutes of practice here saves a lot of confusion later. ## Learning objectives - Explain what a bit and a byte are and why computers use binary. - Convert numbers between decimal and binary (0 to 255). - Convert numbers between binary and hexadecimal, and recognize hexadecimal in a MAC address. - Read an IPv4 address as four 8-bit numbers. ## Key concepts ### Two states: bits and bytes Think of a light switch. It is either on or off, and there is nothing in between. Inside a computer there are billions of tiny electronic switches, and each one is either carrying a signal or not. Telling "on" from "off" is easy and very reliable, even when the signal is weak or noisy. Telling ten different levels apart would be much harder and would cause mistakes. That is why computers use only two states. We write the two states as the digits `1` (on) and `0` (off). One of these digits is a **bit**, short for *binary digit*. A single bit can only say yes or no, so computers group bits together. A group of 8 bits is a **byte**. How many different values can a byte hold? Each bit has 2 choices, and there are 8 bits, so there are 2 × 2 × 2 × 2 × 2 × 2 × 2 × 2 = **256** different patterns. We use them to count from 0 to 255. (There are 256 values, but the largest is 255, because counting starts at 0.) A number written using only the digits 0 and 1 is called a **binary** number. The numbers you use every day, with digits 0 to 9, are **decimal** numbers. > [!CHECK] > How many different values can one byte (8 bits) hold? > > - [ ] 8 > - [ ] 255 > - [x] 256 > - [ ] 1,024 > > Each of the 8 bits has 2 possible states, so there are 2 to the power of 8 = 256 patterns. They represent the numbers 0 to 255, which is why 255 is the largest value, not the count. ### Place values: how counting really works You already know how to read binary. You just don't know it yet, because it works exactly like decimal. Look at the decimal number 407: | Place value | 100 | 10 | 1 | |---|---|---|---| | Digit | 4 | 0 | 7 | The number means 4 × 100 + 0 × 10 + 7 × 1 = 407. Each column is worth **10 times** the column to its right, because decimal has ten digits (0 to 9). When a column runs out of digits, you carry over to the next one: after 9 comes 10. Binary has only two digits, so each column is worth **2 times** the column to its right. For one byte there are 8 columns: | Place value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 | |---|---|---|---|---|---|---|---|---| Starting from the right you double each time: 1, 2, 4, 8, 16, 32, 64, 128. Learn this row by heart; you will use it constantly. A digit of `1` in a column means "count this column"; a `0` means "skip it". <figure class="diagram" style="--dg-w: 1040px"><svg xmlns="http://www.w3.org/2000/svg" class="dg" viewBox="0 0 1040 340" width="1040" height="340" role="img" aria-labelledby="binhex-place-values-title binhex-place-values-desc" font-family="Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" xml:lang="en"> <title id="binhex-place-values-title">Binary place values for one byte</title> <desc id="binhex-place-values-desc">A byte is eight bits. The columns have place values 128, 64, 32, 16, 8, 4, 2 and 1 from left to right. The example byte is 1 0 1 1 0 0 1 0. The columns holding a 1 are 128, 32, 16 and 2, so they count; the others are skipped. Adding the counted columns gives 128 + 32 + 16 + 2 = 178.</desc> <rect class="dg-bg" x="0.5" y="0.5" width="1039" height="339" rx="16" fill="#ffffff" stroke="#e3e3dd"/> <g class="dg-l1"><path class="dg-stroke" d="M154 38V30H1010V38" stroke="#0369a1" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g> <g class="dg-l1"><rect class="dg-bg-plain" x="518.4" y="18" width="127.2" height="24" rx="12" fill="#ffffff"/><text x="582" y="34.5" font-size="13" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle">1 byte = 8 bits</text></g> <text x="24" y="93" font-size="14" class="dg-text" fill="#17171c" font-weight="700">Place value</text> <text x="24" y="159" font-size="14" class="dg-text" fill="#17171c" font-weight="700">Bit</text> <text x="24" y="225" font-size="14" class="dg-text" fill="#17171c" font-weight="700">Counts?</text> <rect class="dg-card" x="154" y="60" width="100" height="52" rx="10" fill="#f0f0ec" stroke="#cfcfc8"/> <text x="204" y="94" font-size="22" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">128</text> <g class="dg-l1"><rect class="dg-solid" x="154" y="126" width="100" height="52" rx="10" fill="#0369a1"/><text x="204" y="162" font-size="26" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g> <text x="204" y="226" font-size="18" class="dg-ink" fill="#15803d" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">128</text> <rect class="dg-card" x="262" y="60" width="100" height="52" rx="10" fill="#f0f0ec" stroke="#cfcfc8"/> <text x="312" y="94" font-size="22" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">64</text> <rect class="dg-card" x="262" y="126" width="100" height="52" rx="10" fill="#ffffff" stroke="#cfcfc8" stroke-width="1.5"/><text x="312" y="162" font-size="26" class="dg-muted" fill="#5c5c68" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text> <text x="312" y="226" font-size="18" class="dg-muted" fill="#5c5c68" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">-</text> <rect class="dg-card" x="370" y="60" width="100" height="52" rx="10" fill="#f0f0ec" stroke="#cfcfc8"/> <text x="420" y="94" font-size="22" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">32</text> <g class="dg-l1"><rect class="dg-solid" x="370" y="126" width="100" height="52" rx="10" fill="#0369a1"/><text x="420" y="162" font-size="26" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g> <text x="420" y="226" font-size="18" class="dg-ink" fill="#15803d" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">32</text> <rect class="dg-card" x="478" y="60" width="100" height="52" rx="10" fill="#f0f0ec" stroke="#cfcfc8"/> <text x="528" y="94" font-size="22" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">16</text> <g class="dg-l1"><rect class="dg-solid" x="478" y="126" width="100" height="52" rx="10" fill="#0369a1"/><text x="528" y="162" font-size="26" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g> <text x="528" y="226" font-size="18" class="dg-ink" fill="#15803d" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">16</text> <rect class="dg-card" x="586" y="60" width="100" height="52" rx="10" fill="#f0f0ec" stroke="#cfcfc8"/> <text x="636" y="94" font-size="22" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">8</text> <rect class="dg-card" x="586" y="126" width="100" height="52" rx="10" fill="#ffffff" stroke="#cfcfc8" stroke-width="1.5"/><text x="636" y="162" font-size="26" class="dg-muted" fill="#5c5c68" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text> <text x="636" y="226" font-size="18" class="dg-muted" fill="#5c5c68" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">-</text> <rect class="dg-card" x="694" y="60" width="100" height="52" rx="10" fill="#f0f0ec" stroke="#cfcfc8"/> <text x="744" y="94" font-size="22" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">4</text> <rect class="dg-card" x="694" y="126" width="100" height="52" rx="10" fill="#ffffff" stroke="#cfcfc8" stroke-width="1.5"/><text x="744" y="162" font-size="26" class="dg-muted" fill="#5c5c68" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text> <text x="744" y="226" font-size="18" class="dg-muted" fill="#5c5c68" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">-</text> <rect class="dg-card" x="802" y="60" width="100" height="52" rx="10" fill="#f0f0ec" stroke="#cfcfc8"/> <text x="852" y="94" font-size="22" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">2</text> <g class="dg-l1"><rect class="dg-solid" x="802" y="126" width="100" height="52" rx="10" fill="#0369a1"/><text x="852" y="162" font-size="26" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g> <text x="852" y="226" font-size="18" class="dg-ink" fill="#15803d" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">2</text> <rect class="dg-card" x="910" y="60" width="100" height="52" rx="10" fill="#f0f0ec" stroke="#cfcfc8"/> <text x="960" y="94" font-size="22" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text> <rect class="dg-card" x="910" y="126" width="100" height="52" rx="10" fill="#ffffff" stroke="#cfcfc8" stroke-width="1.5"/><text x="960" y="162" font-size="26" class="dg-muted" fill="#5c5c68" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text> <text x="960" y="226" font-size="18" class="dg-muted" fill="#5c5c68" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">-</text> <rect class="dg-panel" x="24" y="252" width="992" height="64" rx="12" fill="#f0f0ec"/> <g class="dg-ok"><g class="dg-icon" transform="translate(42 270) scale(1.1667)" fill="none" stroke="#15803d" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20 6 9 17l-5-5"/></g></g> <text x="84" y="281" font-size="22" class="dg-text" fill="#17171c" font-weight="700" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">128 + 32 + 16 + 2 = 178</text> <text x="84" y="303" font-size="13" class="dg-muted" fill="#5c5c68" font-weight="500">Add the place values of the columns that hold a 1</text> </svg></figure> *Figure 1. To read a binary number, add the place values of the columns that hold a 1.* ### Binary to decimal To turn a binary number into decimal, write it under the place-value row and add up the columns that hold a 1. **Worked example: `00101101`** | Place value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 | |---|---|---|---|---|---|---|---|---| | Bit | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 1 | The columns with a 1 are 32, 8, 4 and 1. Add them: 32 + 8 + 4 + 1 = **45**. So `00101101` is 45 in decimal. Two easy ones to remember: `00000000` is 0 and `11111111` is 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255, the largest value a byte can hold. ### Decimal to binary To go the other way, work through the columns from left to right. At each column ask: "Does this place value fit into what I have left?" If yes, write `1` and subtract it. If no, write `0`. **Worked example: 200** | Step | Place value | Fits into what is left? | Bit | Left after | |---|---|---|---|---| | 1 | 128 | Yes (200 ≥ 128) | 1 | 200 − 128 = 72 | | 2 | 64 | Yes (72 ≥ 64) | 1 | 72 − 64 = 8 | | 3 | 32 | No (8 < 32) | 0 | 8 | | 4 | 16 | No | 0 | 8 | | 5 | 8 | Yes (8 ≥ 8) | 1 | 8 − 8 = 0 | | 6 | 4 | No | 0 | 0 | | 7 | 2 | No | 0 | 0 | | 8 | 1 | No | 0 | 0 | Reading the Bit column from top to bottom gives `11001000`. Check it by going back: 128 + 64 + 8 = 200. Always check; it takes five seconds. > [!TIP] > Always write all 8 bits, adding zeros on the left (`101` becomes `00000101`). In networking, numbers are almost always shown as full bytes. > [!CHECK] > What is `00001010` in decimal? > > - [ ] 5 > - [x] 10 > - [ ] 12 > - [ ] 1010 > > The columns holding a 1 are 8 and 2, and 8 + 2 = 10. The binary digits `1010` do not mean "one thousand and ten"; each digit is worth its column. ### Hexadecimal: a shorter way to write bits Binary is exact, but long: one byte is 8 digits, and a MAC address would be 48 digits. People make mistakes copying that many zeros and ones. **Hexadecimal** (or *hex*) is a shorthand. It has **16** digits instead of 10: the usual 0 to 9, then the letters A to F for the values ten to fifteen. | Hex digit | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F | |---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---| | Value | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | The letters can be upper or lower case: `5E` and `5e` are the same number. Why 16? Because 16 is exactly 2 × 2 × 2 × 2. One hex digit holds exactly **4 bits**, and 4 bits (called a **nibble**) can hold the values 0 to 15. So a byte, which is 8 bits, is always exactly **two hex digits**. To convert a byte from binary to hex, split it into two groups of 4 bits and convert each group on its own, using place values 8, 4, 2, 1: **Worked example: `10110010`** - First group `1011` = 8 + 2 + 1 = 11, which is the hex digit **B**. - Second group `0010` = 2, which is the digit **2**. - The byte is `B2` in hex. To go back, turn each hex digit into 4 bits. `C8` is `C` = 12 = `1100`, and `8` = `1000`, so `C8` is `11001000`: the same 200 as in the last section. <figure class="diagram" style="--dg-w: 1040px"><svg xmlns="http://www.w3.org/2000/svg" class="dg" viewBox="0 0 1040 476" width="1040" height="476" role="img" aria-labelledby="binhex-hex-digits-title binhex-hex-digits-desc" font-family="Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" xml:lang="en"> <title id="binhex-hex-digits-title">One byte is two hexadecimal digits</title> <desc id="binhex-hex-digits-desc">The byte 1 0 1 1 0 0 1 0 is split into two groups of four bits. The first group, 1011, equals 8 + 2 + 1 = 11, which is the hexadecimal digit B. The last group, 0010, equals 2, which is the digit 2. So the byte is B2 in hexadecimal. A strip below lists the sixteen hexadecimal digits with their values: 0 to 9 are 0 to 9, then A is 10, B is 11, C is 12, D is 13, E is 14 and F is 15.</desc> <rect class="dg-bg" x="0.5" y="0.5" width="1039" height="475" rx="16" fill="#ffffff" stroke="#e3e3dd"/> <g class="dg-l1"><rect class="dg-tint" x="92.0" y="64" width="100" height="50" rx="10" fill="#e1edf4" stroke="#81b4d0" stroke-width="1.2"/><text x="142" y="98" font-size="26" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g> <g class="dg-l1"><rect class="dg-tint" x="200.0" y="64" width="100" height="50" rx="10" fill="#e1edf4" stroke="#81b4d0" stroke-width="1.2"/><text x="250" y="98" font-size="26" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g> <g class="dg-l1"><rect class="dg-tint" x="308.0" y="64" width="100" height="50" rx="10" fill="#e1edf4" stroke="#81b4d0" stroke-width="1.2"/><text x="358" y="98" font-size="26" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g> <g class="dg-l1"><rect class="dg-tint" x="416.0" y="64" width="100" height="50" rx="10" fill="#e1edf4" stroke="#81b4d0" stroke-width="1.2"/><text x="466" y="98" font-size="26" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g> <g class="dg-l5"><rect class="dg-tint" x="524.0" y="64" width="100" height="50" rx="10" fill="#f7e3ec" stroke="#de8cae" stroke-width="1.2"/><text x="574" y="98" font-size="26" class="dg-ink" fill="#be185d" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g> <g class="dg-l5"><rect class="dg-tint" x="632.0" y="64" width="100" height="50" rx="10" fill="#f7e3ec" stroke="#de8cae" stroke-width="1.2"/><text x="682" y="98" font-size="26" class="dg-ink" fill="#be185d" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g> <g class="dg-l5"><rect class="dg-tint" x="740.0" y="64" width="100" height="50" rx="10" fill="#f7e3ec" stroke="#de8cae" stroke-width="1.2"/><text x="790" y="98" font-size="26" class="dg-ink" fill="#be185d" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g> <g class="dg-l5"><rect class="dg-tint" x="848.0" y="64" width="100" height="50" rx="10" fill="#f7e3ec" stroke="#de8cae" stroke-width="1.2"/><text x="898" y="98" font-size="26" class="dg-ink" fill="#be185d" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g> <g class="dg-l1"><path class="dg-stroke" d="M92.0 50H516.0" stroke="#0369a1" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g> <g class="dg-l1"><rect class="dg-bg-plain" x="251.32" y="26" width="105.36" height="24" rx="12" fill="#ffffff"/><text x="304" y="42.5" font-size="13" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle">First 4 bits</text></g> <g class="dg-l5"><path class="dg-stroke" d="M524.0 50H948.0" stroke="#be185d" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g> <g class="dg-l5"><rect class="dg-bg-plain" x="686.96" y="26" width="98.08" height="24" rx="12" fill="#ffffff"/><text x="736" y="42.5" font-size="13" class="dg-ink" fill="#be185d" font-weight="600" text-anchor="middle">Last 4 bits</text></g> <g class="dg-l1"><path class="dg-stroke" d="M304.0 122V160" stroke="#0369a1" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g> <g class="dg-l1"><path class="dg-stroke" d="M298 155l6 8 6-8" stroke="#0369a1" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g> <g class="dg-l1"><rect class="dg-solid" x="264.0" y="172" width="80" height="72" rx="12" fill="#0369a1"/><text x="304" y="224" font-size="44" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">B</text></g> <text x="304" y="268" font-size="15" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1011 = 8 + 2 + 1 = 11 = B</text> <g class="dg-l5"><path class="dg-stroke" d="M736.0 122V160" stroke="#be185d" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g> <g class="dg-l5"><path class="dg-stroke" d="M730 155l6 8 6-8" stroke="#be185d" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g> <g class="dg-l5"><rect class="dg-solid" x="696.0" y="172" width="80" height="72" rx="12" fill="#be185d"/><text x="736" y="224" font-size="44" class="dg-on" fill="#ffffff" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">2</text></g> <text x="736" y="268" font-size="15" class="dg-ink" fill="#be185d" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0010 = 2 = 2</text> <text x="520" y="306" font-size="14" class="dg-muted" fill="#5c5c68" font-weight="600" text-anchor="middle">The byte 10110010 written in hexadecimal is B2</text> <rect class="dg-panel" x="24" y="328" width="992" height="124" rx="12" fill="#f0f0ec"/> <text x="44" y="354" font-size="11" class="dg-muted" fill="#5c5c68" font-weight="700" letter-spacing="1.2">THE 16 HEXADECIMAL DIGITS AND THEIR VALUES</text> <g class="dg-l1"><rect class="dg-tint" x="43" y="370" width="54" height="40" rx="8" fill="#e1edf4" stroke="#81b4d0" stroke-width="1.2"/><text x="70" y="397" font-size="22" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text></g> <text x="70" y="432" font-size="14" class="dg-muted" fill="#5c5c68" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">0</text> <g class="dg-l1"><rect class="dg-tint" x="103" y="370" width="54" height="40" rx="8" fill="#e1edf4" stroke="#81b4d0" stroke-width="1.2"/><text x="130" y="397" font-size="22" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g> <text x="130" y="432" font-size="14" class="dg-muted" fill="#5c5c68" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text> <g class="dg-l1"><rect class="dg-tint" x="163" y="370" width="54" height="40" rx="8" fill="#e1edf4" stroke="#81b4d0" stroke-width="1.2"/><text x="190" y="397" font-size="22" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">2</text></g> <text x="190" y="432" font-size="14" class="dg-muted" fill="#5c5c68" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">2</text> <g class="dg-l1"><rect class="dg-tint" x="223" y="370" width="54" height="40" rx="8" fill="#e1edf4" stroke="#81b4d0" stroke-width="1.2"/><text x="250" y="397" font-size="22" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">3</text></g> <text x="250" y="432" font-size="14" class="dg-muted" fill="#5c5c68" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">3</text> <g class="dg-l1"><rect class="dg-tint" x="283" y="370" width="54" height="40" rx="8" fill="#e1edf4" stroke="#81b4d0" stroke-width="1.2"/><text x="310" y="397" font-size="22" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">4</text></g> <text x="310" y="432" font-size="14" class="dg-muted" fill="#5c5c68" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">4</text> <g class="dg-l1"><rect class="dg-tint" x="343" y="370" width="54" height="40" rx="8" fill="#e1edf4" stroke="#81b4d0" stroke-width="1.2"/><text x="370" y="397" font-size="22" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">5</text></g> <text x="370" y="432" font-size="14" class="dg-muted" fill="#5c5c68" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">5</text> <g class="dg-l1"><rect class="dg-tint" x="403" y="370" width="54" height="40" rx="8" fill="#e1edf4" stroke="#81b4d0" stroke-width="1.2"/><text x="430" y="397" font-size="22" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">6</text></g> <text x="430" y="432" font-size="14" class="dg-muted" fill="#5c5c68" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">6</text> <g class="dg-l1"><rect class="dg-tint" x="463" y="370" width="54" height="40" rx="8" fill="#e1edf4" stroke="#81b4d0" stroke-width="1.2"/><text x="490" y="397" font-size="22" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">7</text></g> <text x="490" y="432" font-size="14" class="dg-muted" fill="#5c5c68" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">7</text> <g class="dg-l1"><rect class="dg-tint" x="523" y="370" width="54" height="40" rx="8" fill="#e1edf4" stroke="#81b4d0" stroke-width="1.2"/><text x="550" y="397" font-size="22" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">8</text></g> <text x="550" y="432" font-size="14" class="dg-muted" fill="#5c5c68" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">8</text> <g class="dg-l1"><rect class="dg-tint" x="583" y="370" width="54" height="40" rx="8" fill="#e1edf4" stroke="#81b4d0" stroke-width="1.2"/><text x="610" y="397" font-size="22" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">9</text></g> <text x="610" y="432" font-size="14" class="dg-muted" fill="#5c5c68" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">9</text> <g class="dg-l4"><rect class="dg-tint" x="643" y="370" width="54" height="40" rx="8" fill="#f8e8e2" stroke="#e0a086" stroke-width="1.2"/><text x="670" y="397" font-size="22" class="dg-ink" fill="#c2410c" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">A</text></g> <text x="670" y="432" font-size="14" class="dg-muted" fill="#5c5c68" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">10</text> <g class="dg-l4"><rect class="dg-tint" x="703" y="370" width="54" height="40" rx="8" fill="#f8e8e2" stroke="#e0a086" stroke-width="1.2"/><text x="730" y="397" font-size="22" class="dg-ink" fill="#c2410c" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">B</text></g> <text x="730" y="432" font-size="14" class="dg-muted" fill="#5c5c68" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">11</text> <g class="dg-l4"><rect class="dg-tint" x="763" y="370" width="54" height="40" rx="8" fill="#f8e8e2" stroke="#e0a086" stroke-width="1.2"/><text x="790" y="397" font-size="22" class="dg-ink" fill="#c2410c" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">C</text></g> <text x="790" y="432" font-size="14" class="dg-muted" fill="#5c5c68" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">12</text> <g class="dg-l4"><rect class="dg-tint" x="823" y="370" width="54" height="40" rx="8" fill="#f8e8e2" stroke="#e0a086" stroke-width="1.2"/><text x="850" y="397" font-size="22" class="dg-ink" fill="#c2410c" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">D</text></g> <text x="850" y="432" font-size="14" class="dg-muted" fill="#5c5c68" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">13</text> <g class="dg-l4"><rect class="dg-tint" x="883" y="370" width="54" height="40" rx="8" fill="#f8e8e2" stroke="#e0a086" stroke-width="1.2"/><text x="910" y="397" font-size="22" class="dg-ink" fill="#c2410c" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">E</text></g> <text x="910" y="432" font-size="14" class="dg-muted" fill="#5c5c68" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">14</text> <g class="dg-l4"><rect class="dg-tint" x="943" y="370" width="54" height="40" rx="8" fill="#f8e8e2" stroke="#e0a086" stroke-width="1.2"/><text x="970" y="397" font-size="22" class="dg-ink" fill="#c2410c" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">F</text></g> <text x="970" y="432" font-size="14" class="dg-muted" fill="#5c5c68" font-weight="600" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">15</text> </svg></figure> *Figure 2. One byte is two hex digits: convert each group of 4 bits separately.* > [!NOTE] > Hex numbers are sometimes written with a prefix such as `0x` (`0xB2`) or `#` (`#FF8800`) so you can tell they are hex. The prefix is not part of the number. Some places, like a MAC address, don't use any prefix at all. > [!CHECK] > The byte `11110000` is split into two groups of 4 bits. Which hex number is it? > > - [ ] `0F` > - [x] `F0` > - [ ] `E0` > - [ ] `1F` > > The first group `1111` = 15 = F and the second group `0000` = 0, so the byte is `F0`. Keep the groups in the same order as the bits. ### Where you meet these numbers Now you can read three things that were mysterious before. **An IPv4 address** such as `192.168.1.10` is made of **four bytes**, written in decimal and separated by dots. This style is called *dotted decimal*. Each of the four numbers is one byte, so each is between 0 and 255. That is why `192.168.1.256` can't exist: 256 doesn't fit in a byte. In total an IPv4 address has 4 × 8 = 32 bits. Computers handle the 32 bits; people read the four decimal numbers. **A MAC address** (Media Access Control address) is the hardware address of a network card, used on your local network. It is **six bytes**, each written as two hex digits, usually separated by colons or dashes. The address `00:00:5e:00:53:01` is six bytes: `00`, `00`, `5e`, `00`, `53`, `01`. It is one of the addresses reserved for examples in documentation (RFC 7042), so no real card has it. **A web colour** such as `#FF8800` is **three bytes** in hex: red `FF` (255), green `88` (136) and blue `00` (0). Full red, a bit over half green and no blue gives orange. It is a friendly example because you can type a different hex number and see the colour change. <figure class="diagram" style="--dg-w: 1040px"><svg xmlns="http://www.w3.org/2000/svg" class="dg" viewBox="0 0 1040 412" width="1040" height="412" role="img" aria-labelledby="binhex-where-title binhex-where-desc" font-family="Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" xml:lang="en"> <title id="binhex-where-title">Where you meet bytes: IP addresses, MAC addresses and web colours</title> <desc id="binhex-where-desc">Three rows. An IPv4 address such as 192.168.1.10 is four bytes, each written in decimal from 0 to 255 and separated by dots. A MAC address such as 00:00:5e:00:53:01 is six bytes, each written as two hexadecimal digits and separated by colons. A web colour such as #FF8800 is three bytes in hexadecimal for red, green and blue, which are 255, 136 and 0, with a orange swatch beside it.</desc> <rect class="dg-bg" x="0.5" y="0.5" width="1039" height="411" rx="16" fill="#ffffff" stroke="#e3e3dd"/> <rect class="dg-card" x="24" y="24" width="992" height="112" rx="12" fill="#ffffff" stroke="#cfcfc8"/> <g class="dg-l1"><g class="dg-icon" transform="translate(42 42) scale(1.2500)" fill="none" stroke="#0369a1" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"/><path d="M2 12h20"/></g></g> <g class="dg-l1"><text x="84" y="64" font-size="15" class="dg-ink" fill="#0369a1" font-weight="700">IPv4 address</text></g> <text x="42" y="92" font-size="13" class="dg-muted" fill="#5c5c68" font-weight="500">4 bytes, each written in decimal</text> <text x="42" y="112" font-size="13" class="dg-muted" fill="#5c5c68" font-weight="500">(0 to 255), separated by dots</text> <g class="dg-l1"><rect class="dg-tint" x="548" y="54" width="90" height="50" rx="10" fill="#e1edf4" stroke="#81b4d0" stroke-width="1.2"/><text x="593" y="88" font-size="24" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">192</text></g> <text x="651" y="90" font-size="26" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.</text> <g class="dg-l1"><rect class="dg-tint" x="664" y="54" width="90" height="50" rx="10" fill="#e1edf4" stroke="#81b4d0" stroke-width="1.2"/><text x="709" y="88" font-size="24" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">168</text></g> <text x="767" y="90" font-size="26" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.</text> <g class="dg-l1"><rect class="dg-tint" x="780" y="54" width="90" height="50" rx="10" fill="#e1edf4" stroke="#81b4d0" stroke-width="1.2"/><text x="825" y="88" font-size="24" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1</text></g> <text x="883" y="90" font-size="26" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">.</text> <g class="dg-l1"><rect class="dg-tint" x="896" y="54" width="90" height="50" rx="10" fill="#e1edf4" stroke="#81b4d0" stroke-width="1.2"/><text x="941" y="88" font-size="24" class="dg-ink" fill="#0369a1" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">10</text></g> <rect class="dg-card" x="24" y="150" width="992" height="112" rx="12" fill="#ffffff" stroke="#cfcfc8"/> <g class="dg-l2"><g class="dg-icon" transform="translate(42 168) scale(1.2500)" fill="none" stroke="#15803d" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M12 20h.01"/><path d="M2 8.82a15 15 0 0 1 20 0"/><path d="M5 12.86a10 10 0 0 1 14 0"/><path d="M8.5 16.43a5 5 0 0 1 7 0"/></g></g> <g class="dg-l2"><text x="84" y="190" font-size="15" class="dg-ink" fill="#15803d" font-weight="700">MAC address</text></g> <text x="42" y="218" font-size="13" class="dg-muted" fill="#5c5c68" font-weight="500">6 bytes, each written as two</text> <text x="42" y="238" font-size="13" class="dg-muted" fill="#5c5c68" font-weight="500">hexadecimal digits, separated by colons</text> <g class="dg-l2"><rect class="dg-tint" x="472" y="180" width="64" height="50" rx="10" fill="#e3f0e8" stroke="#8ac09e" stroke-width="1.2"/><text x="504" y="214" font-size="24" class="dg-ink" fill="#15803d" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">00</text></g> <text x="549" y="216" font-size="26" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">:</text> <g class="dg-l2"><rect class="dg-tint" x="562" y="180" width="64" height="50" rx="10" fill="#e3f0e8" stroke="#8ac09e" stroke-width="1.2"/><text x="594" y="214" font-size="24" class="dg-ink" fill="#15803d" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">00</text></g> <text x="639" y="216" font-size="26" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">:</text> <g class="dg-l2"><rect class="dg-tint" x="652" y="180" width="64" height="50" rx="10" fill="#e3f0e8" stroke="#8ac09e" stroke-width="1.2"/><text x="684" y="214" font-size="24" class="dg-ink" fill="#15803d" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">5e</text></g> <text x="729" y="216" font-size="26" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">:</text> <g class="dg-l2"><rect class="dg-tint" x="742" y="180" width="64" height="50" rx="10" fill="#e3f0e8" stroke="#8ac09e" stroke-width="1.2"/><text x="774" y="214" font-size="24" class="dg-ink" fill="#15803d" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">00</text></g> <text x="819" y="216" font-size="26" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">:</text> <g class="dg-l2"><rect class="dg-tint" x="832" y="180" width="64" height="50" rx="10" fill="#e3f0e8" stroke="#8ac09e" stroke-width="1.2"/><text x="864" y="214" font-size="24" class="dg-ink" fill="#15803d" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">53</text></g> <text x="909" y="216" font-size="26" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">:</text> <g class="dg-l2"><rect class="dg-tint" x="922" y="180" width="64" height="50" rx="10" fill="#e3f0e8" stroke="#8ac09e" stroke-width="1.2"/><text x="954" y="214" font-size="24" class="dg-ink" fill="#15803d" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">01</text></g> <rect class="dg-card" x="24" y="276" width="992" height="112" rx="12" fill="#ffffff" stroke="#cfcfc8"/> <g class="dg-l4"><g class="dg-icon" transform="translate(42 294) scale(1.2500)" fill="none" stroke="#c2410c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"/><path d="M14 2v4a2 2 0 0 0 2 2h4"/><path d="M10 9H8"/><path d="M16 13H8"/><path d="M16 17H8"/></g></g> <g class="dg-l4"><text x="84" y="316" font-size="15" class="dg-ink" fill="#c2410c" font-weight="700">Web colour</text></g> <text x="42" y="344" font-size="13" class="dg-muted" fill="#5c5c68" font-weight="500">3 bytes in hexadecimal after a # sign:</text> <text x="42" y="364" font-size="13" class="dg-muted" fill="#5c5c68" font-weight="500">red, green, blue (255, 136, 0)</text> <text x="638" y="339" font-size="30" class="dg-text" fill="#17171c" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">#</text> <g class="dg-l4"><rect class="dg-tint" x="656" y="306" width="90" height="50" rx="10" fill="#f8e8e2" stroke="#e0a086" stroke-width="1.2"/><text x="701" y="340" font-size="24" class="dg-ink" fill="#c2410c" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">FF</text></g> <g class="dg-l4"><rect class="dg-tint" x="756" y="306" width="90" height="50" rx="10" fill="#f8e8e2" stroke="#e0a086" stroke-width="1.2"/><text x="801" y="340" font-size="24" class="dg-ink" fill="#c2410c" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">88</text></g> <g class="dg-l4"><rect class="dg-tint" x="856" y="306" width="90" height="50" rx="10" fill="#f8e8e2" stroke="#e0a086" stroke-width="1.2"/><text x="901" y="340" font-size="24" class="dg-ink" fill="#c2410c" font-weight="700" text-anchor="middle" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">00</text></g> <rect x="960" y="306" width="50" height="50" rx="10" fill="#ff8800" stroke="#cfcfc8"/> </svg></figure> *Figure 3. Different notations, same idea: a few bytes written in a readable way.* > [!CHECK] > Why is `10.20.30.300` not a valid IPv4 address? > > - [ ] Because it has too many dots > - [x] Because 300 is larger than 255, the biggest value of a byte > - [ ] Because addresses can't start with 10 > - [ ] Because IPv4 addresses must be written in hex > > Each of the four numbers is one byte, so it must be between 0 and 255. Dotted decimal is the usual way to write IPv4 addresses. ## How it works Putting it together, here is the whole journey of one address, `192.168.1.10`, from what you read to what the computer stores. 1. You read four decimal numbers: 192, 168, 1 and 10. 2. Each one is a byte. Using the subtraction method: 192 = 128 + 64 = `11000000`; 168 = 128 + 32 + 8 = `10101000`; 1 = `00000001`; 10 = 8 + 2 = `00001010`. 3. The computer stores the four bytes one after the other, as 32 bits: `11000000 10101000 00000001 00001010`. 4. If you wanted a shorter form, you would write each byte in hex: `C0 A8 01 0A`. Nothing changes along the way. It is the same number, written in three different ways. You pick the way that suits the reader: bits for the computer, decimal for IP addresses, hex for compact things like MAC addresses. > [!CHECK] > Which statement is true about `192.168.1.10`, `11000000.10101000.00000001.00001010` and `C0.A8.01.0A`? > > - [ ] They are three different addresses > - [x] They are the same address written in decimal, binary and hex > - [ ] Only the first one can be used on a network > - [ ] The hex form is a different, shorter address > > Decimal, binary and hex are only different notations. The value stored in the computer is the same. ## Worked example Let's convert the address `203.0.113.5`, one of the examples reserved for documentation (RFC 5737). | Decimal | Place values used | Binary | |---|---|---| | 203 | 128 + 64 + 8 + 2 + 1 | `11001011` | | 0 | none | `00000000` | | 113 | 64 + 32 + 16 + 1 | `01110001` | | 5 | 4 + 1 | `00000101` | Check 203: 203 − 128 = 75; 75 − 64 = 11; 11 − 8 = 3; 3 − 2 = 1; 1 − 1 = 0. The bits that fit are 128, 64, 8, 2 and 1, giving `11001011`. The full address in binary is `11001011.00000000.01110001.00000101`. ## Common pitfalls - **Reading binary like a decimal number** — `1010` is not one thousand and ten; it is 10. Always use the columns. - **Forgetting the leading zeros** — `101` and `00000101` are the same number, but in networking you need all 8 bits to keep the columns aligned. - **Mixing up hex letters and values** — `A` to `F` are the values 10 to 15, not 1 to 6. And `10` in hex is 16, not ten. - **Thinking hex is a different number** — `FF` and `255` are the same value. The notation changes, not the number. - **Assuming a number is decimal when it isn't** — `10` can mean ten (decimal), two (binary) or sixteen (hex). The context, or a prefix like `0x`, tells you which. ## Security considerations Binary and hex themselves are not a security topic, but a few habits help. When you copy an IP or MAC address into a firewall rule or an access list, a single wrong digit points the rule at a different device, so double-check by reading it back byte by byte. Also remember that a MAC address is not a secret or a proof of identity: it can be changed in software, so never rely on it alone to decide who is allowed on a network. Finally, hex dumps of data are not encrypted. Writing something in hex or binary only changes how it looks, not who can read it. ## Summary - Computers use two states (on and off), written 1 and 0. One digit is a bit; 8 bits make a byte, which holds 256 values (0 to 255). - Binary columns are worth 128, 64, 32, 16, 8, 4, 2, 1. To convert binary to decimal, add the columns with a 1. To convert decimal to binary, subtract the largest place value that fits, from left to right. - Hexadecimal has 16 digits (0 to 9 and A to F). One hex digit is 4 bits, so one byte is two hex digits. - An IPv4 address is four bytes in decimal, separated by dots. A MAC address is six bytes in hex. A web colour is three bytes in hex. ## Glossary | Term | Definition | |---|---| | bit | A binary digit: a single 0 or 1. The smallest unit of data in a computer. | | byte | A group of 8 bits. It can hold 256 different values, 0 to 255. | | binary | A number system with only two digits, 0 and 1. Each column is worth twice the one to its right. | | decimal | The everyday number system with ten digits, 0 to 9. Each column is worth ten times the one to its right. | | hexadecimal (hex) | A number system with 16 digits, 0 to 9 and A to F. One hex digit stands for 4 bits. | | nibble | A group of 4 bits, which is half a byte and exactly one hex digit. | | MAC address | Media Access Control address: the six-byte hardware address of a network card, written as hex, for example `00:00:5e:00:53:01`. | | dotted decimal | The usual way of writing an IPv4 address: four bytes in decimal separated by dots, for example `192.168.1.10`. | ## Check your understanding 1. Convert 77 to binary, then to hex. Check your binary answer by adding the columns back up. 2. A friend says "`11111111` is a big number, so it doesn't fit in a byte". What is the number, and is your friend right? 3. In the MAC address `00:00:5e:00:53:01`, how many bytes are there, and what is the third byte in decimal? ## References - [RFC 791](https://www.rfc-editor.org/rfc/rfc791): Internet Protocol (where the 32-bit IPv4 address is defined) - [RFC 7042](https://www.rfc-editor.org/rfc/rfc7042): IANA considerations for IEEE 802 parameters (the documentation MAC address range) - [RFC 5737](https://www.rfc-editor.org/rfc/rfc5737): IPv4 address blocks reserved for documentation