<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>Garvit Singla - Subnetting</title>
    <subtitle>Systems programming, network architecture, and engineering thoughts by Garvit Singla.</subtitle>
    <link rel="self" type="application/atom+xml" href="/blog/tags/subnetting/atom.xml"/>
    <link rel="alternate" type="text/html" href="/blog"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2026-06-12T00:00:00+00:00</updated>
    <id>/blog/tags/subnetting/atom.xml</id>
    <entry xml:lang="en">
        <title>You suck at Subnetting</title>
        <published>2026-06-12T00:00:00+00:00</published>
        <updated>2026-06-12T00:00:00+00:00</updated>
        
        <author>
          <name>
            Garvit Singla
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="/blog/you-suck-at-subnetting/"/>
        <id>/blog/you-suck-at-subnetting/</id>
        
        <content type="html" xml:base="/blog/you-suck-at-subnetting/">&lt;p&gt;I was studying for my Computer Networks exam late at night, and I came across a topic that almost every computer science student dreads at first: &lt;strong&gt;Subnetting&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Most textbooks throw binary math at you right away: &lt;em&gt;255.255.255.192, AND operations, borrow 3 bits, calculate magic numbers&lt;/em&gt;. But when you strip away the convoluted formulas, subnetting is just a clean, logical puzzle of organizing computers into neighborhoods.&lt;/p&gt;
&lt;p&gt;Here is the intuition behind how a single IPv4 address block is partitioned across different departments, branches, and organizations without burning through scarce address space.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;the-core-problem-why-subnet-at-all&quot;&gt;The Core Problem: Why Subnet at All?&lt;/h2&gt;
&lt;p&gt;An IPv4 address consists of &lt;strong&gt;32 bits&lt;/strong&gt;, typically written in dotted-decimal format:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;192.168.1.1  =&amp;gt;  11000000 . 10101000 . 00000001 . 00000001&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In the early days of the Internet, addresses were categorized into rigid classes (Class A, Class B, Class C). If a company needed 300 IP addresses, a Class C network (254 usable hosts) was too small, so they were granted a Class B network (65,534 usable hosts).&lt;/p&gt;
&lt;p&gt;The result? Over &lt;strong&gt;65,000 addresses were completely wasted&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Subnetting—and specifically &lt;strong&gt;Classless Inter-Domain Routing (CIDR)&lt;/strong&gt;—was invented to solve this exact problem by decoupling network boundaries from octet octets.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;anatomy-of-an-ip-address-network-vs-host&quot;&gt;Anatomy of an IP Address: Network vs Host&lt;/h2&gt;
&lt;p&gt;Every IP address has two responsibilities:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Network ID&lt;/strong&gt;: Which street or neighborhood the packet belongs to.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Host ID&lt;/strong&gt;: Which specific apartment unit on that street receives the packet.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The &lt;strong&gt;Subnet Mask&lt;/strong&gt; tells routers where the Network ID ends and where the Host ID begins:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;IP Address:   192.168.1.50   -&amp;gt;  11000000.10101000.00000001.00110010&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Subnet Mask:  255.255.255.0  -&amp;gt;  11111111.11111111.11111111.00000000&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                                 [------- Network ID -------] [ Host ]&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When you see &lt;code&gt;/24&lt;/code&gt; (CIDR notation), it literally means: &lt;strong&gt;the first 24 bits are fixed as the network prefix&lt;/strong&gt;. The remaining 8 bits ($32 - 24 = 8$) are left for hosts:&lt;/p&gt;
&lt;p&gt;$$\text{Usable Hosts} = 2^{\text{host bits}} - 2 = 2^8 - 2 = 254$$&lt;/p&gt;
&lt;p&gt;Why subtract 2?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;All 0s in host portion&lt;/strong&gt;: Represents the Network Address itself.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;All 1s in host portion&lt;/strong&gt;: Represents the Broadcast Address for everyone in that subnet.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;borrowing-bits-the-subnetting-trick&quot;&gt;Borrowing Bits: The Subnetting Trick&lt;/h2&gt;
&lt;p&gt;Suppose your organization is assigned &lt;code&gt;192.168.1.0/24&lt;/code&gt;, but you have 4 separate teams:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Engineering (50 people)&lt;/li&gt;
&lt;li&gt;Design (25 people)&lt;/li&gt;
&lt;li&gt;Sales (20 people)&lt;/li&gt;
&lt;li&gt;Operations (15 people)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Instead of begging for 4 separate Class C ranges, we &lt;strong&gt;borrow bits from the host portion&lt;/strong&gt;:&lt;/p&gt;
&lt;p&gt;To create at least 4 subnets, we need $2^n \ge 4 \implies n = 2$ bits.&lt;/p&gt;
&lt;p&gt;Now our subnet mask increases from &lt;code&gt;/24&lt;/code&gt; to &lt;code&gt;/26&lt;/code&gt; (&lt;code&gt;24 + 2 = 26&lt;/code&gt;):&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;New Mask: 255.255.255.192 (/26)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Remaining Host bits: 32 - 26 = 6 bits&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Hosts per subnet: 2^6 - 2 = 62 usable hosts&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Each subnet has a step size (block size) of $256 - 192 = 64$:&lt;/p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th style=&quot;text-align: left&quot;&gt;Subnet&lt;/th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Network Address&lt;/th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Usable Host Range&lt;/th&gt;&lt;th style=&quot;text-align: left&quot;&gt;Broadcast Address&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Engineering&lt;/strong&gt;&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;192.168.1.0/26&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;192.168.1.1&lt;/code&gt; – &lt;code&gt;192.168.1.62&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;192.168.1.63&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Design&lt;/strong&gt;&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;192.168.1.64/26&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;192.168.1.65&lt;/code&gt; – &lt;code&gt;192.168.1.126&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;192.168.1.127&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Sales&lt;/strong&gt;&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;192.168.1.128/26&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;192.168.1.129&lt;/code&gt; – &lt;code&gt;192.168.1.190&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;192.168.1.191&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Operations&lt;/strong&gt;&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;192.168.1.192/26&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;192.168.1.193&lt;/code&gt; – &lt;code&gt;192.168.1.254&lt;/code&gt;&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;&lt;code&gt;192.168.1.255&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;p&gt;Zero overlap, complete broadcast isolation, and optimal resource utilization.&lt;/p&gt;
&lt;hr /&gt;
&lt;h2 id=&quot;the-rule-of-thumb-for-your-next-exam-or-interview&quot;&gt;The Rule of Thumb for Your Next Exam or Interview&lt;/h2&gt;
&lt;p&gt;Whenever you need to calculate subnets quickly in your head:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Identify the number of hosts required.&lt;/li&gt;
&lt;li&gt;Find the smallest power of 2 that satisfies: $2^h - 2 \ge \text{required hosts}$.&lt;/li&gt;
&lt;li&gt;Your CIDR prefix will be $32 - h$.&lt;/li&gt;
&lt;li&gt;Your block size is always $2^h$.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Next time someone tells you subnetting is hard, remember it’s just cutting a pie into powers of two.&lt;/p&gt;
</content>
        
    </entry>
</feed>
