IPv4 addressing

17 minuti

Every device that speaks IP (Internet Protocol) needs a unique address, and most of today’s traffic still uses IPv4 (IP version 4). The exam expects you to know what an IPv4 address is made of, how the subnet mask splits it into network and host portions, and how to find the network address, broadcast address, and usable host range — fast. CompTIA’s summary names public vs. private addressing, APIPA, RFC 1918, loopback, subnetting (VLSM, CIDR), and address classes (A–E); the IPv6 addressing video (objective 1.8) closes the topic as its own section below. These notes follow Prof. Messer’s Network+ N10-009 videos: “Binary Math”, “IPv4 Addressing”, “Classful Subnetting”, “IPv4 Subnet Masks”, “Calculating IPv4 Subnets and Hosts”, “Magic Number Subnetting”, and “Seven Second Subnetting” (1.7), and “IPv6 Addressing” (1.8).

⏱ Video — Binary Math (9:05): 0:03 why binary math · 0:41 bits, bytes, and octets · 0:55 the conversion chart · 1:51 binary to decimal · 4:20 decimal to binary · 7:41 eight bits, zero to 255 · 8:01 more bits, more values · 8:43 powers of two ⏱ Video — IPv4 Addressing (10:56): 0:03 the ipv4 address · 0:43 subnet mask · 1:17 default gateway · 1:58 loopback addresses · 2:39 reserved addresses · 3:12 virtual ip addresses · 4:02 octets and 32 bits · 5:21 dhcp · 5:52 apipa link-local addresses · 7:17 ipv4 exhaustion · 7:48 private addresses and nat · 8:47 rfc 1918 ranges ⏱ Video — Classful Subnetting (10:48): 0:04 address classes · 0:33 default masks per class · 0:52 unused since 1993 · 1:35 network vs host bits · 1:54 the class table · 2:23 identifying the class · 4:57 four key subnet values · 6:09 worked example class a · 7:58 worked example class b · 9:16 worked example class c ⏱ Video — IPv4 Subnet Masks (8:51): 0:15 classless subnetting · 0:40 cidr block notation · 1:34 device notation differences · 2:05 contiguous ones · 2:27 counting the ones · 4:14 worked conversions · 5:05 the decimal mask chart · 6:15 decimal examples · 7:26 reverse conversion · 8:10 the /26 and /20 ⏱ Video — Calculating IPv4 Subnets and Hosts (9:36): 0:34 why we subnet · 1:11 variable-length subnet masks · 1:51 the pizza analogy · 2:07 a class a default · 3:53 borrowing bits · 4:30 powers of two · 4:42 subnet and host formulas · 5:17 example 10.1.1.0/24 · 6:36 example 192.168.11.0/26 · 8:00 example 172.16.55.0/21 · 9:23 faster shortcuts ⏱ Video — Magic Number Subnetting (21:01): 0:38 the 40-device scenario · 1:22 trying the masks · 2:34 the optimal /26 · 2:47 the powers-of-two check · 4:18 four key values · 5:33 the magic number method · 5:52 cidr-to-decimal chart · 6:51 the interesting octet · 7:45 host range chart · 8:18 the steps · 9:07 example one · 12:12 broadcast by magic number · 14:00 first and last hosts · 14:52 example two · 18:33 example three ⏱ Video — Seven Second Subnetting (16:54): 0:01 recap · 0:45 no calculations required · 1:02 only plus and minus one · 1:23 whiteboard friendly · 1:34 splitting the network · 1:59 build the table · 2:21 networks and addresses columns · 3:04 block boundaries · 3:38 the four steps · 4:32 example /24 · 7:05 example /26 · 9:42 example /20 · 12:25 example /11 · 14:24 example /17 · 16:17 exam tips ⏱ Video — IPv6 Addressing (13:41): 0:05 billions of devices · 0:20 ipv4 exhaustion · 0:25 nat as a stopgap · 1:34 ipv6 128-bit addressing · 2:16 the ipv6 format · 3:06 16-bit sections · 3:37 compression rules · 4:17 compression example one · 5:36 compression example two · 6:34 bridging the gap · 8:18 tunneling 6to4 · 9:05 4in6 tunneling · 9:32 dual stack · 11:07 nat64 and dns64 · 12:05 nat64 walkthrough

Binary math

