How do you calculate the network address from an IP and netmask?
Bitwise-AND the IP with the netmask: where the mask is 1 you keep the IP bit, where it's 0 you force it to 0. The result is the network address.
* Bitwise-AND the IP with the netmask — keep the bit where the mask is 1, force 0 where it is 0 — the /24 result names the subnet (256 addresses, 254 usable). *
The netmask is just a run of 1s (network) followed by 0s (host). ANDing the address with it "masks off" the host bits, leaving only the network bits — that's the address that names the subnet itself. This is the exact computation a host does to decide whether a destination is local: AND both addresses with the mask and compare.
Example 1: /16 network
IP: 172.17.5.3 = 10101100.00010001.00000101.00000011
Netmask: 255.255.0.0 = 11111111.11111111.00000000.00000000
─────────────────────────────────────────────────────────────
Network: 172.17.0.0 = 10101100.00010001.00000000.00000000
Example 2: /24 network
IP: 192.168.5.3 = 11000000.10101000.00000101.00000011
Netmask: 255.255.255.0 = 11111111.11111111.11111111.00000000
─────────────────────────────────────────────────────────────
Network: 192.168.5.0 = 11000000.10101000.00000101.00000000
Rule: Where netmask has 1s → keep IP bits. Where netmask has 0s → set to 0.