IPv4 Subnetting: Decimal Fast Method

Three masks need no maths: 255.0.0.0, 255.255.0.0 and 255.255.255.0. Every other mask has one interesting octet, neither 255 nor 0. Subtract that mask octet from 256 to get the magic number; the subnet ID's interesting octet is the multiple of the magic number at or just below the address's value there.

Free to read12 min read · 12 min video

By , founder of Daveth · Updated

Opening frame of the video walkthrough of IPv4 Subnetting: Decimal Fast Method

Watch this lesson

12 min · Video walkthrough

In Daveth Pro (Network)

The full 12 min walkthrough is in Daveth Pro (Network). See what the plan opens

What this page answers

What is the fastest way to subnet?

Work in decimal. With an easy mask, copy the address where the mask is 255 and write 0 elsewhere. With a difficult mask, only the interesting octet needs maths, using the magic number, 256 minus that mask octet. Read it in “The interesting octet”

Same answers, less writing

Wednesday. Sam did yesterday's binary on the bus, all 32 bits of it, and arrives with one question: is there a quicker way? There is. The binary method works well, but the conversions take time, and even with 04.3's shortcut most people need a lot of practice to get fast. For the exam, you should aim to find the subnet ID and the range of usable addresses from an IP address and mask in about 15 seconds. Most people get there faster, at least after a little practice, with a method that uses only decimal.

The decimal method finds the same answers as 04.3's binary method. It just doesn't tell you anything about why they're right, which is why 04.3 came first. Done right, the two always agree; when yours don't, one of them has a slip, and the binary shows where.

Easy masks

Three masks need no maths at all: 255.0.0.0, 255.255.0.0 and 255.255.255.0. They contain only 255s and 0s, so every octet is either all prefix or all host. For the subnet ID, octet by octet:

  1. Where the mask octet is 255, copy the address's decimal value.
  2. Where the mask octet is 0, write 0.

The broadcast is the same, except that where the mask octet is 0 you write 255. That's 04.3's shortcut, and with an easy mask it's the whole job.

With an easy mask, all four octets have already handed in their answers: copy, or write 0 or 255.

Six to try. Find the subnet ID and broadcast for each:

  1. 10.77.55.3, mask 255.255.255.0
  2. 172.30.99.4, mask 255.255.255.0
  3. 192.168.6.54, mask 255.255.255.0
  4. 10.77.3.14, mask 255.255.0.0
  5. 172.22.55.77, mask 255.255.0.0
  6. 1.99.53.76, mask 255.0.0.0
Address, maskWorkingSubnet IDBroadcast
10.77.55.3, 255.255.255.0easy mask: copy, then 0 or 25510.77.55.010.77.55.255
172.30.99.4, 255.255.255.0easy mask: copy, then 0 or 255172.30.99.0172.30.99.255
192.168.6.54, 255.255.255.0easy mask: copy, then 0 or 255192.168.6.0192.168.6.255
10.77.3.14, 255.255.0.0easy mask: copy, then 0 or 25510.77.0.010.77.255.255
172.22.55.77, 255.255.0.0easy mask: copy, then 0 or 255172.22.0.0172.22.255.255
1.99.53.76, 255.0.0.0easy mask: copy, then 0 or 2551.0.0.01.255.255.255

The interesting octet

Every other mask has one octet that's neither 255 nor 0. These are the difficult masks, and that one octet is the interesting octet, the only one with real maths in it. (Easy, difficult, interesting and the magic number below are labels for this method, not official terms.) A mask can't have two, because its 1s all come first.

The interesting octet is predictable because every subnet of a classful network uses the same mask, the assumption every page has made so far. Take Class B network 172.16.0.0 and try four masks. The subnet IDs' third octets fall in a pattern: multiples of 128, 64, 32 and 16:

MaskSubnetsThird-octet values of the subnet IDs
255.255.128.020, 128
255.255.192.040, 64, 128, 192
255.255.224.080, 32, 64, 96, 128, 160, 192, 224
255.255.240.0160, 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240

