<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ganesh Pawar</title>
    <description>The latest articles on DEV Community by Ganesh Pawar (@frnd4gan).</description>
    <link>https://dev.to/frnd4gan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2594695%2Ffddc6f83-806b-464a-b826-c66a8d992f62.jpg</url>
      <title>DEV Community: Ganesh Pawar</title>
      <link>https://dev.to/frnd4gan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/frnd4gan"/>
    <language>en</language>
    <item>
      <title>CIDR and Subnet Mask</title>
      <dc:creator>Ganesh Pawar</dc:creator>
      <pubDate>Sun, 11 Oct 2026 09:29:33 +0000</pubDate>
      <link>https://dev.to/frnd4gan/cidr-and-subnet-mask-1ki3</link>
      <guid>https://dev.to/frnd4gan/cidr-and-subnet-mask-1ki3</guid>
      <description>&lt;p&gt;Hello All,&lt;/p&gt;

&lt;p&gt;I would like to share something I learned while preparing for the AWS Certified Advanced Networking - Specialty (ANS-C01) certification.&lt;/p&gt;

&lt;p&gt;One of the topics that took me some time to fully understand was:&lt;/p&gt;

&lt;p&gt;Decimal-to-binary conversion&lt;br&gt;
How CIDR notation works&lt;br&gt;
How to determine the network and broadcast address of a subnet&lt;/p&gt;

&lt;p&gt;This may be a topic that others have already covered, but I thought it would still be helpful to share my learning journey.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Decimal to Binary&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Computers do not understand decimal numbers like 192.168.31.1&lt;br&gt;
Computers work with bits (0s and 1s), so the IP address must first be converted into binary before subnet calculations can be performed.&lt;br&gt;
Rules:&lt;br&gt;
    If the remaining number is &amp;gt;= column value → write 1&lt;br&gt;
    If the remaining number is &amp;lt; column value → write 0&lt;/p&gt;

&lt;p&gt;Each octet contains 8 bits.&lt;/p&gt;

&lt;p&gt;The place values for an octet are: 128 64 32 16 8 4 2 1&lt;/p&gt;

&lt;p&gt;Each position can be either:&lt;br&gt;
1 = include the value&lt;br&gt;
0 = do not include the value&lt;/p&gt;

&lt;p&gt;Example : Convert 192 to Binary&lt;br&gt;
Value   Compare Bit Remaining&lt;br&gt;
128 192 ≥ 128   1   64&lt;br&gt;
64  64 ≥ 64     1   0&lt;br&gt;
32  0 &amp;lt; 32      0   0&lt;br&gt;
16  0 &amp;lt; 16      0   0&lt;br&gt;
8   0 &amp;lt; 8       0   0&lt;br&gt;
4   0 &amp;lt; 4       0   0&lt;br&gt;
2   0 &amp;lt; 2       0   0&lt;br&gt;
1   0 &amp;lt; 1       0   0&lt;br&gt;
Result:11000000&lt;/p&gt;

&lt;p&gt;CIDR:  192.168.31.1/18 &lt;br&gt;
Let's try to fetch IP range for above CIDR.&lt;/p&gt;

&lt;p&gt;A /18 mask uses the first 18 bits for the network portion.&lt;br&gt;
In the third octet, the mask is 192 (11000000 in binary).&lt;br&gt;
This creates subnet blocks of 64 in the third octet:&lt;br&gt;
0-63&lt;br&gt;
64-127&lt;br&gt;
128-191&lt;br&gt;
192-255&lt;/p&gt;

&lt;p&gt;Since the third octet is 31, it falls within the 0-63 block.&lt;/p&gt;

&lt;p&gt;Conceptual Steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Convert IP address to a 32-bit binary number. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;E.g. 192.168.31.1/18 Binary is 11000000.10101000.00011111.00000001&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Create the subnet mask from the CIDR prefix.
o   For example, /18 means first 18 bits are 1, rest 14 bits are 0.
11111111.11111111.11000000.00000000&lt;/li&gt;
&lt;li&gt; Perform a bitwise AND operation between the IP and the subnet mask.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Subnet mask in binary: 11111111.11111111.11000000.00000000&lt;br&gt;
IP address in binary:     11000000.10101000.00011111.00000001&lt;br&gt;
AND bitwise Operator results: 11000000.10101000.0000000.0000000&lt;br&gt;
This zeroes out the host bits, leaving only the network bits.&lt;/p&gt;

&lt;p&gt;The bitwise AND operator is used to compare two binary numbers bit by bit. For each bit, the result is 1 if both bits are 1, and 0 if at least one of the bits is 0.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Convert the result back to the dotted decimal format.
o   This is the network address.
which is 11000000.10101000.0000000.0000000
    (128+64).(128+32+8).0.0=192.168.0.0   for 192.168.31.1/18&lt;/li&gt;
&lt;li&gt;Set Host Bits to 1 to Find the Broadcast Address:
•   The broadcast address is the last address in the subnet, which is obtained by setting all the host bits (bits corresponding to the 0s in the subnet mask) to 1.
•   Since /18 leaves the last 14 bits for hosts, set those 14 host bits to 1 in the network address:
Network Address (Binary): 11000000.10101000.00000000.00000000
Set the host bits (the last 14 bits) to 1: 11000000.10101000.00111111.11111111
This binary value converts back to: 192.168.63.255&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Therefore:&lt;/p&gt;

&lt;p&gt;Network address: 192.168.0.0/18&lt;br&gt;
Broadcast address: 192.168.63.255&lt;br&gt;
Usable host range: 192.168.0.1 to 192.168.63.254&lt;/p&gt;

&lt;p&gt;For AWS VPC networking, there is one important difference from traditional networking:&lt;/p&gt;

&lt;p&gt;For the subnet 192.168.0.0/18:&lt;/p&gt;

&lt;p&gt;Type    IP AddressNetwork Address   192.168.0.0&lt;br&gt;
Broadcast Address (traditional networks)    192.168.63.255&lt;br&gt;
Traditional Usable Range    192.168.0.1 - 192.168.63.254&lt;/p&gt;

&lt;p&gt;However, in AWS VPCs, AWS reserves 5 IP addresses per subnet:&lt;/p&gt;

&lt;p&gt;Reserved Address    Purpose&lt;br&gt;
192.168.0.0 Network address&lt;br&gt;
192.168.0.1 VPC router&lt;br&gt;
192.168.0.2 Amazon DNS&lt;br&gt;
192.168.0.3 Reserved by AWS&lt;br&gt;
192.168.63.255  Network broadcast address (reserved by AWS, even though AWS does not support broadcast traffic)&lt;/p&gt;

</description>
      <category>aws</category>
      <category>cloud</category>
      <category>learning</category>
      <category>networking</category>
    </item>
  </channel>
</rss>
