Bookmarks    
nPr and nCr    
Random Number    
SD Calculator    
Sample Size    
Percent Error    
Density    
Molarity    
Molar Mass    
Ohm's Law    
Watts to Amps    
Voltage Drop    
Long Division    
Mixed Numbers    
Rounding    
Nth Root    
Exponents    
Half-Life    
Polar Form    
De Moivre    
3D Distance    
Point to Line    
Cross Product    
Determinant    
Sin Cos Tan    
Triangle Area    
Scale Factor    
Sector Area    
Ellipse Area    
Cube Volume    
Box Volume    
Sphere Volume    
Cone Volume    
Pipe Volume    
Time Duration    
Time Card    
Present Value    
Future Value    
Churn Rate    
A/B Test Calc    
SEO Traffic    
Ideal Weight    
Fat Intake    
Child Height    
Golf Handicap    
Heat Index    
Wind Chill    
Dew Point    
Download Time    
kWh to Cost    
AC Size (BTU)    
Heating Costs    
LED Savings    
Trip Gas Cost    
Tire Size    
Solar Output    
Solar Payback    
Battery Size    
Wall Area    
Gravel Needed    
Mortar Mix    
Slope Grade    
Curtain Size    
Soil Needed    
Sod Needed    
Ramp Length    
Blind Size    
Drain Slope    
Board Feet    
Heat Loss    
Furniture Fit    
Moving Boxes    
Plywood Cuts    
Shelf Sag    
   Add
