Skip to main content
RunBook Academy

OPNsenseI · Networking Foundations for Firewall AdministratorsLayer 2 and Layer 3 foundations

IPv4 and IPv6 addressing, CIDR and subnets

Foundation⏱ ~16 minipcalcsipcalc

What you'll learn

  • Convert between dotted-quad, hex, and decimal IPv4 representations
  • Apply a CIDR mask and identify the network and host portions
  • Plan IPv6 prefixes and reason about /64 boundaries
  • Use subnet arithmetic to size firewall interfaces

Prerequisites

Verified against OPNsense 25.x · FreeBSD 14.x · PF (FreeBSD packet filter) FreeBSD 14.x · Unbound 1.20+ · Kea DHCP OPNsense 25.x plugin · WireGuard in-kernel + OPNsense plugin · strongSwan (IPsec plugin) OPNsense 25.x plugin · OpenVPN 2.6.x · Suricata 7.x · 2026-08-14

Not yet marked complete on this device.

Every interface on the firewall has an IP address, a CIDR prefix length, and (almost always) a gateway. Reading those values, and knowing what they mean, is the first skill the firewall operator must internalise.

IPv4 in 32 bits

An IPv4 address is 32 bits, conventionally written as four decimal octets separated by dots:

192.0.2.50  =  11000000.00000000.00000010.00110010

The CIDR prefix length tells you how many of those bits identify the network:

192.0.2.50/24  →  24-bit network portion, 8-bit host portion
192.0.2.50/26  →  26-bit network portion, 6-bit host portion

/24 is the most common: 256 addresses, of which 254 are usable for hosts (the lowest is the network address, the highest is the broadcast). /30 is the smallest useful subnet for a point-to-point link — two usable addresses, often used for firewall uplinks or CARP VIP segments.

Read-only / Safeipcalc
$ ipcalc 192.0.2.50/26
Address:   192.0.2.50
Netmask:   255.255.255.192 = 11111111.11111111.11111111.11000000
Wildcard:  0.0.0.63
Network:   192.0.2.0/26
HostMin:   192.0.2.1
HostMax:   192.0.2.62
Broadcast: 192.0.2.63
Hosts/Net: 62

Illustrative output

The netmask in dotted-decimal is the same number as the prefix length, just written in four octets: /24 is 255.255.255.0, /26 is 255.255.255.192. The wildcard mask is the inverse, used by ACLs and some firewall engines. OPNsense uses CIDR notation everywhere — the wildcard is internal.

Subnet sizing for firewall interfaces

A firewall interface is a subnet. The firewall owns one IP in that subnet (often the first or last usable address), and the LAN hosts get addresses out of the rest.

InterfaceSubnetFirewall addressHosts
WAN203.0.113.0/29 (provider-assigned)203.0.113.2the upstream router
LAN192.0.2.0/24192.0.2.1up to 253
Servers198.51.100.0/24198.51.100.1up to 253
DMZ198.51.100.128/25198.51.100.129up to 125
Management10.0.0.0/2410.0.0.1up to 253

The mistake most operators make is to give every interface a /24 “for headroom” without thinking about whether the production environment will ever use those 253 addresses. A /25 (126 hosts) or a /26 (62 hosts) is fine for a small VLAN — and the unused addresses are then available for unrelated segments elsewhere.

IPv6 — bigger numbers, same idea

An IPv6 address is 128 bits, written as eight groups of four hex digits separated by colons:

2001:db8:0:0:0:0:0:1

Consecutive groups of zeros can be elided once, so the same address is:

2001:db8::1

CIDR works the same way:

2001:db8:1::/48  →  organisation
2001:db8:1:1::/64 →  subnet (a /64 is the smallest subnet
                      almost every network uses)
2001:db8:1:1::1/64 →  host

The most important rule for IPv6 is a /64 is the smallest subnet a host expects to see on a LAN. SLAAC and IPv6 router advertisements assume /64. If you configure a smaller prefix on a LAN interface, SLAAC will not work, IPv6 autoconfiguration will not work, and hosts will fall back to link-local only.

Read-only / Safesipcalc ipv6
$ sipcalc 2001:db8:1:1::1/64
-[ipv6 : 2001:db8:1:1::1/64]-

Network address....................: 2001:db8:1:1::
Network mask.......................: ffff:ffff:ffff:ffff::
Network mask (in bits).............: 64
Network range......................: 2001:db8:1:1::
- 2001:db8:1:1:ffff:ffff:ffff:ffff
Number of hosts in network.........: 18446744073709551616

Illustrative output

The number of hosts in a /64 is enormous. IPv6 was designed for hosts to have multiple addresses — link-local, global, privacy, multicast — so the address space is not the constraint. The constraint is operational: keep the prefix length consistent with the protocol assumptions.

Why the firewall operator uses this every day

Every interface on OPNsense is a CIDR block plus an IP. Every firewall rule has a source and destination that are CIDR blocks or IPs. Every alias you build will probably be a CIDR block or a table of CIDR blocks. Every NAT entry has a CIDR block for “external address” and another for “internal address”. Knowing how to compute 192.0.2.0/24’s broadcast and usable range — and to spot a typo where someone meant /24 and typed /26 — is a core skill.

Knowledge check · 3 questions

  1. Q1. A subnet is 10.1.2.0/26. What is the directed broadcast address and the number of usable host addresses?

  2. Q2. A /65 prefix on a LAN interface is functionally equivalent to /64 in production.

  3. Q3. Which of the following are good reasons to choose a /27 or /28 instead of a /24 for a VLAN? Select all that apply.

Passing score: 75%. Answers are checked in this browser.