the way i do it is to start with the /30 subnet, count backwards while doubling the number of host, than subtract 2 when you reach the range your looking for.
for example: 45 host
/30= 4
/29= 8
/28= 16
/27= 32
/26= 64 - 2 = 62 available host
another: 500 host
/30= 4
/29= 8
/28= 16
/27= 32
/26= 64
/25= 128
/24= 256
/23= 512 - 2 = 510 available host