Subnetting via Boolean Algebra
Subnetting relies heavily on the bitwise Logical AND operation. When a computer or router wants to determine if another destination IP is on its local subnet (meaning it can communicate directly without a gateway), it performs a bitwise AND between the destination IP address and its own [subnet mask](/tools/subnet-calculator/subnet-mask-reference-table).
The AND Rule Basics:
- `1 AND 1 = 1`
- `1 AND 0 = 0`
- `0 AND 1 = 0`
- `0 AND 0 = 0`
If the result of this AND operation matches the device's own network address, the destination is local. If it differs, the packet is sent to the default gateway.
Mathematical Proof of Subnet Counts
When you 'borrow' bits from the host portion of an IP address to create smaller subnets, the math follows strict powers of two.
Let `b` equal the number of borrowed bits.
Let `h` equal the original number of host bits before borrowing.
\[ \text{Created Subnets} = 2^b \]
\[ \text{Hosts per Subnet} = 2^{(h - b)} - 2 \]
Example Proof: Breaking a /24 into /27s
Imagine you start with a `/24` network (`192.168.1.0/24`). You need to create smaller `/27` subnets.
1. **Borrowed Bits (`b`)**: You are moving from a `/24` to a `/27`. That means you borrowed `27 - 24 = 3` bits.
2. **Subnets Created**: `2^3 = 8` subnets.
3. **Hosts per Subnet**: The new suffix is 27, leaving `32 - 27 = 5` host bits. So, `2^5 - 2 = 30` usable hosts per subnet.
Magic Number Technique
To quickly calculate subnet boundaries without binary math, network engineers use the 'Magic Number' method. The magic number is found by subtracting the interesting octet of the [subnet mask](/tools/subnet-calculator/subnet-mask-reference-table) from 256.
For a `/27` mask (`255.255.255.224`), the interesting octet is 224.
256 - 224 = 32Therefore, your subnets will increment in blocks of 32: `.0`, `.32`, `.64`, `.96`, and so on.