Probability and random number calculators
Independent Events
Independent Events
Two Events Solver
Two Events Solver
Repeated Trials
Repeated Trials
Bayes' Theorem
Bayes' Theorem
Expected Value
Expected Value
Binomial Distribution
Binomial Distribution
nPr and nCr
nPr and nCr
Circular Permutation
Circular Permutation
With Repetition
With Repetition
Random Number
Random Number
Averages and statistics calculators
Average Calculator
Average Calculator
Mean Median Mode
Mean Median Mode
SD Calculator
SD Calculator
Quartiles & IQR
Quartiles & IQR
Frequency Table
Frequency Table
Correlation (r)
Correlation (r)
Normal Probability
Normal Probability
Z-Score Calculator
Z-Score Calculator
Confidence Interval
Confidence Interval
Sample Size
Sample Size
Mark & Recapture
Mark & Recapture
P-Value Calculator
P-Value Calculator
Percentage and ratio calculators
Percentage Calc
Percentage Calc
Percent Change
Percent Change
Percent Difference
Percent Difference
Percent Error
Percent Error
Ratio Calculator
Ratio Calculator
Discount Calculator
Discount Calculator
Sales Tax Calculator
Sales Tax Calculator
Margin Calculator
Margin Calculator
Speed calculators
Speed Calculator
Speed Calculator
Density and concentration calculators
Density
Density
Molarity
Molarity
Molar Mass
Molar Mass
Physics and electricity calculators
Ohm's Law
Ohm's Law
Watts to Amps
Watts to Amps
Resistor Colors
Resistor Colors
Voltage Drop
Voltage Drop
Unit conversion calculators
Weight Converter
Weight Converter
Shoe Size Converter
Shoe Size Converter
Integer and signed number calculators
Long Division
Long Division
LCM Calculator
LCM Calculator
GCF Calculator
GCF Calculator
Integer Calculator
Integer Calculator
Prime Factorization
Prime Factorization
Diophantine Solver
Diophantine Solver
Modulo Calculator
Modulo Calculator
Factor Calculator
Factor Calculator
Roman Numerals
Roman Numerals
Fraction, decimal and rounding calculators
Fraction Calculator
Fraction Calculator
Mixed Numbers
Mixed Numbers
Simplify Fractions
Simplify Fractions
Fraction to Decimal
Fraction to Decimal
Decimal to Fraction
Decimal to Fraction
Rounding
Rounding
Equation and inequality calculators
Linear Equation
Linear Equation
Linear Systems
Linear Systems
Quadratic Formula
Quadratic Formula
Absolute Value
Absolute Value
Quadratic Inequality
Quadratic Inequality
Polynomial calculators
Binomial Theorem
Binomial Theorem
Square root and nth root calculators
Simplify Radicals
Simplify Radicals
Nth Root
Nth Root
Exponent and logarithm calculators
Exponents
Exponents
Log Calculator
Log Calculator
Number of Digits
Number of Digits
Scientific Notation
Scientific Notation
Sci. Notation Math
Sci. Notation Math
Half-Life
Half-Life
Complex number calculators
Complex Numbers
Complex Numbers
Polar Form
Polar Form
De Moivre
De Moivre
Function and graph calculators
Slope Calculator
Slope Calculator
Linear Function
Linear Function
Direct & Inverse Variation
Direct & Inverse Variation
y = ax² Calculator
y = ax² Calculator
Distance Formula
Distance Formula
3D Distance
3D Distance
Section Formula
Section Formula
Point to Line
Point to Line
Lat/Long Distance
Lat/Long Distance
Complete the Square
Complete the Square
Circle Equation
Circle Equation
Conic Sections
Conic Sections
Polar Coordinates
Polar Coordinates
Sequence calculators
Arithmetic Sequence
Arithmetic Sequence
Geometric Sequence
Geometric Sequence
Fibonacci Sequence
Fibonacci Sequence
Recurrence Relation
Recurrence Relation
Vector calculators
Vector Calculator
Vector Calculator
Cross Product
Cross Product
Matrix calculators
Matrix Calculator
Matrix Calculator
Determinant
Determinant
Inverse Matrix
Inverse Matrix
Plane geometry calculators
Sin Cos Tan
Sin Cos Tan
Degrees ⇔ Radians
Degrees ⇔ Radians
a sin θ + b cos θ
a sin θ + b cos θ
Triangle Solver
Triangle Solver
Triangle Area
Triangle Area
Right Triangle
Right Triangle
Pythagorean Theorem
Pythagorean Theorem
Polygon Angles
Polygon Angles
Scale Factor
Scale Factor
Parallel Lines
Parallel Lines
Rectangle Area
Rectangle Area
Parallelogram Area
Parallelogram Area
Trapezoid Area
Trapezoid Area
Circle Calculator
Circle Calculator
Sector Area
Sector Area
Inscribed Angle
Inscribed Angle
Ellipse Area
Ellipse Area
Solid geometry calculators
Cube Volume
Cube Volume
Cube Surface Area
Cube Surface Area
Box Volume
Box Volume
Box Surface Area
Box Surface Area
Cylinder Volume
Cylinder Volume
Cylinder Surface
Cylinder Surface
Sphere Volume
Sphere Volume
Sphere Surface
Sphere Surface
Spherical Cap Volume
Spherical Cap Volume
Cap Surface Area
Cap Surface Area
Ellipsoid Volume
Ellipsoid Volume
Ellipsoid Surface
Ellipsoid Surface
Pyramid Volume
Pyramid Volume
Pyramid Surface
Pyramid Surface
Cone Volume
Cone Volume
Cone Surface Area
Cone Surface Area
Frustum Volume
Frustum Volume
Frustum Surface Area
Frustum Surface Area
Pipe Volume
Pipe Volume
Capsule Volume
Capsule Volume
Capsule Surface Area
Capsule Surface Area
Date and time calculators
Age Calculator
Age Calculator
Days Between Dates
Days Between Dates
Date Calculator
Date Calculator
Hours From Now
Hours From Now
Day of the Week
Day of the Week
Time Calculator
Time Calculator
Time Zone Converter
Time Zone Converter
Hours Calculator
Hours Calculator
Time Duration
Time Duration
Time Card
Time Card
Finance and economics calculators
Compound Interest
Compound Interest
Simple Interest
Simple Interest
Interest Calculator
Interest Calculator
TVM Calculator
TVM Calculator
Present Value
Present Value
Future Value
Future Value
ROI Calculator
ROI Calculator
IRR Calculator
IRR Calculator
Payback Period
Payback Period
Average Return
Average Return
GDP Calculator
GDP Calculator
Web marketing and ad metric calculators
CTR Calculator
CTR Calculator
Conversion Rate
Conversion Rate
CPC, CPM & CPA
CPC, CPM & CPA
ROAS Calculator
ROAS Calculator
Break-Even CPA
Break-Even CPA
LTV Calculator
LTV Calculator
CAC Calculator
CAC Calculator
Churn Rate
Churn Rate
A/B Test Calc
A/B Test Calc
A/B Sample Size
A/B Sample Size
SEO Traffic
SEO Traffic
Break-Even Point
Break-Even Point
Markup vs. Margin
Markup vs. Margin
CAGR Calculator
CAGR Calculator
Health and fitness calculators
BMI Calculator
BMI Calculator
Sleep Calculator
Sleep Calculator
Calorie Calculator
Calorie Calculator
BMR Calculator
BMR Calculator
TDEE Calculator
TDEE Calculator
Ideal Weight
Ideal Weight
Body Fat Calculator
Body Fat Calculator
Lean Body Mass
Lean Body Mass
Calories Burned
Calories Burned
Protein Intake
Protein Intake
Macro Calculator
Macro Calculator
Carb Calculator
Carb Calculator
Fat Intake
Fat Intake
Child Height
Child Height
Sports calculators
Golf Handicap
Golf Handicap
Pace Calculator
Pace Calculator
1RM Calculator
1RM Calculator
Target Heart Rate
Target Heart Rate
Weather calculators
Heat Index
Heat Index
Wind Chill
Wind Chill
Dew Point
Dew Point
Computer calculators
Base Converter
Base Converter
Subnet Calculator
Subnet Calculator
Download Time
Download Time
Household energy and budget calculators
Electricity Cost
Electricity Cost
kWh to Cost
kWh to Cost
Yearly kWh to Cost
Yearly kWh to Cost
AC Size (BTU)
AC Size (BTU)
AC Running Cost
AC Running Cost
Heating Costs
Heating Costs
Gas vs Electric
Gas vs Electric
LED Savings
LED Savings
Salary Calculator
Salary Calculator
Budget Calculator
Budget Calculator
Car calculators
Trip Gas Cost
Trip Gas Cost
EV Charging Cost
EV Charging Cost
EV vs Gas Cost
EV vs Gas Cost
MPG Calculator
MPG Calculator
Tire Size
Tire Size
Solar power and battery calculators
Solar Output
Solar Output
Solar Panel Count
Solar Panel Count
Solar Payback
Solar Payback
Battery Size
Battery Size
Home and DIY calculators
Tile Calculator
Tile Calculator
Stair Calculator
Stair Calculator
Concrete Volume
Concrete Volume
Wall Area
Wall Area
Wallpaper Rolls
Wallpaper Rolls
Paint Calculator
Paint Calculator
Flooring Needed
Flooring Needed
Exterior Walls
Exterior Walls
Gravel Needed
Gravel Needed
Mortar Mix
Mortar Mix
Slope Grade
Slope Grade
Lumber Cut List
Lumber Cut List
Lot Coverage/FAR
Lot Coverage/FAR
Sheet Vinyl Roll
Sheet Vinyl Roll
Insulation Needed
Insulation Needed
Curtain Size
Curtain Size
TV Size & Distance
TV Size & Distance
Soil Needed
Soil Needed
Sod Needed
Sod Needed
Block Calculator
Block Calculator
Brick Calculator
Brick Calculator
Deck Materials
Deck Materials
Ramp Length
Ramp Length
Pilot Hole Size
Pilot Hole Size
Room Ventilation
Room Ventilation
Paint Thinning
Paint Thinning
Baseboard & Trim
Baseboard & Trim
Blind Size
Blind Size
Picture Hanging
Picture Hanging
Drain Slope
Drain Slope
Screw Calculator
Screw Calculator
Board Feet
Board Feet
Fence Calculator
Fence Calculator
Wood Shrinkage
Wood Shrinkage
Caulk Calculator
Caulk Calculator
Heat Loss
Heat Loss
Furniture Fit
Furniture Fit
Moving Boxes
Moving Boxes
Storage Capacity
Storage Capacity
Plywood Cuts
Plywood Cuts
Shelf Sag
Shelf Sag