Subnetting is mostly converting between decimal and binary, so the video builds the fundamentals first.

  • Binary uses two numbers, 0 or 1. Each 0 or 1 is a bit; eight bits together are a byte, also called an octet to be clear it is an 8-bit byte.
  • The conversion chart starts at 1 on the right and doubles leftward: 1, 2, 4, 8, 16, 32, 64, 128 — and it keeps going (256, 512, …) for larger numbers.
  • Binary to decimal: bring down the chart value under every 1 (a 0 contributes nothing), then add up the bottom row.
  • Decimal to binary: walk the chart left to right, asking “is the running total plus this column less than or equal to the target?” — 1 means yes, 0 means no. Only one combination of 0s and 1s equals any decimal value.
chart:       128  64  32  16   8   4   2   1
 
00000010  →  128·0 + 2 = 2            →   2
10000010  →  128 + 2                  → 130
11111111  →  128+64+32+16+8+4+2+1     → 255
 
154 in binary:
  128 ≤ 154? yes → 1   (128)
   64: 192 ≤ 154? no  → 0
   32: 160 ≤ 154? no  → 0
   16: 144 ≤ 154? yes → 1   (144)
    8: 152 ≤ 154? yes → 1   (152)
    4: 156 ≤ 154? no  → 0
    2: 154 ≤ 154? yes → 1   (154)
    1: already there  → 0
                                → 10011010
  • Eight bits convert any number between 0 and 255. More bits mean more possible values: 2 bits → 4 outcomes (00, 01, 10, 11 = 0–3), 3 bits → 8, 4 bits → 16, 5 bits → 32, 6 bits → 64, 7 bits → 128. These are the powers of two: 2⁰ = 1, 2¹ = 2, 2² = 4, 2³ = 8, …

IPv4 addressing

  • The IP address is the unique identifier every device needs to communicate with IP — a series of four numbers separated by periods, e.g. 192.168.1.165. Combined with the subnet mask (also four octets, e.g. 255.255.255.0) it tells the device which IP subnet it is on. The mask is not transmitted on the network; the local device uses it to decide what is local and what is outside the subnet.
  • The default gateway is the IP address of a device on the local subnet (assigned to the router by the administrator, e.g. 192.168.1.1) that lets you communicate outside the subnet. It must be an address on your local network.
  • Loopback: every device has one — the range 127.0.0.1 through 127.255.255.254. Pinging 127.0.0.1 confirms your local IP stack works properly before you worry about other devices.
  • Reserved addresses are never assigned to devices — kept for future use or testing: the video gives 240.0.0.1 through 254.255.255.254, and anything that is a class E address is also reserved (classes below).
  • A VIP (virtual IP address) is not associated with a physical Ethernet adapter; it is assigned to the internals of a device — a virtual machine, or an internal address associated with a router — so you can always reference that device by it.
  • IPv4 and the IP protocol operate at OSI (Open Systems Interconnection) layer 3.
  • An address like 192.168.1.131 is four octets of 8 bits each: 32 bits total = 4 bytes; the maximum decimal value per octet is 255.

Configuration:

  • DHCP (Dynamic Host Configuration Protocol): plug into a wired or wireless network and automatically receive all your IP configuration settings. Early networks required manual configuration of address, mask, and gateway on every device.
  • With no DHCP server you may still get an automatic address — a link-local address, usable only on the local subnet and not routable (no internet). In IPv4 this is APIPA (Automatic Private IP Addressing): the range 169.254.0.1 through 169.254.255.254, with the first and last 256 addresses reserved, so usable assignments run 169.254.1.0 through 169.254.254.255. APIPA uses ARP (Address Resolution Protocol) to confirm nobody else on the local network has the address, then assigns a random number from the block.
  • IPv4 exhaustion: there are far more devices than IPv4 addresses and the assignable blocks are used up. One extension is private IP address ranges — usable only inside a network, never routed on the public internet. Your device almost certainly uses one right now; you reach the internet through NAT (Network Address Translation), which converts the private address to a public one.
  • RFC (Request for Comments) 1918 defines the private ranges:
RangeSize (video)CIDRMaskHost bits
10.0.0.0 – 10.255.255.255over 16 million (one class A block)10.0.0.0/8255.0.0.024
172.16.0.0 – 172.31.255.255just over 1 million (16 class B ranges)172.16.0.0/12255.240.0.020
192.168.0.0 – 192.168.255.255over 65,000 (256 class C ranges)192.168.0.0/16255.255.0.016

