Subnet calculator (IPv4 and IPv6 CIDR)

Find the network address, broadcast, usable host range and host count of any IPv4 or IPv6 CIDR block, with netmask, wildcard and equal subnets.

更新于 已验证的示例:7

IPv4 as 10.1.2.3/24 or with a netmask (10.1.2.3 255.255.255.0); IPv6 as 2001:db8::1/64.
Rounded up to a power of two; 1 keeps the network whole.
试一试
Network
192.168.10.64/26
Network: 192.168.10.64/26
Netmask
255.255.255.192
Wildcard mask
0.0.0.63
Prefix length
26
First usable address
192.168.10.65
Last usable address
192.168.10.126
Broadcast address
192.168.10.127
Usable addresses
62
Total addresses
64
Historical class
C
Address type
Private (RFC 1918)
Prefix of each subnet
28
Addresses in each subnet
16

192.168.10.77 sits inside 192.168.10.64/26, which has 64 addresses (62 usable, 192.168.10.65 to 192.168.10.126). Private (RFC 1918). Splitting it gives 4 × /28 of 16 addresses each.

/26 in binary

Address 192.168.10.77
1
1
0
0
0
0
0
0
1
0
1
0
1
0
0
0
0
0
0
0
1
0
1
0
0
1
0
0
1
1
0
1
Mask 255.255.255.192
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
0
0
0
0
0
Network 192.168.10.64
1
1
0
0
0
0
0
0
1
0
1
0
1
0
0
0
0
0
0
0
1
0
1
0
0
1
0
0
0
0
0
0
Broadcast 192.168.10.127
1
1
0
0
0
0
0
0
1
0
1
0
1
0
0
0
0
0
0
0
1
0
1
0
0
1
1
1
1
1
1
1

Where the address sits in the block

/28 #1: 0 to 16/28 #1/28 #2: 16 to 32/28 #2/28 #3: 32 to 48/28 #3/28 #4: 48 to 64/28 #4Your addressoffset 13
4 subnets of /28, 14 usable addresses each 行数:4
#SubnetFirst usableLast usableBroadcast
1192.168.10.64/28192.168.10.65192.168.10.78192.168.10.79
2192.168.10.80/28192.168.10.81192.168.10.94192.168.10.95
3192.168.10.96/28192.168.10.97192.168.10.110192.168.10.111
4192.168.10.112/28192.168.10.113192.168.10.126192.168.10.127
计算方法 S
  1. Address and mask in binary

    address=11000000.10101000.00001010.01001101mask/26=11111111.11111111.11111111.11000000\begin{aligned}\text{address} &= \texttt{11000000.10101000.00001010.01001101} \\ \text{mask} /26 &= \texttt{11111111.11111111.11111111.11000000}\end{aligned}

    The first 26 bits name the network; the other 6 number the addresses inside it.

  2. Network address: AND with the mask

    11000000.10101000.00001010.01000000=192.168.10.64\texttt{11000000.10101000.00001010.01000000} = 192.168.10.64
  3. Last address: OR with the wildcard

    192.168.10.64∨0.0.0.63=192.168.10.127192.168.10.64 \lor 0.0.0.63 = 192.168.10.127
  4. Count the usable addresses

    232−26−2=64−2=622^{32-26} - 2 = 64 - 2 = 62

    The all-zeros host is the network itself and the all-ones host is the broadcast, so neither is assigned.

  5. Split into equal subnets

    22≥4⇒/26+2=/28232−28=16 addresses each\begin{aligned} 2^{2} &\ge 4 \Rightarrow /26 + 2 = /28 \\ 2^{32-28} &= 16\ \text{addresses each}\end{aligned}

关于Subnet calculator (IPv4 and IPv6 CIDR)

A prefix length p keeps the first p bits of an address as the network and leaves the rest to number hosts. The calculator ANDs the address with the netmask to find the network address, ORs that with the wildcard mask (the inverted netmask) to find the last address, and counts 2^(32 − p) addresses for IPv4 or 2^(128 − p) for IPv6.

Engineers use it to plan VLANs, firewall rules and cloud VPC ranges. The default, 192.168.10.77/26, belongs to 192.168.10.64/26: 64 addresses, 62 of them usable from .65 to .126, with .127 as the broadcast. Splitting it 4 ways gives four /28 subnets of 16 addresses.

IPv4 counts leave out the network and broadcast addresses except on /31 point-to-point links (RFC 3021) and /32 host routes. IPv6 has no broadcast, so only the subnet-router anycast address is left out. Splits are always into a power of two equal subnets; for a VLSM plan, split one of the results again.

计算示例

Host in a /26

Address and prefix
192.168.10.77/26
Split into this many subnets
1
Network
192.168.10.64/26
Netmask
255.255.255.192
Wildcard mask
0.0.0.63
Broadcast address
192.168.10.127
First usable address
192.168.10.65
Last usable address
192.168.10.126
Usable addresses
62
Total addresses
64
Historical class
C
Address type
Private (RFC 1918)

