Calculate PREFIX from subnet mask in bootscripts
Kevin P. Fleming
kpfleming at linuxfromscratch.org
Tue Oct 19 07:36:18 PDT 2004
Gerard Beekmans wrote:
> So never mind my question about what 255.255.255.252 is. It's /30
> according to this table. Good enough for me. Though I'd still appreciate
> the math behind it if anybody can explain it.
The math is pretty easy:
An IP address is 32 bits long. Some portion of those bits, starting from
the beginning, are used to separate the address into "network" and
If you turn your netmask of 255.255.255.252 into binary, it becomes:
1111-1111 1111-1111 1111-1111 1111-1100
If you then count the number of 1-bits starting from the beginning, you
get 30, so this netmask is equivalent to a VLSM prefix of /30.
The common /24 prefix is:
1111-1111 1111-1111 1111-1111 0000-0000
And so on.
More information about the lfs-dev