SideQuest / Networking

Subnetting, explained with light switches

No maths background needed. Flip switches, move a fence, and watch one network split into four. Then find which subnet any device belongs to.

You run a small office with four teams. Each team has up to 50 devices: laptops, phones, a printer. You want every team on its own network, so one team’s problems don’t spill into the others.

Your router gives out addresses from one block: 192.168.1.0/24. Subnetting is cutting that one block into smaller blocks. Here, you cut it into four, one per team.

That’s the whole job. The rest of this page shows you how to make the cut. You won’t memorise formulas. You’ll flip switches and move a fence.

Picture a street. An IP address works like a postal address. One part says which street. The rest says which house on that street. Subnetting puts up fences to turn one long street into several shorter ones.

Step 0: What an IP address is for

Every device on a network, whether it’s a laptop, a phone, a printer or a server, needs an IP address, so messages know where to go. Networking people call any device with an address a host.

An IP address is four numbers separated by dots, like 192.168.1.70. It looks like one long number, but it has two parts:

  • The network part says which network the device is on: the street.
  • The host part says which device it is on that network: the house.

Press the button and watch four addresses split apart.

Look inside an address
  • Your laptop 192.168.1.70 Street 192.168.1, house 70
  • The office printer 192.168.1.20 Street 192.168.1, house 20
  • Your colleague's phone 192.168.1.133 Street 192.168.1, house 133
  • A website 142.250.80.46 A different street entirely

Four devices, four addresses. Press the button to see what the numbers mean.

That split is the most important idea on this page:

  • Same network part = same street. Those devices can send messages straight to each other.
  • Different network part = different street. Messages must go through a router, the device that connects streets together.

But where exactly does the network part end and the host part begin? Above, it was after the third number, but it doesn’t have to be. Choosing where to split is what subnetting is. To see how you choose, you need to look one level down, at the switches inside each number.

Step 1: A number is a row of light switches

Computers don’t store the number 70. They store a row of switches. Each switch is either off (0) or on (1). Each switch is worth double the one on its right. Add up the switches that are on, and you get the number.

Make each number below, then press Count from 0 to 255.

Try itTap a switch to flip it

All switches off=0

Can you make570192255?

Each switch is worth double the one on its right. Add up the switches that are on, and you get the number.

Two things to take away:

  • 8 switches make 256 different patterns, so they can show every number from 0 to 255.
  • Every extra switch doubles the patterns. 1 switch makes 2, 2 switches make 4, 3 make 8. Remember this one. It’s the whole secret of subnetting.

An address like 192.168.1.70 is just four rows of 8 switches, 32 in total. Each number between the dots is one row.

Step 2: The slash number is a fence

The /24 at the end of 192.168.1.0/24 says where to put a fence among those 32 switches. It counts switches from the left.

  • Switches left of the fence say which street. Every house on a street shares them.
  • Switches right of the fence say which house on that street.

At /24, the first 24 switches (192.168.1) sit left of the fence and stay locked. (Who locks them? That’s Step 3.) The last 8 number the houses. That gives you one street with 256 houses.

Now the trick: move the fence to the right. Each switch the fence jumps over stops numbering houses and starts numbering streets. Press Play, or drag the slider yourself, and watch the houses regroup.

Move the fence/24

1 street of 256 houses

0 switches pick the street, 8 switches number the houses.

Each step right does two things at once. The number of streets doubles, and the houses on each street halve. The total never changes. It is always the same 256 addresses with more fences between them.

At /26, 2 switches pick the street. 2 switches make 4 patterns (00, 01, 10, 11), so you get 4 streets, one per team. The other 6 switches number the houses: 64 on each street.

Bigger slash number = more fences = smaller streets. A /27 is smaller than a /26. This is the part that trips everyone up, so read it twice.

Step 3: Who locks the first switches?

In the fence above, you couldn’t touch the first 24 switches. Why 24, and who decided?

Whoever gave you the address block decides. That might be your internet provider, your company’s network team, or the factory settings of your home router. They hand you a block with a fence already in place, like 192.168.1.0/24. Inside it, you can move the fence right to make smaller streets. You can never move it left, because the switches on the left belong to someone else’s plan.