Classful subnetting

  • Address classes describe an IP address relative to its subnet mask. Class A: 8 bits network, 24 bits host, mask 255.0.0.0. Class B: 16 and 16, mask 255.255.0.0. Class C: 24 and 8, mask 255.255.255.0.
  • Class-based subnetting has not been used since 1993 — people still say “class A address” colloquially — but the classes remain the starting point for any subnetting because the network/host demarcation is obvious (after the first 8, 16, or 24 bits).
  • You identify the class from the first octet (or the leading bits in binary):
ClassFirst octetLeading bitsRoleDefault mask
A0 – 1270…assigned to devices255.0.0.0
B128 – 19110…assigned to devices255.255.0.0
C192 – 223110…assigned to devices255.255.255.0
D224 – 2391110…multicast — not an individual device—
E240 – 2551111…reserved—
  • Quick checks: 17.22.90.7 → A; 220.10.77.40 → C; 165.245.0.1 → B; 128.90.10.2 → B; 191.77.24.250 → B; 192.1.12.5 → C.
  • Four values matter for every subnet: the network address (set all host bits to 0), the first usable host (network + 1), the broadcast address (set all host bits to 1, i.e. 255), and the last usable host (broadcast − 1). The same process works for any address and mask.
10.74.222.11 — class A, mask 255.0.0.0
  network:   10.0.0.0        first host: 10.0.0.1
  broadcast: 10.255.255.255  last host:  10.255.255.254
 
172.16.88.200 — class B, mask 255.255.0.0
  network:   172.16.0.0        first host: 172.16.0.1
  broadcast: 172.16.255.255    last host:  172.16.255.254
 
192.168.4.77 — class C, mask 255.255.255.0
  network:   192.168.4.0       first host: 192.168.4.1
  broadcast: 192.168.4.255     last host:  192.168.4.254

IPv4 subnet masks

  • Since 1993 we use classless subnetting — CIDR (Classless Inter-Domain Routing). The mask need not fit a class; instead of writing it in decimal we can give the number of mask bits: 255.0.0.0 is a /8. An address is written like 192.168.1.44/24, where the /24 means a 24-bit mask = 255.255.255.0.
  • Operating systems (e.g. Windows) usually expect the decimal mask; routers and switches often expect CIDR notation — check the device documentation.
  • A subnet mask is a contiguous run of 1s followed by 0s. Count the 1s to get the CIDR value: 24 ones = /24 — 24 network bits, 8 host bits.
  • Conversions in the video: /16 (8+8 ones) = 255.255.0.0 (16 network, 16 host bits); /26 (8+8+8+2) = 255.255.255.192 (26 network, 6 host); /12 (8+4) = 255.240.0.0 (12 network, 20 host); /19 (8+8+3) = 255.255.224.0 (19 network, 13 host); /20 = 255.255.240.0 (20 network, 12 host).
  • Each octet’s decimal value depends only on how many leading 1s it holds:
1-bits in the octet012345678
Decimal value0128192224240248252254255

Calculating subnets and hosts

  • Why subnet at all? No single device could know where every other device in the world is. Instead we build smaller networks and routers move information between them.
  • VLSM (Variable-Length Subnet Masks) lets the mask have any number of bits — unlike the fixed class masks — so you build a network of exactly the right size. Like cutting a pizza: into two pieces, four, eight, or more. A class A 10.0.0.0/8 can be cut into /24s or /26s.
  • Borrowing: with a class A default of 255.0.0.0 (/8), draw the line after the third octet — you keep the first 8 network bits, borrow the middle 16 bits as subnet bits, and shrink the host section to 8 bits. The mask becomes 255.255.255.0, a /24.
  • Formulas with powers of two: number of subnets = 2^(subnet bits), hosts per subnet = 2^(host bits) − 2 — the two subtracted addresses are the network address and the broadcast address.
10.1.1.0/24     class A: 8 network + 16 subnet + 8 host
  subnets = 2^16 = 65,536
  hosts   = 2^8 − 2 = 254
 
192.168.11.0/26 class C: 24 network + 2 subnet + 6 host
  subnets = 2^2 = 4
  hosts   = 2^6 − 2 = 62
 
172.16.55.0/21  class B: 16 network + 5 subnet + 11 host
  subnets = 2^5 = 32
  hosts   = 2^11 − 2 = 2,046

