Cidrsubnet to generate subnets

Hi there,

I have a requirement to split a /24 vnet in azure into two subnets of size /25 and /26 respectively. the VNet IP range is and i want the below subnets to be created with below address range:

sbx-subnet -
bastion subnet -

I am able to get the /25 using cidrsubnet(“”, 1, 0) but for the .128/26 i am not sure the correct usage. I tried with below, but is giving error or different values:
cidrsubnet(“”, 2, 8) → error saying the newbits has to be of higher value.
cidrsubnet(“”, 4, 8) → this will result in

Kindly help me and provide the correct syntax for creating out of


Hi Jerald,

The cidrsubnet function takes a given existing prefix (/24 in this instance), applies an bitmask extended by the ‘number of additional bits’ (/25 = 1 additional bit, /26 2 additional bits) and then returns the ‘nth’ network.

So cidrsubnet(“”, 1, 0) add an additional bit to the network bitmask, to create 2 new subnets (2^n=2 where n=number of additional bits=1) of 128 addresses (7 host bits = 2^7 = 128 addresses)
New subnets are therefore:

#0 - as a.b.c.0hhhhhhh
#1 - as a.b.c.1hhhhhhh

Consider your starting subnet which can be represented as follows, with n showing the network part of the bitmap and h showing the host part:


You wish to further subnet this to get:

The first network of /25 (where a,b,c are the first octets of the network respectively, n are the additional subnet bits and h is the host range:

and 1 network of /26 starting from 128 as start host address of that subnet.

So there are two ways of doing this:

As you already have for the /25:
/25 = cidrsubnet("", 1, 0)

And then for the /26. Ignore that you have calculated the /25 and just understand that you want the 3rd /26 subnet (as the first two /26 subnets 0-63 & 64-127 are the same range as your already reserved /25

/26 = cidrsubnet("", 2, 2)

The second way, which is:

cidrsubnet(cidrsubnet("", 1, 1), 1, 0)

In this second example you are taking the second network of the /25 (

and then feeding that network into another cidrsubnet to take the first network from the next additional but (/26):

Either are valid, but the second way explicitly shows that you are subnetting (to /26) a subnet (the second /25) of the original prefix range (The /24).

The second way would be the way you might illustrate it when working out a IP addressing scheme where you show you have allocated the first /25, and then further sub-netted the second /25:

CIDR sub-Network Number (s bits) Network Subnet Mask Range
/24 11111111.11111111.11111111.00000000
___↳/25 0 11111111.11111111.11111111.s000000
___↳/25 1 11111111.11111111.11111111.s000000
______↳/26 0 11111111.11111111.11111111.1s00000
______↳/26 1 11111111.11111111.11111111.1s00000
1 Like

Hi ExtelligenceIT,

Thanks a lot for the detailed explanation and solution. Apologies for delayed response, I was on vacation. I tried it today and it worked as expected.

Thanks again,

1 Like