Choose IPv4 or IPv6 in "Mode", then enter an IP address and prefix length. The page calculates the network address, host counts, subnet mask and more, and draws a bit diagram.
Table of Contents
-
What you can do on this page
-
What is this calculation used for?
-
How to Use
-
Formula
-
Symbols and terms
-
Good to know before you start
-
How to calculate it in Excel
-
How to calculate it in Google Sheets
-
How to calculate it in Python
-
How to write it in LaTeX and other math languages (copy and paste)
-
How to have ChatGPT do the calculation
-
DataChef Features
-
Related Features
-
NumberChef Calculators List
What you can do on this page
- Enter an IP address and prefix length (for example, 192.168.1.0 /24), and you get the network address, broadcast address and usable host IP range on the spot
- It also calculates the total hosts, usable hosts, subnet mask, wildcard mask, CIDR notation, integer ID and hex ID all at once
- A bit diagram colors the 32 bits of the IP address by network portion and host portion, so you can see how subnetting works
- You can switch between IPv4 and IPv6 modes. In IPv6 mode, it calculates the network, address range and total addresses (\(2^{128-\text{prefix length}}\))
- A plain-language explanation of the formulas and copy-and-paste formulas for Excel, Google Sheets and Python are all on this page
What is this calculation used for?
Large organizations divide one IP network into smaller subnets for each department or location. For example, "to connect up to 60 devices in the sales department, assign a /26, which has 62 usable hosts (\(2^{32-26}-2 = 62\))". You choose the prefix length from the number of devices you need.
Subnet calculation is a basic design skill that network administrators and infrastructure engineers use almost every day.
"192.168.1.0/24" and "subnet mask 255.255.255.0", which you often see in a home router's settings, are exactly this calculation. A /24 has 254 usable hosts, so you can connect up to 254 devices in total, such as phones, computers and TVs.
It also helps when a device will not connect: you can check whether its IP address is in the right range (network).
When you create your own private network in the cloud (such as an AWS VPC), you give its address range in CIDR notation, for example "this VPC is 10.0.0.0/16, and a subnet inside it is 10.0.1.0/24". Overlapping ranges cannot talk to each other, so you need to work out the network addresses and host counts correctly.
For cloud engineers, subnet calculation is a must-have skill and the starting point for building an environment.
Certifications such as Cisco's CCNA and CompTIA Network+ repeatedly ask questions like "Given this IP address and subnet mask, find the network address, the broadcast address and the number of usable hosts".
Binary AND and OR and powers of 2 - the four formulas on this page - are exactly what earns those points. With the steps and the bit diagram, you can practice by working through problems yourself.
In firewall rules and access control lists (ACLs), such as "allow traffic only from this subnet", you specify the addresses to allow or deny together in CIDR notation (for example, 192.168.10.0/24). If you get the network address and range wrong, you may block traffic by mistake or open a hole by accident.
In security work, this calculation is the basis for specifying ranges that are exactly right, no wider and no narrower.
Formula
Symbols and terms
Symbols
| \(N\) | N | The network address, the first address of the network (all host bits 0). It is used as the name of the network itself. |
| \(B\) | B | The broadcast address, the last address of the network (all host bits 1). It is used to send to every device on the network at once. |
| \(W\) | W | The wildcard mask, the subnet mask with its 0s and 1s swapped. Its host bits are all 1, and it is used to find the broadcast address and in access control lists. |
| \(p\) | p | The prefix length, the "24" in "/24". It tells how many bits the network portion has. (From "prefix".) |
| \(H\) | H | The total number of hosts, the total number of addresses in the network, \(H = 2^{32-p}\). (From "host".) |
| \(U\) | U | The number of usable hosts, the number of addresses you can actually give to devices. It is the total minus 2 (the network address and the broadcast address). |
| \(\land\) | AND | Logical AND (conjunction). The result is 1 only when both bits are 1. It is used to find the network address. |
| \(\lor\) | OR | Logical OR (disjunction). The result is 1 when either bit is 1. It is used to find the broadcast address. |
Terms
| subnet | Each of the smaller networks that a large IP network is divided into. Splitting a network by department or location (subnetting) makes it easier to manage and more secure. |
| subnet mask | A 32-bit value that shows where the network portion of an IP address ends and the host portion begins. It has 1s for the network bits and 0s for the host bits (for example, 255.255.255.0). |
| prefix length | The number of network bits. It is written like "/24" and carries the same information as the subnet mask in a shorter form. |
| CIDR | Classless Inter-Domain Routing, usually pronounced "cider". A method that divides networks freely by prefix length instead of by class, written with a slash, as in "192.168.1.0/24". It is the standard on today's internet. |
| network address | The first address of the network (all host bits 0). It is not given to any device and is used as the name of the network itself. |
| broadcast address | The last address of the network (all host bits 1). It is a special address for sending to every device on the network at the same time. |
| wildcard mask | The subnet mask with its bits flipped. The host bits are all 1. It is used to calculate the broadcast address and in router access control lists (ACLs). |
| octet | One of the four parts of an IPv4 address separated by periods (8 bits, 0 to 255). In 192.168.1.0, "192", "168", "1" and "0" are each one octet. |
| private IP address | An IP address reserved for use only inside a home or organization (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, defined in RFC 1918). It cannot be used on the internet as is. An address that works across the whole internet is called a public IP address. |
| IP class (classful addressing) | An older system, used before CIDR became common, that set the size of a network by its first number (the first octet) as Class A, B, C and so on. It is no longer used for routing, but the terms are still around, so this page shows the class too. |
| IPv4 | The 32-bit addressing system (about 4.3 billion addresses), the most widely used one. It is the main focus of this page. |
| IPv6 | The newer 128-bit addressing system, with a practically unlimited number of addresses. It was created to solve the shortage of IPv4 addresses. |
| bit | The smallest unit of information, either 0 or 1. An IPv4 address is made of 32 bits and an IPv6 address of 128 bits. |
Good to know before you start
Here is what helps you use the calculation on this page with real understanding, not just by pressing the button.
| Binary and decimal (high school computer science) |
|
| Powers and exponents (Grades 6–8) |
|
| Logical AND and OR (high school computer science) |
|
| Bits and bytes (high school computer science) |
|
How to calculate it in Excel
| Prefix length p | 24 |
| Host bits (32−p) | =32-B1 |
| Total hosts | =2^B2 |
| Usable hosts | =MAX(B3-2,0) |
| Prefix length p | 24 |
| Subnet mask as an integer | =(2^32)-(2^(32-B1)) |
| First octet | =INT(B2/16777216) |
| Second octet | =INT(MOD(B2,16777216)/65536) |
| Third octet | =INT(MOD(B2,65536)/256) |
| Fourth octet | =MOD(B2,256) |
The second table splits the subnet mask into its four octets (0 to 255). B2 calculates the whole mask as one integer, and B3 to B6 take out each octet using quotients and remainders of division by powers of 256. For /24, the result is 255.255.255.0.
How to calculate it in Google Sheets
| Prefix length p | 24 |
| Host bits (32−p) | =32-B1 |
| Total hosts | =2^B2 |
| Usable hosts | =MAX(B3-2,0) |
| Prefix length p | 24 |
| Subnet mask as an integer | =(2^32)-(2^(32-B1)) |
| First octet | =INT(B2/16777216) |
| Second octet | =INT(MOD(B2,16777216)/65536) |
| Third octet | =INT(MOD(B2,65536)/256) |
| Fourth octet | =MOD(B2,256) |
How to calculate it in Python
import ipaddress
ip = "192.168.10.130" # IP address
prefix = 24 # prefix length (the 24 in /24)
net = ipaddress.ip_network(f"{ip}/{prefix}", strict=False)
total = net.num_addresses # total hosts = 2 ** (32 - prefix)
usable = max(total - 2, 0) # usable hosts (0 for /31 and /32)
print(f"Network address: {net.network_address}")
print(f"Broadcast address: {net.broadcast_address}")
print(f"Subnet mask: {net.netmask}")
print(f"Wildcard mask: {net.hostmask}")
print(f"Total hosts: {total}")
print(f"Usable hosts: {usable}")
How to write it in LaTeX and other math languages (copy and paste)
N = IP ∧ mask
N = \mathrm{IP} \land \mathrm{mask}
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mrow>
<mi>N</mi>
<mo>=</mo>
<mi>IP</mi>
<mo>∧</mo>
<mi>mask</mi>
</mrow>
</math>
N = IP ^^ mask
BitAnd[ip, mask]
N := Bits:-And(ip, mask);
N = bitand(ip, mask);
N = IP ∧ mask
B = N ∨ W
B = N \lor W
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mrow>
<mi>B</mi>
<mo>=</mo>
<mi>N</mi>
<mo>∨</mo>
<mi>W</mi>
</mrow>
</math>
B = N vv W
BitOr[network, wildcard]
B := Bits:-Or(network, wildcard);
B = bitor(network, wildcard);
B = N ∨ W
H = 2^(32 − p)
H = 2^{32 - p}
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mrow>
<mi>H</mi>
<mo>=</mo>
<msup>
<mn>2</mn>
<mrow><mn>32</mn><mo>−</mo><mi>p</mi></mrow>
</msup>
</mrow>
</math>
H = 2^(32 - p)
2^(32 - p)
H := 2^(32 - p);
H = 2^(32 - p);
H = 2^(32-p)
U = H − 2
U = H - 2
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<mrow>
<mi>U</mi>
<mo>=</mo>
<mi>H</mi>
<mo>−</mo>
<mn>2</mn>
</mrow>
</math>
U = H - 2
H - 2
U := H - 2;
U = H - 2;
U = H - 2
How to have ChatGPT do the calculation
You are a network calculation assistant. Do the following calculation by actually running Python (the standard library's ipaddress module), and base your answer only on the numbers from the execution result (do not answer by mental math or guessing). For the IPv4 address 192.168.10.130 with a prefix length of /24, find: 1. The network address 2. The broadcast address 3. The subnet mask and the wildcard mask 4. The total number of hosts and the number of usable hosts Show the code you used and the numbers from the execution result.
How to Use
-
1Enter your numbersType the numbers you want to calculate with into the input fields
-
2CalculatePress the "Calculate" button
-
3Check the resultThe result appears on the spot. The same page also explains the idea behind the calculation and the formula
DataChef Features
No technical knowledge required.
Intuitive and user-friendly operation.
Can be used without registering personal information.
Automatic file deletion by clicking "download".
and rapid file conversion.
No attribution required.
No need to contact us for commercial use permission.