Magic number subnetting

  • Scenario: you are given 192.168.1.0/24 and need more than one network with 40 devices per subnet. Borrowing bits one at a time: /24 = 1 network, 254 hosts; /25 (255.255.255.128) = 2 networks, 126 hosts; /26 (255.255.255.192) = 4 networks, 62 hosts — fits 40 devices; /27 (255.255.255.224) = 8 networks but only 30 hosts. The optimal mask is the /26. The powers-of-two check: 2² = 4 subnets, 2⁶ − 2 = 62 hosts.
  • Every subnet calculation wants the same four values: network address (subnet ID), broadcast address, first available host, last available host. Binary conversion gets all four — slowly. The magic number method does it with only simple addition and subtraction, usually in your head.
  • The steps: (1) convert the mask to decimal if needed; (2) find the interesting octet — the one whose mask is neither 0 nor 255; (3) the magic number = 256 − the interesting octet’s mask value; (4) list the host range in blocks of the magic number; (5) the subnet ID is the first number of the block containing the IP’s interesting octet; (6) the broadcast address is the last number of that block (subnet ID + magic − 1). Mask 255 → copy the IP value straight down; mask 0 → write 0 for the subnet ID (255 for the broadcast row).
  • Handy charts: CIDR ↔ decimal (octet 2 is the interesting octet for /9–/16, octet 3 for /17–/24, octet 4 for /25–/30; /31 leaves no host room and /32 no host bits, so neither is used by default) and block boundaries (a 128-block splits 0–127 / 128–255, a 64-block runs 0–63, 64–127, …).
example 1 — 165.245.77.14, mask 255.255.240.0
  interesting octet: 3 (240)   magic = 256 − 240 = 16
  subnet ID:   165.245. 64. 0    (77 is in block 64–79)
  broadcast:   165.245. 79.255   (64 + 16 − 1 = 79)
  first host:  165.245. 64. 1
  last host:   165.245. 79.254
 
example 2 — 10.180.122.244, mask 255.248.0.0
  interesting octet: 2 (248)   magic = 256 − 248 = 8
  subnet ID:   10.176.  0.  0    (180 is in block 176–183)
  broadcast:   10.183.255.255   (176 + 8 − 1 = 183)
  first host:  10.176.  0.  1
  last host:   10.183.255.254
 
example 3 — 172.16.242.133/27, mask 255.255.255.224
  interesting octet: 4 (224)   magic = 256 − 224 = 32
  subnet ID:   172.16.242.128   (133 is in block 128–159)
  broadcast:   172.16.242.159   (128 + 32 − 1 = 159)
  first host:  172.16.242.129
  last host:   172.16.242.158

Seven second subnetting

  • Seven second subnetting is the shortcut the video’s author uses on the exam. It has the same structure as the magic number method, but no calculations at all — everything is pre-determined in a table you write out beforehand. The only arithmetic is +1 and −1 for the first and last usable addresses.
  • Subnetting is just splitting a network into smaller pieces: a 256-host block cut with .128 gives two subnets, .192 gives four, .224 gives eight, and so on.
  • The table to memorize (or write on the whiteboard): a CIDR ↔ decimal subnet mask column, a networks column (start at 2, double up to 256), and an addresses column (start at 128, halve down to 1). For speed, note the block boundaries too — 128-address blocks start at 0 and 128; 64-address blocks at 0, 64, 128, 192; likewise 32, 16, 8, and 4.
Addresses per subnetBlock boundaries
1280, 128
640, 64, 128, 192
320, 32, 64, 96, 128, 160, 192, 224
160, 16, 32, … 240
80, 8, 16, … 248
40, 4, 8, … 252
  • Four steps: (1) convert the IP and mask to decimal (use the table if given CIDR); (2) network address — mask 255 copies the IP value down, mask 0 brings down 0, and the block start of the interesting octet; (3) broadcast — 255 copies down, 0 becomes 255, and the interesting octet is the last number of its block (next block start − 1); (4) first usable = network + 1, last usable = broadcast − 1.
165.245.12.88/24  → mask 255.255.255.0
  network   165.245.12.0     first 165.245.12.1
  broadcast 165.245.12.255   last  165.245.12.254
 
165.245.12.88/26  → mask 255.255.255.192, 64-address blocks
  88 sits in block 64–127
  network   165.245.12.64    first 165.245.12.65
  broadcast 165.245.12.127   last  165.245.12.126
 
165.245.12.88/20  → mask 255.255.240.0, 16-address blocks
  octet 3: 12 sits in block 0–15
  network   165.245. 0. 0    first 165.245. 0. 1
  broadcast 165.245.15.255   last  165.245.15.254
 
