CALCULATORCASTLE

IP Subnet Calculator

Calculate subnet mask, network address, broadcast address, and host range for any IP.

About

IP Subnet Calculator

Two calculators sit above this text. The first takes an IPv4 address and a subnet mask and returns the network address, the broadcast address, the usable host range and the host counts, along with the same address written out in binary, as a single integer, in hexadecimal and in reverse-DNS form. The second does the same for an IPv6 prefix, where the address counts run to twenty digits and the arithmetic stops fitting in an ordinary number.

What a subnet is

A subnet is a division of an IP network. An IP network is a set of communications protocols used on the internet and on private networks built the same way, known collectively as TCP/IP after its two best-known members, the Transmission Control Protocol and the Internet Protocol.

Cutting one network into two or more smaller networks is called subnetting. Routers pass traffic between the pieces and act as the boundary between them, which is the practical reason to subnet at all: traffic that stays inside a subnet never troubles the router, and broadcast traffic stops at its edge. IPv4 is still the most widely deployed addressing architecture. IPv6 was specified in 1998, and Google's own adoption measurements now put more than 40% of its users on IPv6 connections.

How an address splits into network and host

An IP address carries two parts. The first is a network number, also called the routing prefix. The second is a rest field, which identifies one host or one network interface inside that network. Every host on a subnet shares the same prefix and holds a different rest field, so the prefix says which network and the rest field says which machine.

Nothing in the four numbers of an address says where the split falls. That is what the subnet mask is for. The mask is another 32-bit value, written in the same dotted-decimal style, whose bits are all ones up to the split and all zeros after it. 255.255.255.0 is twenty-four ones followed by eight zeros, so the first twenty-four bits are the prefix and the last eight identify the host.

CIDR notation

Writing out 255.255.255.252 to say "thirty ones" is tedious, so a routing prefix is usually written in Classless Inter-Domain Routing notation instead: the address, a slash, and the number of leading one-bits in the mask. 255.255.255.252 becomes /30. CIDR applies to both IPv4 and IPv6, and for IPv6 it is the only notation in use, since IPv6 has no dotted-decimal mask form.

Prior to CIDR, an IPv4 prefix was read straight off the address using its class. A first octet from 1 to 126 made it class A with an implied /8, 128 to 191 made it class B with /16, and 192 to 223 made it class C with /24. Since CIDR arrived in 1993, assigning an address to an interface takes both the address and its mask, because the address alone no longer tells you where the boundary sits.

Reading the mask in binary

The calculator prints the mask in binary because that is where the arithmetic happens. The network address is the address ANDed with the mask, which keeps every bit the mask covers and zeroes the rest. The broadcast address is the network ORed with the wildcard mask, which is the subnet mask inverted, filling every host bit with ones.

The wildcard mask is worth knowing separately. Cisco access lists and OSPF network statements take a wildcard rather than a subnet mask, so 0.0.0.3 in a config means the same block as /30. Subtracting each octet of the mask from 255 gets you there.

The size of the block follows from the host bits alone. For a prefix of n bits there are 232n addresses, and the usable host count is 232n2, because the first address names the network and the last is the broadcast address.

Typical subnets for IPv4

Every prefix from /1 to /32, the mask it corresponds to, and how many hosts the block leaves once the network and broadcast addresses are taken out.

Prefix sizeNetwork maskUsable hosts per subnet
/1128.0.0.02,147,483,646
/2192.0.0.01,073,741,822
/3224.0.0.0536,870,910
/4240.0.0.0268,435,454
/5248.0.0.0134,217,726
/6252.0.0.067,108,862
/7254.0.0.033,554,430
Class A
/8255.0.0.016,777,214
/9255.128.0.08,388,606
/10255.192.0.04,194,302
/11255.224.0.02,097,150
/12255.240.0.01,048,574
/13255.248.0.0524,286
/14255.252.0.0262,142
/15255.254.0.0131,070
Class B
/16255.255.0.065,534
/17255.255.128.032,766
/18255.255.192.016,382
/19255.255.224.08,190
/20255.255.240.04,094
/21255.255.248.02,046
/22255.255.252.01,022
/23255.255.254.0510
Class C
/24255.255.255.0254
/25255.255.255.128126
/26255.255.255.19262
/27255.255.255.22430
/28255.255.255.24014
/29255.255.255.2486
/30255.255.255.2522
/31255.255.255.2540
/32255.255.255.2550