It works kind of like a car park with bays numbered in equal blocks: bays 0 to 63 on level 1, 64 to 127 on level 2, 128 to 191 on level 3. Knowing your bay number, you know your level: the block your number falls in. (Where it stops: a car park uses its first and last bay on every level. A subnet keeps its first number as its ID and its last as its broadcast.)

So finding the subnet ID means finding the right multiple. For each octet:

  1. Mask octet 255: copy the address's decimal value.
  2. Mask octet 0: write 0.
  3. Otherwise, this is the interesting octet. Calculate the magic number, 256 − the mask octet. Then write the multiple of the magic number that is closest to the address's value without going over it.

The magic number is simply the gap from one subnet ID to the next: the block size. Take 130.4.102.1, mask 255.255.240.0. The first two mask octets are 255, so copy 130.4. The fourth is 0, so write 0. The third, 240, is interesting: 256 − 240 = 16. Count the multiples of 16 from 0, and do start at 0: 0, 16, 32, 48, 64, 80, 96, 112. The closest to 102 without going over is 96, so the subnet ID is 130.4.96.0.

There's nothing magic about the magic number. It just sounds better than "the gap".

Another: 192.168.5.77, mask 255.255.255.224. Copy the first three octets. The fourth is interesting: 256 − 224 = 32, and the multiples are 0, 32, 64, 96 and so on. The closest to 77 without going over is 64, so the subnet ID is 192.168.5.64. And yesterday's whiteboard numbers, 172.16.150.41 with 255.255.192.0: 256 − 192 = 64, the multiples are 0, 64, 128 and 192, and 150 falls in the block 128 to 191, so 172.16.128.0, the same answer 04.3 found in binary. Two masks make the counting short: with 128 the only multiples are 0 and 128, and with 254 they're every even number.

That last one is the trap on the boundary. When the address's value in the interesting octet is exactly a multiple of the magic number, "closest without going over" is that multiple itself: the address is in the block that starts there, not the one before. It's the subnet ID itself only if every octet after the interesting one is 0. Take 192.168.5.96 with a /27 mask: it isn't in the block 64 to 95, it starts the next one, 96 to 127, and as that subnet's ID it can't be a host's address. But 130.4.96.7 with 255.255.240.0 is an ordinary host in 130.4.96.0: its third octet sits on the block start, and its fourth octet isn't 0.

The next block starts at 96. The address didn't arrive early; it arrived first.

The broadcast: ID plus block, minus 1

The broadcast starts from the subnet ID. If you only have an address, find its subnet ID first. Then, for each octet:

  1. Mask octet 255: copy the subnet ID's value.
  2. Mask octet 0: write 255.
  3. The interesting octet: the subnet ID's value, plus the magic number, minus 1.

The mask hasn't changed, so neither has the magic number: if you've just found the subnet ID, you already know it. For 130.4.96.0 with 255.255.240.0: copy 130.4, write 255 in the fourth octet, and in the third, 96 + 16 − 1 = 111. The broadcast is 130.4.111.255. For 192.168.5.64 with 255.255.255.224: copy the first three, and in the fourth, 64 + 32 − 1 = 95: 192.168.5.95. The broadcast sits one below the next subnet's ID. Both, octet by octet:

OctetMaskAddressSubnet IDBroadcast
first255130copy: 130copy: 130
second2554copy: 4copy: 4
third240 (interesting: 256 − 240 = 16)102multiple of 16 not over 102: 9696 + 16 − 1 = 111
fourth01write 0write 255
Result255.255.240.0130.4.102.1130.4.96.0130.4.111.255
OctetMaskAddressSubnet IDBroadcast
first255192copy: 192copy: 192
second255168copy: 168copy: 168
third2555copy: 5copy: 5
fourth224 (interesting: 256 − 224 = 32)77multiple of 32 not over 77: 6464 + 32 − 1 = 95
Result255.255.255.224192.168.5.77192.168.5.64192.168.5.95

