A Python-based IPv4 subnetting utility for calculating and visualizing network information from CIDR notation or a subnet mask.
The project was built to make IPv4 subnetting easier to understand by showing both the calculated addresses and their binary representation, including a visual distinction between network and host portions.
IP-Subnetting-v2 can calculate and display:
- IPv4 address in binary
- Subnet mask in decimal
- Subnet mask in binary
- Network address
- Network address in binary
- Broadcast address
- Usable host range
- Host capacity
- Network and host portions of an IPv4 address
The utility accepts both:
192.168.1.10/24
and:
192.168.1.10 255.255.255.0
Run the program:
python3 subnetting.pyThe application asks for an IPv4 address using either CIDR notation:
10.0.2.15/24
or an explicit subnet mask:
10.0.2.15 255.255.255.0
For a /24 network, the calculated information includes values such as:
IP Address: 10.0.2.15
Subnet Mask: 255.255.255.0
Network Address: 10.0.2.0
Broadcast Address: 10.0.2.255
Usable IP Range: 10.0.2.1 - 10.0.2.254
The program also displays the binary representation of the address and subnet mask.
IPv4 subnetting is fundamentally based on bits.
For example:
IP Address:
10.0.2.15
Binary:
00001010.00000000.00000010.00001111
A /24 subnet mask becomes:
11111111.11111111.11111111.00000000
This makes it possible to see which bits belong to the network portion and which belong to the host portion.
The terminal output uses ANSI colors to visually separate:
- Network bits
- Host bits
Conceptually:
11111111.11111111.11111111.00000000
└──────── Network ─────────┘└─ Host ─┘
This makes the project useful not only as a calculator, but also as a learning tool for understanding how subnet masks divide an IPv4 address.
CIDR notation defines how many of the 32 IPv4 bits belong to the network portion.
For example:
/24
corresponds to:
11111111.11111111.11111111.00000000
which is:
255.255.255.0
The program performs this conversion automatically.
The network address is calculated by applying the subnet mask to the IPv4 address.
Conceptually:
IP Address
AND
Subnet Mask
=
Network Address
Example:
192.168.1.42
255.255.255.0
----------------
192.168.1.0
The broadcast address is calculated from the network address and the host portion of the subnet.
Example:
Network: 192.168.1.0
Mask: 255.255.255.0
Broadcast: 192.168.1.255
For traditional IPv4 subnets, the first address represents the network and the last address represents the broadcast address.
For example:
Network: 192.168.1.0
First Host: 192.168.1.1
Last Host: 192.168.1.254
Broadcast: 192.168.1.255
IP-Subnetting-v2/
├── subnetting.py
└── subnetting.txt
The main implementation is contained in:
subnetting.py
The project uses an object-oriented structure to separate the different input formats.
An abstract base class defining the common subnetting interface.
It includes abstract operations for tasks such as:
- Decimal-to-binary conversion
- Subnet mask conversion
- Network/host calculations
- Network/host visualization
Handles addresses supplied using CIDR notation.
Example:
192.168.1.10/24
It converts the CIDR prefix into a subnet mask and performs the required IPv4 calculations.
Handles addresses supplied with an explicit subnet mask.
Example:
192.168.1.10 255.255.255.0
Determines which implementation should be used based on the supplied input format.
Conceptually:
User Input
│
├── Contains "/" ──────► CIDR
│
└── IP + Mask ─────────► SubnetMask
The application validates IPv4 addresses by checking:
- Four IPv4 octets are present
- Each octet is numeric
- Each octet is between
0and255
CIDR values are checked to ensure they are between:
/0
and:
/32
- Python 3
- A terminal with ANSI color support
The project only uses Python standard-library modules and does not require third-party packages.
Clone the repository:
git clone https://github.com/bellurm/IP-Subnetting-v2.git
cd IP-Subnetting-v2Run the program:
python3 subnetting.pyThis project demonstrates practical understanding of:
- IPv4 addressing
- CIDR notation
- Subnet masks
- Binary and decimal conversion
- Network addresses
- Broadcast addresses
- Host ranges
- Network and host bits
- Python
- Object-oriented programming
- Abstract base classes
- Factory-style object creation
- Input validation
- Terminal output formatting
Subnetting calculators can provide an answer immediately, but they often hide the binary operations that produce that answer.
IP-Subnetting-v2 was created to expose those intermediate steps and make subnetting easier to understand visually.
The goal is not only to calculate:
192.168.1.10/24
but also to understand why the resulting network is:
192.168.1.0/24
and how the network and host portions are represented at the bit level.
This is an educational IPv4 subnetting utility rather than a complete network engineering library.
The current implementation uses the traditional IPv4 usable-host calculation:
2^host_bits - 2
As a result, /31 and /32 networks are not handled using their special modern networking semantics.
Explicit subnet masks are validated as IPv4-formatted values, but the current implementation does not perform full validation that the mask contains only contiguous network bits.
IPv6 is not currently supported.
The project can be useful for:
- Learning IPv4 subnetting
- Networking fundamentals
- Cybersecurity fundamentals
- Network administration practice
- CIDR exercises
- Visualizing network and host bits
- Understanding binary IPv4 representation
Cyber Worm
GitHub: @bellurm