Tools
Subnet Calculator
Enter an IPv4 address with a prefix or a mask and get the network, broadcast, first and last host, host count, wildcard, class and type. See the binary behind it, or switch to VLSM and plan subnets of different sizes inside one network.
The tool
How it works
Finding the network and the hosts
An IPv4 address is 32 bits. The mask says how many of them, from the left, name the network (the prefix length, as in /24). The rest name the host. The network address is the address AND the mask, bit by bit: a 1 in the mask keeps the address bit and a 0 clears it. The broadcast address is the network with all host bits set to 1, which is the same as the network OR the wildcard (the mask turned upside down).
The first host is the network address plus 1, and the last host is the broadcast address minus 1. A subnet with h host bits has 2^h addresses and 2^h - 2 usable hosts, because the network and broadcast addresses cannot be given to a device. Two cases are different: a /31 has 2 usable addresses on a point-to-point link (RFC 3021), and a /32 is one single address.
Classes and address types
The class comes from the first bits: A starts with 0 (first number 0 to 127), B with 10 (128 to 191), C with 110 (192 to 223), D with 1110 (224 to 239, multicast) and E with 1111 (240 and up). Today networks are routed by their prefix, not by class, but the class is still asked in exams. Private addresses are 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16. The page also names loopback (127/8), link-local (169.254/16), shared carrier-grade NAT (100.64/10) and multicast.
VLSM: subnets of different sizes
With variable length subnet masks you do not cut a network into equal parts. Each group of devices gets a block just big enough: the smallest block with at least hosts + 2 addresses. A campus Wi-Fi with 100 users needs a /25 (126 hosts), while a link between two routers needs only a /30.
The planner puts the biggest subnet first, then the next biggest, each at the next address that is a multiple of its size. This keeps every block aligned, nothing overlaps, and the unused space stays in one piece at the end of the base network.
Questions
How do I find the network address from an IP and a mask?
Write both in binary and AND them: the result has a 1 only where both have a 1. For 192.168.1.130 with 255.255.255.192, the last octet is 10000010 AND 11000000 = 10000000, which is 128. The network is 192.168.1.128. The Binary AND steps tab shows this for your own address.
Why do I subtract 2 to count the hosts in a subnet?
The first address of a subnet names the network and the last one is the broadcast address, so neither can belong to a device. A /24 has 256 addresses and 254 hosts. A /31 is the exception on a point-to-point link, where both addresses are used, and a /32 is a single host.
What is a wildcard mask?
The wildcard is the subnet mask with every bit flipped. For 255.255.255.0 it is 0.0.0.255. Router access lists use it to say which bits of an address must match (0) and which can be anything (1).
What is VLSM and why use it?
Variable length subnet masks let each subnet have its own size. A lab of 50 computers gets a /26 and a link between two routers gets a /30, so few addresses are wasted. Equal-size subnets would force the biggest size on every group.
Which IPv4 addresses are private?
Three blocks are reserved for private use (RFC 1918): 10.0.0.0 to 10.255.255.255, 172.16.0.0 to 172.31.255.255 and 192.168.0.0 to 192.168.255.255. Devices using them reach the internet through NAT.
Learn the idea behind it
The tool is easier to use once you know what it is doing. These courses and lessons teach it from the start: the Computer Networks course, the Digital Logic course and the Computer Architecture course.
- Subnetting (Networks)Split one network into smaller ones: masks, network and broadcast addresses, host counts, and giving each group a block of the right size with VLSM.
- IP addresses (Networks)IPv4 addresses in decimal and binary, the network and host parts, private addresses, NAT, and why IPv6 has 128 bits.
- Routing tables and longest prefix match (Networks)How a router decides where to send each packet: forwarding tables, the longest matching prefix, the default route, route aggregation and the TTL.
- DHCP and NAT: getting an address and sharing one (Networks)How a device gets its IP address automatically with DHCP, and how NAT lets a whole home share one public address by rewriting addresses and ports.
More tools
- Subnetting in binaryThe smaller version that sits inside the lesson.
- Number System ConverterBinary, octal, decimal, hex, 2's complement and IEEE 754, with steps.
- K-Map SolverKarnaugh maps for 2 to 5 variables with SOP, POS and steps.