Mask to Prefix
Lesson 11 of 46 in Coddy's IP Addressing and Subnetting course.
A mask and a prefix length are the same fact in two costumes. To go from mask to prefix, count the ones.
Full octets are easy: each 255 contributes 8. The interesting octet is the partial one. Remember the left-packed bytes from chapter one: 128 is one bit, 192 is two, 224 is three, 240 is four, 248 is five, 252 is six, 254 is seven.
So 255.255.255.192 is 8 + 8 + 8 + 2 = /26. With that little table memorized, you convert masks at a glance.
Challenge
BeginnerConvert each mask to its prefix length. Print one per line, slash included, in this order:
255.0.0.0255.255.255.192
Expected output:
/8
/26Try it yourself
All lessons in IP Addressing and Subnetting
Practice on your own: Terminal playground