The old rule: address classes

In the early internet, nobody chose where the fence went. The first number of the address decided it. These groups are called address classes, and you’ll still meet them in courses, exams and old documentation:

ClassFirst numberFirst switchesDefault fenceLocked (network part)Free (host part)
A1 to 1260.../8first numberlast three numbers
B128 to 19110../16first two numberslast two numbers
C192 to 223110./24first three numberslast number
D224 to 2391110nonemulticast, for groupsno devices
E240 to 2551111nonereserved for experimentsno devices

You only need the first number to know the class, because the class is set by the first few switches. Try it:

Old-school address classesOnly the first number matters
.x.x.x
Try:

Its first 8 switches. The leading switches decide the class:

Default fence
Default mask
Devices per network

So 192.168.1.0 is Class C, which is why its default fence is /24 and the first three numbers are locked. Most home routers keep that default, which is why you see 255.255.255.0 everywhere.

Why classes were retired. They were far too rigid. A company that needed 300 addresses was too big for a Class C (254 devices), so it got a whole Class B: 65,534 addresses, most of them wasted. The internet started running out. In 1993, classes were replaced with CIDR (Classless Inter-Domain Routing): the fence can go after any switch, and the slash number says exactly where. A company that needs 500 addresses gets a /23, and nothing is wasted.

Today: the slash number tells you where the fence is, whatever the class. The class only tells you the old default. If you see 10.1.2.0/24, it’s a Class A address with a /24 fence, and the /24 is what counts.

The slash is shorthand for the subnet mask

Before slashes, the fence was written as a subnet mask: four numbers, like 255.255.255.0. Many devices and settings screens still ask for it that way. It describes the same fence:

  • Write a 1 for every switch left of the fence (network) and a 0 for every switch right of it (host).
  • Read those 32 switches as four numbers, exactly like Step 1.

/24 is 24 ones and 8 zeros: 11111111.11111111.11111111.00000000, which reads as 255.255.255.0. The slash version is just shorter to write. Slide through the converter and you’ll see the pattern:

Slash to mask/24 = 255.255.255.0
Jump to:

    The only 9 numbers a mask can use (switches on, from the left):

    0011282192322442405248625272548255

    Start at 128 and keep adding half as much: 128, +64 = 192, +32 = 224, +16 = 240 ... It's just the switches from Step 1 turning on one by one.

    The quick method, no binary needed:

    1. Divide the slash number by 8. The answer is how many 255s come first.
    2. The remainder is how many switches are on in the next number. Look it up on the ladder: 1 = 128, 2 = 192, 3 = 224, 4 = 240, 5 = 248, 6 = 252, 7 = 254.
    3. Everything after that is 0.

    Example, /26: 26 / 8 = 3 remainder 2. Three 255s, then 2 on the ladder is 192. So /26 = 255.255.255.192.

    Example, /20: 20 / 8 = 2 remainder 4. Two 255s, then 240, then 0. So /20 = 255.255.240.0.

    Going the other way is just as easy: count 8 for each 255, then add the ladder position of the next number. 255.255.255.224 = 8 + 8 + 8 + 3 = /27.

    Bonus: subtract the last non-zero mask number from 256 to see how often streets start. 256 - 192 = 64, so /26 streets start at 0, 64, 128 and 192, exactly what you saw in Step 2.

    Step 4: Two houses on every street are taken

    Zoom into the second street, 192.168.1.64/26. Press Walk the street and watch the house switches as you go.

    Walk one street192.168.1.64/26

    192.168.1.64

    64 houses - 1 name sign - 1 megaphone = 62 homes for devices

    • The first house has every house switch off. It is the street’s name sign, called the network address. No device lives there.
    • The last house has every house switch on. It is a megaphone: send a message to it and every house on the street hears it. This is the broadcast address. No device lives there either.

    So each /26 street has 64 addresses, and 62 of them can go to devices. Each team needs 50 devices plus 1 router, 51 in total. It fits.

    You can go back to the fence in Step 2 and tick Mark the 2 reserved houses to see the sign and the megaphone on every street.

    Step 5: Which street does a device live on?

    A laptop has the address 192.168.1.70/26. Which team’s street is it on? Turn 70 into switches, look at the switches left of the fence, and you have your answer.

    Find the streetFence at /26
    192.168.1.
    Or try:

    1 Turn the number into switches

    128?64?32?16?8?4?2?1?

    Left to place: 70

      2 The 2 switches left of the fence pick the street

      00 .0 to .63
      01 .64 to .127
      10 .128 to .191
      11 .192 to .255

      Once it clicks, use the shortcut. At /26, a new street starts every 64 addresses: at 0, 64, 128 and 192. 70 is between 64 and 127, so it lives on the street that starts at 64.

      Remember your colleague’s phone from Step 0, at 192.168.1.133? With the fence at /24, it shared a street with your laptop. With the fence at /26, 133 falls between 128 and 191, so it’s now on a different street from the laptop at .70. The addresses didn’t change. Only the fence moved.

      The four streets, in proper notation

      Here is your finished office plan. Every address starts with 192.168.1., so the table shows only the last number.

      TeamStreet (network)Homes for devicesMegaphone (broadcast)
      1192.168.1.0/26.1 to .62.63
      2192.168.1.64/26.65 to .126.127
      3192.168.1.128/26.129 to .190.191
      4192.168.1.192/26.193 to .254.255

      The streets sit side by side. None overlap, and none leave a gap.

      Step 6: Watch it all work together

      Here’s why all of this matters. Every device gets three settings, usually handed out automatically by the router (a service called DHCP):

      • its IP address: which house it is,
      • its subnet mask: where the fence is, so it knows which part of an address is the street,
      • its default gateway: the router’s door on its own street.

      With those three settings, a device makes one decision before every message it sends: “Is the destination on my street?” If yes, it delivers the message directly. If no, it hands the message to the gateway and lets the router deal with it.

      Below are two of the office’s streets with a router between them. Press Send, or try the three examples.

      Send a messageTwo /26 streets, one router
      Try:

      Street A (team 1)

      192.168.1.0/26

      Laptop .10
      Printer .20

      Street B (team 2)

      192.168.1.64/26

      Laptop .70
      Phone .80

      Router

      Door on A.1 Door on B.65

      Its table, by network address:

      • 192.168.1.0/26use door .1
      • 192.168.1.64/26use door .65

      The sender's network settings (what you'd see on the device)

      IP address
      Subnet mask
      255.255.255.192 (/26)
      Default gateway

        Look at what each address type did:

        • The host part let each device tell the others apart on its own street.
        • The network address (the street sign) is how the router lists streets in its table. It never belongs to a device, because it names the whole street.
        • The broadcast address (the megaphone) reached every device on one street, and the router stopped it there.
        • The gateway has to be a home on the sender’s own street. The laptop at .70 can use .65. It can’t use .1: that’s on another street, and a device can only reach its own street directly.

        Giving the router the first home, like .1 or .65, is a common habit, not a rule. Any home on the street will do.

        See your own settings. On Windows, open a terminal and run ipconfig. On macOS or Linux, run ip addr or open your network settings. You’ll find your IP address, your subnet mask (or a / number) and your default gateway: the same three settings as the simulator.

        The real words, decoded

        You now understand subnetting. Networking people just use different words for the same ideas:

        What we called itWhat networking people call it
        StreetNetwork, or subnet
        HouseHost, the address of one device
        The fence, like /26Prefix length, written in CIDR notation
        The fence as four numbers, like 255.255.255.192Subnet mask
        The old default fence, set by the first numberAddress class (A, B, C)
        SwitchBit
        Street switchesNetwork bits. The ones you took from the houses are subnet bits
        House switchesHost bits
        Street name signNetwork address
        MegaphoneBroadcast address
        The street’s gateDefault gateway, a router interface

        CIDR stands for Classless Inter-Domain Routing. It is just the name for writing an address with a slash. See RFC 4632 if you want the formal version.

        Cheat sheet

        FenceHouse switchesAddresses per streetHomes for devicesStreets inside a /24
        /2482562541
        /2571281262
        /26664624
        /27532308
        /284161416

        The rule behind the table: house switches = 32 minus the slash number. Each house switch doubles the addresses, so a street has 2 to the power of that many addresses. Take away 2 for the sign and the megaphone.

        Two special cases skip the “take away 2” rule: a /31 link between two routers, and a /32 that means a single address. You won’t need them for an office.

        Your turn

        Use a fresh block, 10.20.30.0/24. Try each question before you open the worked answers. If you get one wrong, the feedback tells you why.

        1. Choose the size

        Split 10.20.30.0/24 into four equal subnets. Each must fit 50 devices and one router interface. Choose the smallest block that fits.

        2. Find the network
        3. Choose the gateway

        Worked answers
        1. /26. Four blocks of 64 addresses fit inside a /24. Each offers 62 usable host addresses, enough for 50 devices and one router interface.
        2. 10.20.30.128/26. The last number, 150, falls in the 128-191 block. Its usable range is .129-.190, and its broadcast address is .191.
        3. 10.20.30.65/26. Both .65 and .70 belong to the .64-.127 block. The .1 address belongs to another /26, and .127 is broadcast. Address arithmetic checks that the gateway is in range; you must also configure that address on a router.

        Check your plan with the subnet checker

        You don’t need to install anything. Type any block and any device below and the checker does the maths in your browser. It’s filled in with the practice answers to start with.

        Subnet checkerRuns in your browser. Nothing is sent anywhere.

        1 Split a block

        SubnetUsable addressesBroadcastTotal / usable

        2 Check a device and its gateway

        Network
        Subnet mask
        Usable addresses
        Broadcast
        This address is

        Try these, and predict the answer before you look:

        1. Change the gateway to 10.20.30.1. It should say No, because .1 is on a different street from .70.
        2. Change Split into to /27. You get eight smaller streets with 30 usable addresses each. That suits small teams, but not 50 devices plus a router.
        3. Type 10.20.30.150/26 as the device. Its network should be 10.20.30.128/26, the answer to practice question 2.
        4. Type a block with a typo, like 10.20.30.5/24. The checker tells you which network address you probably meant.
        Prefer code? The same checks in Python

        If you have Python 3, save this as subnet_check.py and run python subnet_check.py (or python3 subnet_check.py on some systems). It uses Python’s built-in ipaddress module and only calculates; it doesn’t change your network settings.

        from ipaddress import ip_address, ip_interface, ip_network
        
        office = ip_network("10.20.30.0/24")
        
        for subnet in office.subnets(new_prefix=26):
            hosts = list(subnet.hosts())
            print(f"{subnet}: {subnet.num_addresses} total, {len(hosts)} usable")
        
        laptop = ip_interface("10.20.30.70/26")
        gateway = ip_address("10.20.30.65")
        
        print("Laptop network:", laptop.network)
        print("Gateway in same subnet:", gateway in laptop.network)
        print("Network for .150:", ip_interface("10.20.30.150/26").network)

        Expected output:

        10.20.30.0/26: 64 total, 62 usable
        10.20.30.64/26: 64 total, 62 usable
        10.20.30.128/26: 64 total, 62 usable
        10.20.30.192/26: 64 total, 62 usable
        Laptop network: 10.20.30.64/26
        Gateway in same subnet: True
        Network for .150: 10.20.30.128/26

        Before you build it for real

        A plan on paper doesn’t create four networks. In a lab or simulator, put each team on its own network segment or VLAN, give the router an address on each street, and give every device its address, mask and gateway. Then add routing and firewall rules for the traffic you want to allow. A subnet on its own doesn’t block anything.

        Carry this into your AWS lab

        The fence works the same way in AWS: a /26 still holds 64 addresses. But AWS keeps 5 addresses on every subnet, not 2: the first four and the last one. That leaves 59 for your resources. AWS networks also have no megaphone, because they don’t support broadcast. AWS documents these reserved addresses here.

        The AWS Day 3 subnet lab uses a /16 network and /20 subnets. Same method: 32 - 20 = 12 house switches, and 12 switches make 4,096 addresses. Those streets start every 16 in the third number: 172.31.0.0/20, 172.31.16.0/20, 172.31.32.0/20, and so on.