18.172.200.77/11  → mask 255.224.0.0, 32-address blocks
  octet 2: 172 sits in block 160–191
  network    18.160. 0. 0    first  18.160. 0. 1
  broadcast  18.191.255.255  last   18.191.255.254
 
18.172.200.77/17  → mask 255.255.128.0, 128-address blocks
  octet 3: 200 sits in block 128–255
  network   18.172.128. 0    first 18.172.128. 1
  broadcast 18.172.255.255   last  18.172.255.254
  • Exam tips: practice writing the table — in Notepad/WordPad if you test online, or on the whiteboard at a testing center (their dry-erase markers may not make a readable table; check whether you may bring your own fine-tip pen). Whether your shortcut is seven second subnetting, the magic number method, or something else, find the one that suits you and use it.

IPv6 addressing

  • Current estimates put some 20 billion devices on the internet, while IPv4 supports only 4.29 billion addresses — and there are no more IPv4 addresses to assign. NAT keeps things working (hundreds or thousands of devices behind a minimal number of public addresses), but some applications prefer not to use NAT, adding complexity.
  • IPv6 (IP version 6) is the solution: a 128-bit address versus IPv4’s 32 bits. The space is so large that every grain of sand on earth could have 45 quintillion unique IPv6 addresses.
  • Format: hexadecimal values separated by colons — e.g. fe80::5d18:652:6ffd:8f52. Each colon-separated section is 16 bits (2 bytes, 2 octets), so the full address is 128 bits = 16 bytes.
  • Compression rules: a run of all-zero groups can be replaced with a double colon (::) — only once per address — and leading zeros in each group are removed.
2600:dddd:1111:0000:0000:0000:0000:0001
  drop leading zeros, collapse the zero run (once):
2600:dddd:1111::1
 
2601:04c3:4002:be00:0000:0000:0000:0066
  drop leading zeros, collapse the zero run:
2601:4c3:4002:be00::66
  • IPv4 and IPv6 cannot communicate directly, so bridging methods exist (all stopgaps — the long-term answer is moving everything to IPv6):
    • Tunneling: carry one protocol inside the other. 6to4 sends IPv6 over an existing IPv4 network (building an IPv6 address from your IPv4 address), but needs a specialized relay router and supports no NAT — removed from all Windows versions and rarely seen today. 4in6 tunnels IPv4 across an IPv6 network.
    • Dual stack: the same system — e.g. one Ethernet adapter — holds both an IPv4 and an IPv6 address. IPv4 applications use the IPv4 address as always; IPv6 applications use the IPv6 address, its own routing table, and fully independent settings. The usual middle ground.
    • Translation: NAT64 translates between IPv4 and IPv6 with a specialized router, paired with DNS64, a specialized DNS server that translates DNS requests between the two.
  • The NAT64/DNS64 flow: an IPv6-only client wants an IPv4-only site (professormesser.com). It sends a DNS request to the DNS64 server, which asks the site’s IPv4 DNS server and builds an IPv6 version of the returned address that points at the NAT64 router. The client thinks it has the site’s IPv6 address; the NAT64 router translates the client’s IPv6 traffic to IPv4 for the web server (and reverses the translation for responses).
IPv6 client → DNS64 server → IPv4 DNS server → A (IPv4) record
IPv6 client ← synthesized IPv6 address (of the NAT64 router)
IPv6 client → NAT64 router (translate) → IPv4 web server

Where attacks live — mental map (beyond the video)

Not from the video — why this matters for security.

  • ARP (which APIPA uses to claim an address) is trust-on-first-use: ARP spoofing/poisoning on the local subnet lets an attacker claim addresses and sit in the middle of local traffic.
  • Knowing the RFC 1918 private ranges is recon 101: an external scan showing 10.x/172.16.x/192.168.x addresses means leaked or misconfigured information — and NAT hides your real host count from the outside.
  • An APIPA address (169.254.x.x) on a workstation is a red flag: the machine found no DHCP server — broken access, or a rogue DHCP server worth hunting.
  • Subnetting skill cuts both ways: attackers map network and broadcast boundaries to aim broadcast abuse (e.g. amplification) or to find where segmentation ends; defenders use the same four values to write ACLs and verify segmentation holds.
  • IPv6 on dual-stack hosts is an easy blind spot: networks managed “IPv4-only” in practice often still run IPv6 on the wire — firewall and monitor both stacks or an attacker will use the one you forgot.