IP Subnet Calculator (IPv4 and IPv6 CIDR)

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.

The prefix length is the "24" in "/24" (the number of network bits). Use 0 to 32 for IPv4 and 0 to 128 for IPv6. With /31 and /32, the number of usable hosts is 0.
Result
Enter an IP address and prefix length on the left and press "Calculate". The network address, host counts and a bit diagram will appear here.

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
The IP class (A, B, C and so on) on this page follows the original classful definition based on the first octet (the first number). Classes are an old idea; today's internet mostly uses CIDR, which divides networks freely by prefix length. The "IP type" is "Private" if the address falls in a private IP range and "Public" otherwise, so special addresses such as loopback (127.0.0.1) are classed as "Public". Use a prefix length of 0 to 32 (0 to 128 for IPv6).

What is this calculation used for?

Designing networks for offices and data centers

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.

Setting up a home or office router (Wi-Fi)

"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).

Building networks in the cloud (AWS, Azure and others)

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.

A standard topic in networking certifications

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.

Setting address ranges in firewalls and access control

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

Network address (IP AND subnet mask)
Standard notation (the usual math form)
\(N\) \(=\) \(\mathrm{IP}\) \(\mathbin{\text{AND}}\) \(\mathrm{mask}\)
In words (symbols replaced with words)
④ network address \(N\) \(=\) ① IP address ③ \(\mathbin{\text{AND}}\) ② subnet mask
The formula in words
① Compare each bit of the IP address with each bit of
② the subnet mask ,
③ keep a 1 only where both bits are 1 (the AND operation),
④ and you get the network address \(N\) (the address with all host bits set to 0)
Quick example
For 192.168.10.130 with /24 (subnet mask 255.255.255.0), only the last octet changes
network address \(=\) 192.168.10.130 (IP) \(\mathbin{\text{AND}}\) 255.255.255.0 (mask)
\(130 = 10000010_{2}, \quad 0 = 00000000_{2}\)
\(10000010 \mathbin{\text{AND}} 00000000 = 00000000 = 0\)
\(\Rightarrow 192.168.10.0\)
Key idea
AND (logical conjunction) is the operation that gives 1 only where both bits are 1. A subnet mask has 1s in the high bits (the network portion) and 0s in the low bits (the host portion), so ANDing it with an IP address keeps the network portion as it is and turns every host bit into 0. This gives the first address of that network, the network address.
Broadcast address (network OR wildcard mask)
Standard notation (the usual math form)
\(B\) \(=\) \(N\) \(\mathbin{\text{OR}}\) \(W\)
In words (symbols replaced with words)
③ broadcast address \(B\) \(=\) ① network address \(N\) ② \(\mathbin{\text{OR}}\) ② wildcard mask \(W\)
The formula in words
① Compare each bit of the network address \(N\) with each bit of
② the wildcard mask \(W\) (the subnet mask with its 0s and 1s swapped) , and set a 1 wherever either bit is 1 (the OR operation),
③ and you get the broadcast address \(B\) (the address with all host bits set to 1)
Quick example
From the network 192.168.10.0 and the wildcard mask 0.0.0.255, only the last octet changes
broadcast address \(=\) 192.168.10.0 (network) \(\mathbin{\text{OR}}\) 0.0.0.255 (wildcard)
\(0 = 00000000_{2}, \quad 255 = 11111111_{2}\)
\(00000000 \mathbin{\text{OR}} 11111111 = 11111111 = 255\)
\(\Rightarrow 192.168.10.255\)
Key idea
OR (logical disjunction) is the operation that gives 1 wherever either bit is 1. A wildcard mask is the subnet mask with its 0s and 1s swapped, so its host bits are all 1. ORing it with the network address fills every host bit with 1, which gives the last address of that network, the broadcast address. The broadcast address is a special address for sending to every device on the network at once.
Total hosts (a power of \(2\))
Standard notation (the usual math form)
In words (symbols replaced with words)
\(H\) \(=\) \(2\) \(32-p\)
③ total hosts \(H\) \(=\) ① 2 (on or off) ② host bits \(32-p\)
The formula in words
① Multiply 2 (the two states of one bit, on or off) by itself
② as many times as the number of host bits \(32-p\) (32 bits minus the \(p\) network bits) ,
③ and you get the total number of hosts \(H\)
Quick example
For /24, the host portion has \(32-24=8\) bits, so
total hosts \(=\) 2 8 (host bits)
\(2^{32-24} = 2^{8} = 256\)
Key idea
Each host bit can be 0 or 1, two choices. With \(32-p\) host bits, there are \(2^{32-p}\) combinations, and that is the total number of addresses in the network (the total number of hosts). Each time the prefix length \(p\) goes up by 1 (one more network bit), the number of hosts is cut exactly in half.
Usable hosts (total − 2)
Standard notation (the usual math form)
In words (symbols replaced with words)
\(U\) \(=\) \(H\) \(-\) \(2\)
③ usable hosts \(U\) \(=\) ① total hosts \(H\) \(-\) ② 2 (network and broadcast)
The formula in words
① From the total number of hosts \(H\) ,
② subtract 2 (the network address at the start and the broadcast address at the end) ,
③ and you get the number of usable hosts \(U\) (the number of addresses you can give to devices)
Quick example
For /24, the total number of hosts is 256, so
usable hosts \(=\) 256 (total hosts) \(-\) 2
\(256 - 2 = 254\)
Key idea
In each network, the first address (the network address) and the last address (the broadcast address) are reserved for special uses and cannot be given to devices. So the number of addresses you can actually use is the total minus 2. The exceptions are /31 (2 addresses) and /32 (1 address): subtracting 2 leaves nothing, so the number of usable hosts is treated as 0 (/31 has a special use for point-to-point links).
Subnet calculations rest on four formulas - network address = IP AND subnet mask, broadcast address = network OR wildcard mask, total hosts = \(2^{32-p}\), and usable hosts = total − 2. Each time the prefix length \(p\) goes up by 1, the network splits in two and the number of hosts is cut in half. IPv6 works the same way, and the total number of addresses is \(2^{128-p}\).

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)
  • Being able to convert a decimal number such as 192 to binary, 11000000 (an IP address is really a binary number)
  • Knowing that one binary digit (a bit) has two possible values, 0 or 1
