Its VLSM ( Veriable Lenght Subnet Masking )
IP Blocks are comimng in Factors of 2
2 = 2^1 = /31 (32-1) = 255.255.255.254
4 = 2^2 = /32 (32-2) = 255.255.255.252
8 = 2^3 = /29 (32-3) = 255.255.255.248
16 = 2^4 = /28 (32-4) = 255.255.255.240
32 = 2^5 = /27 (32-5) = 255.255.255.224
64 = 2^6 = /26 (32-6) = 255.255.255.192
128 = 2^7 = /25 (32-7) = 255.255.255.128
256 = 2^8 = /24 (32-8) = 255.255.255.0
512 = 2^9 = /23 (32-9) = 255.255.254.0
1024 = 2^10 = /22 (32-10) = 255.255.252.0
So if you need 500 host in one branch , you have to take 512 host range .
192.168.0.0/23
if you need 40 hosts ...You need to get a 64 block , But you can not get it from 192.168.0.0/23 since its utilized for branch 1 therefore you have to get the next block 192.168.2.0 , it can be divided into 4 nos of 64 blocks from that IP range 192.168.2.0/26 , 192.168.2.64/26 ,192.168.2.128/26 ,192.168.2.192/26
hope you get an idea about it