I recently started to learn how IPv4 works. I know how to divide a given address range in smaller ones and set up a network in that way (at least in Netsim K).
But I wanted to do a bit of something else. Let's say I have 2 IP addresses, P1 and P2 and a netmask M. How can I determine the smallest range that contains both P1 and P2. I can start by doing P1 & M to determine P1's network and P2 & M for P2's. If these networks are the same I should just try to divide that range into smaller ones. But what if they are different.
Let's say I have the netmask: 255.255.192.0 (/18) and the IPs: 18.104.22.168 and 22.214.171.124. This gives me: 126.96.36.199 and 188.8.131.52 for the network addresses. Doing IP or not netmask gives: 184.108.40.206 and 220.127.116.11 as broadcast addresses. What should I do now? It seems like I did something wrong. But assuming I didn't, should I try to merge 18.104.22.168 / 18 with the above range and so on until I have those 2 IPs in the same network?
EDIT: after the answer, here is the way I did this for the above example (just in case someone else stumbles upon this in the future).
193.230.014.208 and 193.231.020.017 have 15 bits in common. In base 2: 193.11100110.don't care (also, don't care about 193) 193.11100111. This means that the network these 2 share has a /15 netmask. Doing a logical and between any of the addresses and this new netmask will give us the desired network.