What the IP class row is telling you

The IP class shown in the result comes from the prefix length, not from the first octet of the address. That is worth stating plainly, because the two readings disagree. Feed the calculator 37.136.110.118 with a /30 and the class reads C, since /24 through /32 fall in the class C band of the table above. Read the same address the old way and its first octet of 37 makes it class A.

Neither reading is wrong, they answer different questions. The prefix-based one describes the size of the block you asked for. The address-based one describes the historical allocation the address came from, which since 1993 has no bearing on how the address is routed. The Network Class buttons above work on the same prefix-based reading: they change which masks the menu offers, and picking a different class does not change any number in the result.

Public, private and the blocks in between

The IP type row names the block an address belongs to. Three ranges are set aside by RFC 1918 for private use, and traffic from them is not routed across the public internet, which is why a home network almost always sits inside 192.168.0.0/16. Several other ranges are reserved for narrower purposes.

BlockPurposeDefined in
0.0.0.0/8This networkRFC 1122
10.0.0.0/8Private useRFC 1918
100.64.0.0/10Carrier-grade NATRFC 6598
127.0.0.0/8LoopbackRFC 1122
169.254.0.0/16Link-localRFC 3927
172.16.0.0/12Private useRFC 1918
192.0.0.0/24IETF protocol assignmentsRFC 6890
192.0.2.0/24Documentation (TEST-NET-1)RFC 5737
192.88.99.0/246to4 relay anycast, deprecatedRFC 7526
192.168.0.0/16Private useRFC 1918
198.18.0.0/15BenchmarkingRFC 2544
198.51.100.0/24Documentation (TEST-NET-2)RFC 5737
203.0.113.0/24Documentation (TEST-NET-3)RFC 5737
224.0.0.0/4MulticastRFC 5771
240.0.0.0/4ReservedRFC 1112
255.255.255.255/32Limited broadcastRFC 8190

The documentation blocks are useful when writing anything down. Examples in this text use 192.0.2.0/24 and its two siblings precisely because no real network can be reached through them, so a copied config cannot accidentally point at somebody else's equipment.

The awkward sizes: /31 and /32

The table gives /31 and /32 zero usable hosts, and by the classical rule that is right: a /31 holds two addresses, both spoken for by the network and broadcast roles, and a /32 holds one. Both are used anyway.

RFC 3021 allows a /31 on a point-to-point link, where there is no broadcast to worry about and the two addresses simply become the two ends. That halves the address waste on router-to-router links, which used to take a /30 and leave two of its four addresses idle. A /32 names a single interface, which is how loopback addresses and host routes are written. The calculator reports the classical count of zero for both, and shows the whole block in the range column so you can still see the addresses involved.

The other identifiers in the result

The second table converts the address rather than the network. The binary ID is the same 32 bits with the dots removed. The integer ID is those bits read as one unsigned number, which is how an address is usually stored in a database and compared in a range query. The hex ID is the same value in base 16, two digits per octet.

The in-addr.arpa name is what a reverse DNS lookup asks for: the four octets in reverse order with that suffix, so 37.136.110.118 becomes 118.110.136.37.in-addr.arpa. The reversal exists because DNS names get more specific right to left while IP addresses get more specific left to right.

The last two rows bridge to IPv6. An IPv4-mapped address embeds the 32 bits inside an IPv6 address after a ::ffff: prefix, which lets a dual-stack socket carry IPv4 traffic without a separate code path. The 6to4 prefix is the /48 that RFC 3056 derives from a public IPv4 address, giving a site an IPv6 range without asking anyone for one. 6to4 was deprecated in 2015, but the derivation still shows what an address maps to.

A worked example

Take 37.136.110.118 with a /30. In binary the address is 00100101.10001000.01101110.01110110 and the mask is 11111111.11111111.11111111.11111100. ANDing them clears the last two bits and gives 00100101.10001000.01101110.01110100, which is 37.136.110.116, the network address. ORing that with the wildcard 0.0.0.3 sets both bits and gives 37.136.110.119, the broadcast.