Powers and exponents (Grades 6–8)
  • Knowing that "2 to the \(n\)th power" is 2 multiplied \(n\) times, as in \(2^8 = 256\)
  • Having a feel for how one more host bit doubles the number of hosts
Logical AND and OR (high school computer science)
  • Knowing the rules - AND gives 1 only when both bits are 1, and OR gives 1 when either bit is 1
  • Being able to apply these two operations bit by bit (digit by digit)
Bits and bytes (high school computer science)
  • Knowing that 1 byte = 8 bits and can hold 0 to 255 (8 binary digits)
  • Knowing that an IPv4 address is made of 8 bits × 4 = 32 bits

How to calculate it in Excel

Copy the whole table below and paste it into cell A1 in Excel. It works as is.
Table for total hosts and usable hosts
Prefix length p 24
Host bits (32−p) =32-B1
Total hosts =2^B2
Usable hosts =MAX(B3-2,0)
Table for the subnet mask
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)
In the first table, enter a prefix length in B1, and the host bits, total hosts and usable hosts are calculated automatically. "^" is the power symbol, so "=2^B2" is "2 multiplied by itself B2 times". For /24, you get 256 total hosts and 254 usable hosts. MAX(…,0) keeps the result from going below 0 for /31 and /32.
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

Copy the whole table below and paste it into cell A1 in Google Sheets. It works as is.
Table for total hosts and usable hosts
Prefix length p 24
Host bits (32−p) =32-B1
Total hosts =2^B2
Usable hosts =MAX(B3-2,0)
Table for the subnet mask
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 same formulas as in Excel work as is. Copy the whole table, paste it into cell A1, and replace B1 with your own prefix length. Taking out each octet with INT (quotient) and MOD (remainder) works the same way too.

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}")
The standard library's ipaddress module is all you need. strict=False in ip_network lets you pass an IP whose host bits are not 0 (such as 192.168.10.130) and treats it as its network instead of raising an error. Change the IP address and prefix length at the top and run it.

How to write it in LaTeX and other math languages (copy and paste)

Network address (IP AND subnet mask)
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>&#x2227;</mo>
    <mi>mask</mi>
  </mrow>
</math>
N = IP ^^ mask
BitAnd[ip, mask]
N := Bits:-And(ip, mask);
N = bitand(ip, mask);
N = IP ∧ mask
Broadcast address (network OR wildcard 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>&#x2228;</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
Total hosts (a power of \(2\))
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>&#x2212;</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)
Usable hosts (total − 2)
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>&#x2212;</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
  1. 1
    Enter your numbers
    Type the numbers you want to calculate with into the input fields
  2. 2
    Calculate
    Press the "Calculate" button
  3. 3
    Check the result
    The result appears on the spot. The same page also explains the idea behind the calculation and the formula
  DataChef Features
Easy and Free
Unlimited conversions for free.
No technical knowledge required.
Intuitive and user-friendly operation.
No Registration Required
Available immediately after access.
Can be used without registering personal information.
Safe and Secure
Fully SSL encrypted communication.
Automatic file deletion by clicking "download".
Fast
High-speed site access
and rapid file conversion.
No Watermark
No watermark.
No attribution required.
Commercial Use Available
Free for commercial use.
No need to contact us for commercial use permission.