A Windows Forms application for calculating IPv4 subnet information based on IP address and CIDR mask bits.
- Four separate text boxes for entering each octet of an IPv4 address
- Input validation: only numeric values 0-255 are accepted
- Default IP: 123.123.234.132
- Clipboard Paste Button: Pastes IP address from clipboard (supports format xxx.xxx.xxx.xxx)
- Public IP Button: Retrieves your public IP address from web services (api.ipify.org, icanhazip.com, or ifconfig.me)
- Both buttons are 28x28 pixels with emoji icons
- TrackBar control ranging from 0 to 32 bits
- Default: 28 bits (matching example specification)
- Real-time updates as slider moves
- Current value displayed next to slider
The application calculates and displays:
- Subnet Bits: Number of bits borrowed from the host portion for subnetting (based on classful addressing)
- Max Subnets: Maximum number of possible subnets (2^subnet_bits - 2)
- Host Bits: Number of bits available for host addresses (32 - mask bits)
- Max Hosts: Maximum usable host addresses per subnet (2^host_bits - 2)
- Current Mask: Subnet mask in dotted decimal notation
Shows detailed network information:
- Subnet (network address)
- Broadcast address
- First usable host address
- Last usable host address
- Total usable hosts
Special cases handled:
- /31 networks: Point-to-point links (RFC 3021) with 2 usable addresses
- /32 networks: Single host addresses
Every control has descriptive tooltips explaining its purpose and usage.
The application uses classful IP addressing for subnet calculations:
- Class A (0-127.x.x.x): Default /8 mask
- Class B (128-191.x.x.x): Default /16 mask
- Class C (192-223.x.x.x): Default /24 mask
- Class D (224-239.x.x.x): Multicast (no subnetting)
- Class E (240-255.x.x.x): Reserved (no subnetting)
Subnet bits are calculated as: Current Mask Bits - Class Default Mask Bits
For IP 123.123.234.132 with /28 mask:
- Class: A (default /8)
- Subnet bits: 28 - 8 = 20
- Max subnets: 2^20 - 2 = 1,048,574
- Host bits: 32 - 28 = 4
- Max hosts: 2^4 - 2 = 14
- Mask: 255.255.255.240
- Subnet: 123.123.234.128
- Broadcast: 123.123.234.143
This matches the specification exactly.
All calculations update automatically when:
- Any IP octet value changes
- The mask slider moves
The paste button parses IP addresses in standard dotted decimal notation (xxx.xxx.xxx.xxx) from clipboard text.
The public IP button attempts to retrieve your external IP address using multiple fallback services:
If all services fail or timeout (5 second limit), it returns "127.0.0.1" as a fallback.
- .NET 9.0 SDK or later
- Windows operating system
cd SubnetCalc
dotnet build
dotnet run
The compiled executable is located at:
bin/Debug/net9.0-windows/SubnetCalc.exe
SubnetCalc/
├── Form1.cs - Main form logic and event handlers
├── Form1.Designer.cs - UI layout and control definitions
├── Program.cs - Application entry point
├── SubnetCalc.csproj - Project configuration
└── README.md - This file
Form1_Load
: Initializes form and performs first calculationIpOctet_TextChanged
: Triggers recalculation when IP changesIpOctet_KeyPress
: Validates numeric input onlyTrackBarMask_ValueChanged
: Updates calculations when mask changesBtnPasteClipboard_Click
: Handles clipboard paste functionalityBtnGetPublicIp_Click
: Retrieves public IP address asynchronously
GetClassMaskBits
: Determines IP class and returns default mask bitsUpdateSubnetInfo
: Main calculation engine - updates all display fieldsGetCurrentIpAddress
: Parses IP octets into 32-bit unsigned integerIpToString
: Converts 32-bit integer to dotted decimal notationTryParseIpAddress
: Validates and parses IP address strings
GetPublicIpAddressAsync
: Asynchronous public IP retrieval with fallback
The buttons use Unicode emoji characters:
- 📋 (Clipboard) for paste button
- 🌐 (Globe) for public IP button
These should display correctly on Windows 10+ systems with proper font support.
The application follows historical subnet calculation methods where:
- Subnet zero and all-ones subnets were reserved (hence the -2 in calculations)
- Modern networks typically allow these subnets, but classic calculations exclude them
- IP octets are validated to ensure values 0-255
- Only numeric input is allowed in IP fields
- Empty or invalid fields prevent calculations until corrected