Two host bits mean four addresses and two usable ones, 37.136.110.117 and 37.136.110.118. The address entered is the second of the pair. Since /30 blocks are 4 addresses wide, the surrounding 37.136.110.0/24 divides into 64 of them, starting at .0, .4, .8 and so on to .252, which is the table the calculator prints underneath.

Splitting a block into unequal pieces

Real networks rarely want equal subnets. Variable-length subnet masking means using a different prefix for each piece of a block, sized to what that piece holds. Given 192.0.2.0/24 and a need for one segment of 100 hosts, one of 50 and four point-to-point links, the arithmetic runs: 100 hosts needs 7 host bits, so a /25 with 126 usable; 50 needs 6, so a /26 with 62; each link takes a /30.

Allocate largest first to avoid stranding address space. The /25 takes 192.0.2.0 to 192.0.2.127. The /26 takes 192.0.2.128 to 192.0.2.191. The four /30s then come out of 192.0.2.192 onward, at .192, .196, .200 and .204, leaving 192.0.2.208/28 and up still free. Setting the calculator to /30 with an address in that upper range shows exactly which four-address slot each link occupies.

IPv6 prefixes

IPv6 addresses are 128 bits, written as eight groups of four hex digits. A run of all-zero groups collapses to a double colon once per address, so 2001:0db8:85a3:0000:0000:8a2e:0370:7334 shortens to 2001:db8:85a3::8a2e:370:7334. The calculator prints both forms, since configs and logs disagree about which to use.

There is no broadcast address in IPv6 and no network address to reserve, so every address in a prefix is usable in principle. A /64 is the standard size for one link, because stateless address autoconfiguration builds the bottom 64 bits from the interface itself. That leaves 18,446,744,073,709,551,616 addresses on a single segment, which is more than the entire IPv4 space squared. A residential site is typically handed a /56 or /48, giving it 256 or 65,536 separate /64 links to allocate internally.

2001:db8::/32 is the documentation prefix, the IPv6 counterpart to 192.0.2.0/24, which is why it appears in the field above and in nearly every IPv6 example ever written.

Common questions

Frequently asked questions

It marks where an IP address stops describing the network and starts describing the host. The router ANDs a destination address with the mask to work out which network the address belongs to, then decides whether to deliver locally or forward. Two hosts with the same address but different masks will disagree about who is local to them, which is a common cause of traffic that leaves in one direction and never comes back.

254. A /24 leaves 8 host bits, so the block holds 256 addresses, and the first and last are taken by the network address and the broadcast address. The same subtraction runs at every size: a /25 gives 126, a /26 gives 62, a /27 gives 30.

The IP class row reads the prefix length rather than the first octet. A /30 sits in the /24 to /32 band that the reference table labels class C, so that is what it reports. By the older address-based reading, a first octet of 37 would make it class A. Since CIDR replaced classful routing in 1993 the address-based class no longer affects how traffic is routed, so it is a historical label rather than an operational one.

They are inverses. Where the subnet mask has a one, the wildcard has a zero. 255.255.255.252 and 0.0.0.3 describe the same /30. Cisco access lists and OSPF network statements take the wildcard form, so both appear in the result.

On a point-to-point link, yes. RFC 3021 defines the two addresses in a /31 as the two ends of the link, with no network or broadcast address reserved, because a link with exactly two interfaces has nothing to broadcast to. Most current router software supports it. On a broadcast segment such as Ethernet with more than two devices, a /31 is not usable.

Add two to the host count, for the network and broadcast addresses, then round up to the next power of two. Sixty hosts needs 62 addresses, which rounds to 64, which is 6 host bits, which is a /26. Leave headroom: a segment sized to exactly today's device count needs renumbering the moment it grows.

It lists every subnet of the chosen size inside the surrounding classful block. A /30 is four addresses wide and the surrounding /24 holds 256, so 256 divided by 4 gives 64 subnets. Change the prefix and both the row count and the step between rows change with it. The highlighted row is the one holding the address entered.

The arithmetic is the same, the conventions are not. Prefixes are still a count of leading bits, but there is no broadcast address and nothing is reserved at either end of a block, so every address counts. Subnetting below /64 breaks stateless address autoconfiguration, so /64 is treated as the floor for an ordinary link even though the address space would allow far smaller pieces.