How to put two subnets next to each other?
You need to distinguish the subnet start address and the subnet size. The number behind the slash is the size (in 32-x bits). So you can have two /27 subnets like this
10.0.0.1/27 == 10.0.0.1 -> 10.0.0.30
10.0.0.33/27 == 10.0.0.33 -> 10.0.0.62
but a /27 and a /25 subnet in the same way would mean starting the /25 at a later address
10.0.0.1/27 == 10.0.0.1 -> 10.0.0.30
10.0.0.129/25 == 10.0.0.129 -> 10.0.0.254
since the /25 subnet "needs" more space. You cannot start the /25 subnet at an arbitrary address, only at the correct boundaries:
10.0.0.1/25 == 10.0.0.1 -> 10.0.0.126
10.0.0.129/25 == 10.0.0.129 -> 10.0.0.254
but note that
10.0.0.33/25 == 10.0.0.1 -> 10.0.0.126
because 10.0.0.33/25
is just another way of saying 10.0.0.1/25
or 10.0.0.0/25
.
You could also decide to "fill" the space between you /27 and your /25 subnet with more /27 subnets:
10.0.0.1/27 == 10.0.0.1 -> 10.0.0.30
10.0.0.33/27 == 10.0.0.33 -> 10.0.0.62
10.0.0.65/27 == 10.0.0.65 -> 10.0.0.94
10.0.0.97/27 == 10.0.0.97 -> 10.0.0.126
10.0.0.129/25 == 10.0.0.129 -> 10.0.0.254
or with another /27 and a /26:
10.0.0.1/27 == 10.0.0.1 -> 10.0.0.30
10.0.0.33/27 == 10.0.0.33 -> 10.0.0.62
10.0.0.65/26 == 10.0.0.65 -> 10.0.0.126
10.0.0.129/25 == 10.0.0.129 -> 10.0.0.254
Prefixes/subnets use binary logic. Subnets are determined by the bits that are fixed and the bits that are usable for addresses. The number of fixed bits is the prefix length or subnet mask. A few IPv4 examples:
Prefix: 10.0.0.0/8
Prefix length: 8
Subnet mask: 255.0.0.0
Prefix bits: 00001010 00000000 00000000 00000000 = 10.0.0.0
Subnet mask bits: 11111111 00000000 00000000 00000000 = 255.0.0.0
A 1
in the subnet mask bits indicates that the corresponding bit is fixed, and a 0
indicates that you can use that bit. The prefix length is the number of bits set to 1
, and the subnet mask is that binary number written down as an IPv4 address.
So in this example you can use:
First address in the prefix: 00001010 00000000 00000000 00000000 = 10.0.0.0
Last address in the prefix: 00001010 11111111 11111111 11111111 = 10.255.255.255
Another example with a different prefix length:
Prefix: 10.0.0.0/10
Prefix length: 10
Subnet mask: 255.192.0.0
Prefix bits: 00001010 00000000 00000000 00000000 = 10.0.0.0
Subnet mask bits: 11111111 11000000 00000000 00000000 = 255.192.0.0
In this example you can use less addresses:
First address in the prefix: 00001010 00000000 00000000 00000000 = 10.0.0.0
Last address in the prefix: 00001010 00111111 11111111 11111111 = 10.63.255.255
As you can see the subnet is determined by the value and number of the fixed bits. When using your example 1.0.0.32/25
you get:
Prefix: 1.0.0.32/25
Prefix length: 25
Subnet mask: 255.255.255.128
Prefix bits: 00000001 00000000 00000000 00100000 = 10.0.0.32
Subnet mask bits: 11111111 11111111 11111111 10000000 = 255.255.255.128
First address in the prefix: 00000001 00000000 00000000 00000000 = 1.0.0.0
Last address in the prefix: 00000001 00000000 00000000 01111111 = 1.0.0.127
The value 32 is in the middle of the flexible bits. When looking at /25
prefixes you get:
Prefix length: 25
Subnet mask bits: 11111111 11111111 11111111 10000000
1st /25 in 1.0.0.0: 00000001 00000000 00000000 00000000 = 1.0.0.0/25
2nd /25 in 1.0.0.0: 00000001 00000000 00000000 10000000 = 1.0.0.128/25
3rd /25 in 1.0.0.0: 00000001 00000000 00000001 00000000 = 1.0.1.0/25
4th /25 in 1.0.0.0: 00000001 00000000 00000001 10000000 = 1.0.1.128/25
5th /25 in 1.0.0.0: 00000001 00000000 00000010 00000000 = 1.0.2.0/25
Etc.
When looking at /27
prefixes you get:
Prefix length: 27
Subnet mask bits: 11111111 11111111 11111111 11100000
1st /25 in 1.0.0.0: 00000001 00000000 00000000 00000000 = 1.0.0.0/27
2nd /25 in 1.0.0.0: 00000001 00000000 00000000 00100000 = 1.0.0.32/27
3rd /25 in 1.0.0.0: 00000001 00000000 00000000 01000000 = 1.0.0.64/27
4th /25 in 1.0.0.0: 00000001 00000000 00000000 01100000 = 1.0.0.96/27
5th /25 in 1.0.0.0: 00000001 00000000 00000000 10000000 = 1.0.0.128/27
Etc.
In an IPv4 subnet the first address (flexible bits all 0
) is reserved and called the network address. The last address (flexible bits all 1
) is the subnet broadcast address. You can't use those for network interfaces on devices.
If you want to put multiple subnets next to each other you'll have to make sure that they don't overlap. When you don't have a lot of address space like with IPv4 making all the subnets fit can be a very difficult process, and keeping it manageable when changing the addressing plan is even harder. That is why IPv6 is so nice to work with: plenty of address space, and a subnet is usually a /64
(it is possible to use different prefix lengths but that does break some things like auto-configuration).
If you are interested in IPv6 addressing plans then take a look at the 'Preparing an IPv6 Addressing Plan' document I wrote a couple of years ago for SURFnet (the Dutch National Research and Education Network). The way subnetting works in IPv6 is exactly the same as for IPv4, except the numbers are a lot bigger and written in hexadecimal (which corresponds much better to bits than the decimal notation used for IPv4!). Prefix lengths, having fixed and flexible bits all works in exactly the same way though. A short example:
Prefix: 2001:0db8:0000:0000:0000:0000:0000:0000/64
Prefix length: 64
Subnet mask: not really used anymore in IPv6, but it would have been:
ffff:ffff:ffff:ffff:0000:0000:0000:0000
Prefix bits: 0010 0000 0000 0001 0000 1101 1011 1000 = 2001:0db8
0000 0000 0000 0000 0000 0000 0000 0000 = 0000:0000
0000 0000 0000 0000 0000 0000 0000 0000 = 0000:0000
0000 0000 0000 0000 0000 0000 0000 0000 = 0000:0000
Subnet mask bits: 1111 1111 1111 1111 1111 1111 1111 1111 = ffff:ffff
1111 1111 1111 1111 1111 1111 1111 1111 = ffff:ffff
0000 0000 0000 0000 0000 0000 0000 0000 = 0000:0000
0000 0000 0000 0000 0000 0000 0000 0000 = 0000:0000
First address in the prefix:
0010 0000 0000 0001 0000 1101 1011 1000 = 2001:0db8
0000 0000 0000 0000 0000 0000 0000 0000 = 0000:0000
0000 0000 0000 0000 0000 0000 0000 0000 = 0000:0000
0000 0000 0000 0000 0000 0000 0000 0000 = 0000:0000
Last address in the prefix:
0010 0000 0000 0001 0000 1101 1011 1000 = 2001:0db8
0000 0000 0000 0000 0000 0000 0000 0000 = 0000:0000
1111 1111 1111 1111 1111 1111 1111 1111 = ffff:ffff
1111 1111 1111 1111 1111 1111 1111 1111 = ffff:ffff
So from 2001:0db8:0000:0000:0000:0000:0000:0000
to 2001:0db8:0000:0000:ffff:ffff:ffff:ffff
PS: I didn't use the recommended/canonical notation here on purpose. Usually you compress the zeroes in the address and write 2001:0db8:0000:0000:0000:0000:0000:0000
as 2001:db8::
, 2001:0db8:0000:0000:0000:0000:0000:0001
is written as 2001:db8::1
, etc.
For a /24, the last octet (usually reserved) for the network is .0 and only .0.
1 subnet
For a /25, it may then be either .0 or .128.
2 subnets
For a /26, it may be either .0, .64, .128, or .192.
4 subnets
For a /27, it may be either .0, .32, .64, .96, .128, .160, .192, or .224.
8 subnets
for a /28, .0, .16, .32, .48, .64, .80, .96, .112, .128, .144, .160, .176, .192, .208, .224, or .240.
16 subnets
for a /29, .0, .8, .16, .24, .32, .40, .48, .56, .64, .72, .80, .88, .96, .104, .112, .120, .128, .136, .144, .152, .160, .168, .176, .184, .192, .200, .208, .216, .224, .232, .240, or .248
32 subnets
The /30 prefix is usually found on point-to-point interfaces.
64 subnets
The /31 prefix is not commonly found in the wild, as it has no commonly addressable hosts, since it only spans 2 network numbers, the "network" and the "broadcast" with no space for a host IP.
128 subnets
(all even numbers between 0 and 254)The /32 prefix is used to specify a route for a single host. It's the most specific of routes and if present, should take routing precedence over all other route table entries that are not also /32s. A /32 does not have a 'network' nor a 'broadcast' address.
256 subnets
(0 and 255 may not work on some implementations)