核验来源:Python 3.8 ipaddress.ip_interface('192.168.10.77/26').network, .netmask, .hostmask, .broadcast_address, list(hosts())

Point-to-point /31 (edge)

Address and prefix
10.0.0.0/31
Split into this many subnets
1
First usable address
10.0.0.0
Last usable address
10.0.0.1
Usable addresses
2
Total addresses
2

核验来源:RFC 3021 §2; Python 3.8 list(ip_network('10.0.0.0/31').hosts()) = [10.0.0.0, 10.0.0.1]

Single host /32 (edge)

Address and prefix
203.0.113.5/32
Split into this many subnets
1
Network
203.0.113.5/32
First usable address
203.0.113.5
Last usable address
203.0.113.5
Usable addresses
1
Address type
Documentation, TEST-NET-3 (RFC 5737)

核验来源:Python 3.8 list(ip_network('203.0.113.5/32').hosts()) = [203.0.113.5]; RFC 5737 §3

Netmask instead of a prefix

Address and prefix
172.16.5.4 255.255.240.0
Split into this many subnets
1
Network
172.16.0.0/20
Prefix length
20
Broadcast address
172.16.15.255
Total addresses
4,096
Historical class
B

核验来源:Python 3.8 ip_interface('172.16.5.4/255.255.240.0').network = 172.16.0.0/20, num_addresses = 4096

常见问题

How many usable hosts are in a /24 subnet?

A /24 has 256 addresses and 254 usable hosts, because the all-zeros address names the network and the all-ones address is the broadcast. The IPv4 rule is 2^(32 − prefix) − 2: a /25 gives 126, a /26 62, a /27 30, a /28 14, a /29 6 and a /30 2. The exceptions are /31, where RFC 3021 lets a point-to-point link use both addresses, and /32, a single host.

What is the difference between a subnet mask and CIDR notation?

They say the same thing in two ways. CIDR notation writes the number of network bits after a slash, as in /26; a subnet mask writes those bits as a dotted address with that many leading ones, so /26 is 255.255.255.192 and /20 is 255.255.240.0. CIDR, introduced in 1993 and now defined in RFC 4632, replaced the fixed class A, B and C boundaries, so any prefix from /0 to /32 is valid.

What is a wildcard mask?

A wildcard mask is the subnet mask with every bit inverted, so 255.255.255.192 becomes 0.0.0.63. Cisco IOS access lists and OSPF network statements use it: a 0 bit must match and a 1 bit is ignored. To get it, subtract each octet of the netmask from 255. For a /26 the last octet is 63, one less than the block's 64 addresses.

Why do AWS and Azure subnets have 5 fewer usable addresses?

Both clouds reserve 5 addresses in every subnet: the network address, the next three (for the router and DNS, or held for future use) and the last address. A /24 in an AWS VPC or Azure virtual network therefore has 251 assignable addresses instead of the 254 shown here. The smallest subnet AWS allows is a /28, which leaves 11; Azure's smallest is a /29, which leaves 3.

How many addresses are in an IPv6 /64?

A /64 holds 2^64 = 18,446,744,073,709,551,616 addresses. It is the standard size for one IPv6 LAN because RFC 4291 requires 64-bit interface identifiers for most unicast addresses, and stateless autoconfiguration (SLAAC) builds addresses from them. A /48 contains 65,536 of those /64 subnets, and a /56 contains 256.

“Subnet calculator (IPv4 and IPv6 CIDR)”有多准确?

准确性取决于输入值和方法的假设。十进制运算使用50位有效数字,但估算、数值方法和源数据的精度可能较低;显示时的舍入并不能消除这些限制。 已按独立来源核验的计算示例:7。 例如,“Host in a /26”根据Python 3.8 ipaddress.ip_interface('192.168.10.77/26').network, .netmask, .hostmask, .broadcast_address, list(hosts())进行核验。

这种方法出自哪里?

RFC 4632 — Classless Inter-domain Routing (CIDR); RFC 3021 — Using 31-bit prefixes on IPv4 point-to-point links; RFC 1918 — Address allocation for private internets; RFC 4291 — IPv6 addressing architecture; RFC 5952 — IPv6 text representation; IANA IPv4 and IPv6 special-purpose address registries (RFC 6890).

关于此计算器

network=address∧masklast=network∨¬maskhosts=232−p−2\begin{aligned}\text{network} &= \text{address} \land \text{mask} \\ \text{last} &= \text{network} \lor \lnot\text{mask} \\ \text{hosts} &= 2^{32-p} - 2\end{aligned}

来源

  1. RFC 4632 — Classless Inter-domain Routing (CIDR)
  2. RFC 3021 — Using 31-bit prefixes on IPv4 point-to-point links
  3. RFC 1918 — Address allocation for private internets
  4. RFC 4291 — IPv6 addressing architecture; RFC 5952 — IPv6 text representation
  5. IANA IPv4 and IPv6 special-purpose address registries (RFC 6890)

已对照来源验证

此计算器包含 7 个已解示例,答案来自独立来源。这些示例会在测试套件中运行,你也可以在此运行验证。

相关计算器