The range works as in 04.3: add 1 to the subnet ID's fourth octet for the first usable address, and subtract 1 from the broadcast's fourth octet for the last. Six difficult masks to try, subnet ID and broadcast for each:

  1. 10.77.55.3, mask 255.248.0.0
  2. 172.30.99.4, mask 255.255.192.0
  3. 192.168.6.54, mask 255.255.255.252
  4. 10.77.3.14, mask 255.255.128.0
  5. 172.22.55.77, mask 255.255.254.0
  6. 1.99.53.76, mask 255.255.255.248
Address, maskWorkingSubnet IDBroadcast
10.77.55.3, 255.248.0.0second octet: 256 − 248 = 8; 72 is the multiple not over 77; 72 + 8 − 1 = 7910.72.0.010.79.255.255
172.30.99.4, 255.255.192.0third octet: 256 − 192 = 64; 64 is the multiple not over 99; 64 + 64 − 1 = 127172.30.64.0172.30.127.255
192.168.6.54, 255.255.255.252fourth octet: 256 − 252 = 4; 52 is the multiple not over 54; 52 + 4 − 1 = 55192.168.6.52192.168.6.55
10.77.3.14, 255.255.128.0third octet: 256 − 128 = 128; 0 is the multiple not over 3; 0 + 128 − 1 = 12710.77.0.010.77.127.255
172.22.55.77, 255.255.254.0third octet: 256 − 254 = 2; 54 is the multiple not over 55; 54 + 2 − 1 = 55172.22.54.0172.22.55.255
1.99.53.76, 255.255.255.248fourth octet: 256 − 248 = 8; 72 is the multiple not over 76; 72 + 8 − 1 = 791.99.53.721.99.53.79

Getting fast

Practise in two phases. While learning, aim for 90% correct at any speed, with any help. Before the exam, aim for 100%, in 20 to 30 seconds a problem (subnet ID, broadcast and range), with just your head and a notepad.

The decimal method needs the mask in dotted decimal, so if a question gives a prefix like /20, convert it first (04.2): /20 is 255.255.240.0. Some people would rather memorise than calculate, and keep a table like this one, which gives the magic number straight from the prefix. Use it, ignore it, or make your own:

Mask value in the interesting octetMagic numberPrefix, if octet 2 is interestingPrefix, if octet 3 is interestingPrefix, if octet 4 is interesting
128128/9/17/25
19264/10/18/26
22432/11/19/27
24016/12/20/28
2488/13/21/29
2524/14/22/30
2542/15/23

The ruler below does the decimal method for any Class A, B or C address with a mask from the class's own length to /30, with the blocks of the interesting octet drawn to scale, and checks the answer in binary the 04.3 way. Here it is for 172.16.150.41 with mask 255.255.192.0:

Interactive tool: The block ruler Address 172.16.150.41 Mask 255.255.192.0 172.16.150.41, mask 255.255.192.0 (/18) first octet second octet third octet fourth octet Mask 255 255 192 0 Action copy copy magic 64 0, or 255 Subnet ID 172 16 128 0 Broadcast 172 16 191 255 Magic number 256 − 192 = 64. 150 falls in the block 128 to 191. Subnet ID 172.16.128.0, broadcast 172.16.191.255 (128 + 64 − 1 = 191

Sam reworks yesterday's whiteboard numbers in decimal: magic 64, 150 falls in the block 128 to 191, so 172.16.128.0 and 172.16.191.255. Maya checks it the binary way, and the two agree.

Five lines to keep

  1. Easy masks (only 255s and 0s): copy the octets where the mask is 255; write 0 for the ID and 255 for the broadcast where it's 0.
  2. A difficult mask has one interesting octet, neither 255 nor 0, and it needs the magic number: 256 minus that mask octet.
  3. Subnet ID, interesting octet: the multiple of the magic number closest to the address's value in that octet without going over, counting from 0.
  4. Broadcast, interesting octet: the subnet ID's value plus the magic number, minus 1.
  5. Convert a prefix mask to dotted decimal first, and check a doubtful answer in binary.

Next, 04.5: every subnet so far has had the same mask. A WAN link needs 2 addresses and head office's Staff VLAN about 200. Do they have to be the same size?

The interactive lesson

The whole lesson, with its drawings and its questions. Free with a Daveth account.

Open the lesson