<?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: Nicholas</title>
    <description>The latest articles on DEV Community by Nicholas (@heynickn).</description>
    <link>https://dev.to/heynickn</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%2F460480%2F1130e1dd-3b84-4042-a6c5-4e5b16b3b4e0.png</url>
      <title>DEV Community: Nicholas</title>
      <link>https://dev.to/heynickn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/heynickn"/>
    <language>en</language>
    <item>
      <title>Subnetting explained in Computer Networking</title>
      <dc:creator>Nicholas</dc:creator>
      <pubDate>Mon, 05 Oct 2026 14:35:28 +0000</pubDate>
      <link>https://dev.to/heynickn/subnetting-explained-in-computer-networking-5dff</link>
      <guid>https://dev.to/heynickn/subnetting-explained-in-computer-networking-5dff</guid>
      <description>&lt;h2&gt;
  
  
  Subnetting explained in Computer Networking
&lt;/h2&gt;

&lt;p&gt;If you're in the networking field, or you're currently on your journey to becoming a Network Engineer, you've definitely come across the term &lt;strong&gt;subnetting&lt;/strong&gt;. But what actually is it? That's what I'll be explaining in this blog. To be honest, subnetting confused me when I first learned it, but after some practice it's now something I find pretty easy, so if you're struggling with it right now, don't worry. I'll do my best to break it down in a way that actually makes sense.&lt;/p&gt;

&lt;p&gt;Note: You do need a basic understanding of binary to fully grasp subnetting.&lt;/p&gt;

&lt;h3&gt;
  
  
  So what is Subnetting?
&lt;/h3&gt;

&lt;p&gt;Subnetting is the process of splitting a larger Internet Protocol (IP) network into smaller networks, which are called &lt;strong&gt;subnets&lt;/strong&gt;. Makes sense, right? So what does that look like in practice?&lt;/p&gt;

&lt;p&gt;Well, before answering that, we need to look at the structure of a typical IP address. Let's use this one as an example:&lt;/p&gt;

&lt;p&gt;192.168.1.0&lt;/p&gt;

&lt;p&gt;What does each number between the dots (&lt;code&gt;.&lt;/code&gt;) mean? Each one represents an &lt;strong&gt;octet&lt;/strong&gt;, which is exactly &lt;strong&gt;8 bits&lt;/strong&gt; in length. An IPv4 address is always made up of 4 octets, so every IPv4 address is &lt;strong&gt;32 bits&lt;/strong&gt; long in total (8 bits x 4 octets), which is the same as 4 bytes. With that out of the way, here's how you'll usually see this IP address written:&lt;/p&gt;

&lt;p&gt;192.168.1.0/24&lt;/p&gt;

&lt;p&gt;Now I know what you're thinking: what the hell is that &lt;code&gt;/24&lt;/code&gt;? Well, that's exactly what the next section covers.&lt;/p&gt;




&lt;h3&gt;
  
  
  The Network &amp;amp; Host Portion
&lt;/h3&gt;

&lt;p&gt;Every IP address is split into two parts: the &lt;strong&gt;network portion&lt;/strong&gt; and the &lt;strong&gt;host portion&lt;/strong&gt;. So what exactly does that mean?&lt;/p&gt;

&lt;h4&gt;
  
  
  Network Portion
&lt;/h4&gt;

&lt;p&gt;The network portion identifies which network a device belongs to.&lt;/p&gt;

&lt;h4&gt;
  
  
  Host Portion
&lt;/h4&gt;

&lt;p&gt;The host portion identifies a specific device on that network.&lt;/p&gt;

&lt;p&gt;So the &lt;code&gt;/24&lt;/code&gt; tells us that the first &lt;strong&gt;24 bits&lt;/strong&gt; of the IP address make up the &lt;strong&gt;network portion&lt;/strong&gt;. That leaves the remaining &lt;strong&gt;8 bits&lt;/strong&gt; (32 - 24 = 8) for the &lt;strong&gt;host portion&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In our example, that means the first 3 octets (3 octets x 8 bits = 24 bits) make up the network portion:&lt;/p&gt;

&lt;p&gt;192.168.1&lt;/p&gt;

&lt;p&gt;And the last octet is the host portion:&lt;/p&gt;

&lt;p&gt;0&lt;/p&gt;

&lt;p&gt;Like I mentioned earlier, the host portion identifies a specific device on a network. But you might be wondering how many devices the host portion can actually support. Well, that's easy to work out, because there's a simple formula for it:&lt;/p&gt;

&lt;p&gt;2^n-2&lt;/p&gt;

&lt;p&gt;&lt;code&gt;n&lt;/code&gt; represents the number of host bits. Host bits?? It's just a zero! Well, to make sense of this, let's convert the IP address into binary.&lt;/p&gt;

&lt;p&gt;11000000 10101000 00000001 00000000&lt;/p&gt;

&lt;p&gt;To make it easier to visualize, I'm going to highlight the network and host portion to make the distinction clear.&lt;/p&gt;

&lt;p&gt;11000000 10101000 00000001 00000000&lt;/p&gt;

&lt;p&gt;The red represents the &lt;strong&gt;network portion&lt;/strong&gt; and the blue represents the &lt;strong&gt;host portion&lt;/strong&gt;. So even though the host portion is just a &lt;code&gt;0&lt;/code&gt; in decimal, in binary it's made up of 8 bits, and those are our &lt;strong&gt;host bits&lt;/strong&gt;. Now let's go back to that formula from earlier, 2^n-2. We know &lt;code&gt;n&lt;/code&gt; is the &lt;em&gt;number of host bits&lt;/em&gt;, but why do we subtract 2? That's because every network reserves 2 addresses that can't be given to devices: the &lt;strong&gt;network address&lt;/strong&gt; and the &lt;strong&gt;broadcast address&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Note: The &lt;strong&gt;network address&lt;/strong&gt; is the first address in a network and identifies the network itself. The &lt;strong&gt;broadcast address&lt;/strong&gt; is the last address, and it's used to send traffic to every device on the network at once.&lt;/p&gt;

&lt;p&gt;Now, to answer our original question: how many devices can the host portion support? We have &lt;strong&gt;8 host bits&lt;/strong&gt;, so let's plug 8 in as &lt;code&gt;n&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;2^8-2=254&lt;/p&gt;

&lt;p&gt;And there's our answer: the &lt;code&gt;192.168.1.0/24&lt;/code&gt; network can support up to &lt;strong&gt;254 devices&lt;/strong&gt;. That's 256 addresses in total, minus the network address (&lt;code&gt;192.168.1.0&lt;/code&gt;) and the broadcast address (&lt;code&gt;192.168.1.255&lt;/code&gt;), which leaves &lt;code&gt;192.168.1.1&lt;/code&gt; to &lt;code&gt;192.168.1.254&lt;/code&gt; for our devices.&lt;/p&gt;




&lt;h3&gt;
  
  
  The problem
&lt;/h3&gt;

&lt;p&gt;To see what problems come up when a network isn't split into subnets, let's look at the example network topology below:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvjnacg8ht2uszp84ipgl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvjnacg8ht2uszp84ipgl.png" alt="Example Network Topology" width="800" height="462"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the topology we have two separate Local Area Networks (LANs), LAN1 and LAN2. Each LAN has its own router, and the two routers are connected to each other, which links the LANs together. Within each LAN, a switch is connected to the router, and the end hosts (the PCs) are connected to the switch.&lt;/p&gt;

&lt;p&gt;Let's say LAN1 is given the network &lt;code&gt;192.168.1.0/24&lt;/code&gt; and LAN2 is given &lt;code&gt;192.168.2.0/24&lt;/code&gt;. That gives each LAN 254 usable addresses, but each one only needs 3 of them: 2 for the PCs and 1 for the router, which acts as the default gateway. That leaves &lt;strong&gt;251 addresses&lt;/strong&gt; in each LAN going unused, or &lt;strong&gt;502 wasted addresses&lt;/strong&gt; across both!&lt;/p&gt;

&lt;p&gt;Note: A &lt;strong&gt;default gateway&lt;/strong&gt; is the device (usually a router) that hosts send their traffic to whenever it's meant for a different network. The gateway then forwards that traffic on towards its destination.&lt;/p&gt;

&lt;p&gt;So how do we fix this? This is where subnetting comes in. Instead of giving each LAN its own &lt;code&gt;/24&lt;/code&gt;, we can take a single network, &lt;code&gt;192.168.1.0/24&lt;/code&gt;, and split it into smaller &lt;strong&gt;subnets&lt;/strong&gt;, each with only as many addresses as a LAN actually needs.&lt;/p&gt;




&lt;h3&gt;
  
  
  Subnetting
&lt;/h3&gt;

&lt;p&gt;Before we split the network into subnets, we need to understand the &lt;strong&gt;broadcast domains&lt;/strong&gt; in our topology.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;From Wikipedia: A broadcast domain is a logical division of a computer network, in which all nodes can reach each other by broadcast at the data link layer.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here's the same topology again, but this time with each broadcast domain highlighted:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2zsk2m63xc7fptp6h682.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2zsk2m63xc7fptp6h682.png" alt="Highlighted Example Network Topology" width="800" height="490"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are three broadcast domains in the topology: one for LAN1 (pink), one for LAN2 (yellow), and one for the link between the two routers (blue). That router-to-router link is known as a &lt;strong&gt;point-to-point&lt;/strong&gt; connection, since it only ever connects two devices. Each broadcast domain needs its own subnet, so we'll need &lt;strong&gt;3 subnets&lt;/strong&gt; in total.&lt;/p&gt;

&lt;h4&gt;
  
  
  LAN1
&lt;/h4&gt;

&lt;p&gt;Let's start with LAN1. First, let's bring back the binary representation of &lt;code&gt;192.168.1.0/24&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;11000000 10101000 00000001 00000000&lt;/p&gt;

&lt;p&gt;To split this network, we'll have to &lt;strong&gt;borrow&lt;/strong&gt; some of the host bits and turn them into network bits. We can't borrow from the network portion, because those bits identify the network we've been given (&lt;code&gt;192.168.1&lt;/code&gt;), and changing them would give us a completely different network.&lt;/p&gt;

&lt;p&gt;I've already done the math, and we're going to need a &lt;code&gt;/29&lt;/code&gt; subnet for both LAN1 and LAN2. But why &lt;code&gt;/29&lt;/code&gt;, and how did I come up with that? Well, first let's look at what &lt;code&gt;/29&lt;/code&gt; means. What's the difference between 29 and 24? It's 5, so we've borrowed &lt;strong&gt;5 bits&lt;/strong&gt; from the host portion. But that still doesn't explain why we picked 29. To see why, let's look at the binary representation of &lt;code&gt;192.168.1.0&lt;/code&gt; again, this time with the borrowed bits highlighted:&lt;/p&gt;

&lt;p&gt;11000000 10101000 00000001 00000000&lt;/p&gt;

&lt;p&gt;The green bits are the 5 we've borrowed, which leaves us with just &lt;strong&gt;3 host bits&lt;/strong&gt; (blue). Now let's plug that into our formula from earlier to see how many usable addresses that gives LAN1:&lt;/p&gt;

&lt;p&gt;2^3-2=6&lt;/p&gt;

&lt;p&gt;Remember, we subtract 2 because the first and last addresses are reserved for the network and broadcast addresses. So technically this subnet gives us 8 addresses (2^3), but only 6 of them can actually be used. That means LAN1's subnet will be:&lt;/p&gt;

&lt;p&gt;192.168.1.0/29&lt;/p&gt;

&lt;p&gt;Here's what LAN1 looks like with its new subnet:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F903s97dyn7gx1lwkp5uu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F903s97dyn7gx1lwkp5uu.png" alt="LAN1" width="800" height="760"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Device&lt;/th&gt;
&lt;th&gt;IP Address&lt;/th&gt;
&lt;th&gt;Role&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;td&gt;192.168.1.0&lt;/td&gt;
&lt;td&gt;Network address&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Router1&lt;/td&gt;
&lt;td&gt;192.168.1.6&lt;/td&gt;
&lt;td&gt;Default gateway&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PC0&lt;/td&gt;
&lt;td&gt;192.168.1.1&lt;/td&gt;
&lt;td&gt;End host&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PC1&lt;/td&gt;
&lt;td&gt;192.168.1.2&lt;/td&gt;
&lt;td&gt;End host&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;td&gt;192.168.1.7&lt;/td&gt;
&lt;td&gt;Broadcast address&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;This subnet gives us 8 addresses in total (including the network and broadcast addresses), and we're using 5 of them, which leaves 3 spare (&lt;code&gt;192.168.1.3&lt;/code&gt; to &lt;code&gt;192.168.1.5&lt;/code&gt;). That's completely fine! Subnets always come in powers of 2, so you'll rarely be able to fit the exact number of hosts you need. If anything, those spare addresses give us some breathing room in case we want to add a few more devices later.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h4&gt;
  
  
  LAN2
&lt;/h4&gt;

&lt;p&gt;Since LAN2 has the same number of devices as LAN1, it can use the same &lt;code&gt;/29&lt;/code&gt; prefix. First, we need to find its network address. LAN1 has already taken the addresses from &lt;code&gt;192.168.1.0&lt;/code&gt; to &lt;code&gt;192.168.1.7&lt;/code&gt;, so LAN2's network address is simply the next address after LAN1's broadcast address: &lt;code&gt;192.168.1.8&lt;/code&gt;. Great, that's our network address sorted, but we still need to find the broadcast address.&lt;/p&gt;

&lt;p&gt;To find the broadcast address, we need to set all the host bits to 1. So let's look at &lt;code&gt;192.168.1.8&lt;/code&gt; in binary:&lt;/p&gt;

&lt;p&gt;11000000 10101000 00000001 00001000&lt;/p&gt;

&lt;p&gt;The host bits are the ones in blue, so let's set them all to 1:&lt;/p&gt;

&lt;p&gt;11000000 10101000 00000001 00001111&lt;/p&gt;

&lt;p&gt;The first 3 octets haven't changed, so we only need to focus on the last one, which is now:&lt;/p&gt;

&lt;p&gt;00001111&lt;/p&gt;

&lt;p&gt;Converting &lt;code&gt;00001111&lt;/code&gt; to decimal gives us &lt;strong&gt;15&lt;/strong&gt; (8 + 4 + 2 + 1), so LAN2's broadcast address is &lt;code&gt;192.168.1.15&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now that we have both the network and broadcast addresses, everything in between (&lt;code&gt;192.168.1.9&lt;/code&gt; to &lt;code&gt;192.168.1.14&lt;/code&gt;) can be used for the devices in LAN2.&lt;/p&gt;

&lt;p&gt;Here's what LAN2 looks like with its new subnet:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fraozrtmmxtj119pugu1p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fraozrtmmxtj119pugu1p.png" alt="LAN2" width="800" height="750"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Device&lt;/th&gt;
&lt;th&gt;IP Address&lt;/th&gt;
&lt;th&gt;Role&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;td&gt;192.168.1.8&lt;/td&gt;
&lt;td&gt;Network address&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Router0&lt;/td&gt;
&lt;td&gt;192.168.1.14&lt;/td&gt;
&lt;td&gt;Default gateway&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PC2&lt;/td&gt;
&lt;td&gt;192.168.1.9&lt;/td&gt;
&lt;td&gt;End host&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PC3&lt;/td&gt;
&lt;td&gt;192.168.1.10&lt;/td&gt;
&lt;td&gt;End host&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;td&gt;192.168.1.15&lt;/td&gt;
&lt;td&gt;Broadcast address&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h4&gt;
  
  
  Point-to-Point
&lt;/h4&gt;

&lt;p&gt;We have one more broadcast domain to cover: the link between the two routers. This point-to-point connection is different from the LANs because there are no PCs or switches on it, just the two routers, each connected by one of its interfaces. Since we only need 2 usable addresses (one for each router), we're going to use a &lt;code&gt;/30&lt;/code&gt; prefix for this subnet. That means borrowing 6 bits from the original host portion (30 - 24), one more than the &lt;code&gt;/29&lt;/code&gt;s we used for the LANs, which leaves us with just &lt;strong&gt;2 host bits&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Now that we know the size of the subnet, let's find its network address. Just like with LAN2, we start from the next address after the previous subnet's broadcast address. LAN2's broadcast address was &lt;code&gt;192.168.1.15&lt;/code&gt;, so this subnet's network address is &lt;code&gt;192.168.1.16&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;192.168.1.16/30&lt;/p&gt;

&lt;p&gt;Next up is the broadcast address. Same as before, we need to set all the host bits to 1, so let's look at &lt;code&gt;192.168.1.16&lt;/code&gt; in binary:&lt;/p&gt;

&lt;p&gt;11000000 10101000 00000001 00010000&lt;/p&gt;

&lt;p&gt;This time 6 bits are green (borrowed) and only 2 are blue (host bits). Let's set those 2 host bits to 1:&lt;/p&gt;

&lt;p&gt;11000000 10101000 00000001 00010011&lt;/p&gt;

&lt;p&gt;Again, only the last octet has changed:&lt;/p&gt;

&lt;p&gt;00010011&lt;/p&gt;

&lt;p&gt;Converting &lt;code&gt;00010011&lt;/code&gt; to decimal gives us &lt;strong&gt;19&lt;/strong&gt; (16 + 2 + 1), so the broadcast address is &lt;code&gt;192.168.1.19&lt;/code&gt;. That leaves &lt;code&gt;192.168.1.17&lt;/code&gt; and &lt;code&gt;192.168.1.18&lt;/code&gt; as our usable addresses, which is exactly what our formula gives us:&lt;/p&gt;

&lt;p&gt;2^2-2=2&lt;/p&gt;

&lt;p&gt;That's one address for each router, with none left over. Unlike the LANs, this subnet is a perfect fit, which is why &lt;code&gt;/30&lt;/code&gt; is a common choice for point-to-point links.&lt;/p&gt;

&lt;p&gt;Here's what the point-to-point link looks like with its new subnet:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7adxu9csvtkl9gf4gnf4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7adxu9csvtkl9gf4gnf4.png" alt="Point-to-Point" width="800" height="220"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Device&lt;/th&gt;
&lt;th&gt;IP Address&lt;/th&gt;
&lt;th&gt;Role&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;td&gt;192.168.1.16&lt;/td&gt;
&lt;td&gt;Network address&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Router1&lt;/td&gt;
&lt;td&gt;192.168.1.17&lt;/td&gt;
&lt;td&gt;Point-to-point interface&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Router0&lt;/td&gt;
&lt;td&gt;192.168.1.18&lt;/td&gt;
&lt;td&gt;Point-to-point interface&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;td&gt;192.168.1.19&lt;/td&gt;
&lt;td&gt;Broadcast address&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;Notice how we did the two &lt;code&gt;/29&lt;/code&gt;s first and left the &lt;code&gt;/30&lt;/code&gt; until last? When you're splitting a network into subnets of different sizes, always start with the biggest. A subnet's network address has to be a multiple of its size, so if we'd given the link &lt;code&gt;192.168.1.0/30&lt;/code&gt; first, the next &lt;code&gt;/29&lt;/code&gt; couldn't start at &lt;code&gt;.4&lt;/code&gt; (4 isn't a multiple of 8). We'd have to skip ahead to &lt;code&gt;.8&lt;/code&gt;, wasting &lt;code&gt;.4&lt;/code&gt; to &lt;code&gt;.7&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;And that's subnetting covered! This blog doesn't cover absolutely everything about subnetting, but it does cover a good chunk of it. Anyway, I hope you enjoyed the read! If you spot any mistakes, please click the "Edit this page on GitHub" link and open a PR with your corrections. I've also put together a quiz below to test your knowledge. Good luck!&lt;/p&gt;

</description>
      <category>networking</category>
      <category>network</category>
      <category>infrastructure</category>
      <category>devops</category>
    </item>
    <item>
      <title>Swift - 1 Month.</title>
      <dc:creator>Nicholas</dc:creator>
      <pubDate>Tue, 10 Nov 2020 12:35:12 +0000</pubDate>
      <link>https://dev.to/heynickn/swift-1-month-1hoj</link>
      <guid>https://dev.to/heynickn/swift-1-month-1hoj</guid>
      <description>&lt;h1&gt;
  
  
  Introduction
&lt;/h1&gt;

&lt;p&gt;Recently I've been learning Swift &amp;amp; iOS development for the past month now and I've decided to document my journey, every month I'll write a post about everything I've learned, the challenges I face, and the goals I set for myself. 😄&lt;/p&gt;

&lt;h3&gt;
  
  
  What I've learned
&lt;/h3&gt;

&lt;p&gt;So I've been following &lt;a href="https://www.udemy.com/course/ios-13-app-development-bootcamp/" rel="noopener noreferrer"&gt;Dr. Angela Yu's Udemy course on iOS13 &amp;amp; Swift 5&lt;/a&gt; and so far I'm pretty impressed with the course and I've already learned so much about the Swift programming language, I definitely recommend it if you're looking to learn Swift. So here are some of the interesting things I've learned:&lt;/p&gt;




&lt;h4&gt;
  
  
  1. Optionals 🤷‍♂️
&lt;/h4&gt;

&lt;p&gt;Swift was designed to be a safe programming language, which means it's less likely to get runtime errors. A common way that code can fail is when it tries to use data or a value that is missing. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="kd"&gt;struct&lt;/span&gt; &lt;span class="kt"&gt;Human&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;middleName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt;
    &lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="nv"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;

    &lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;fullName&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;middle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;middleName&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;firstName&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="s"&gt; &lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;middle&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="s"&gt; &lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;lastName&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;firstName&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="s"&gt; &lt;/span&gt;&lt;span class="se"&gt;\(&lt;/span&gt;&lt;span class="n"&gt;lastName&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;human&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;Human&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nv"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Mary"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nv"&gt;middleName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nv"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Smith"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here I created a &lt;code&gt;struct&lt;/code&gt; which has three properties, &lt;code&gt;firstName&lt;/code&gt;, &lt;code&gt;middleName&lt;/code&gt; (which has a type of optional string) and a &lt;code&gt;lastName&lt;/code&gt;. When a property has an optional type, it means that the property can either have a value or it can be &lt;code&gt;nil&lt;/code&gt; so no value.&lt;/p&gt;

&lt;p&gt;In the code snippet above, I unwrapped the &lt;code&gt;middleName&lt;/code&gt; property so the program wouldn't crash, this is called &lt;a href="https://medium.com/@strawb3rryx7/swift-what-is-the-optional-binding-7624c7f9098e" rel="noopener noreferrer"&gt;Optional Binding&lt;/a&gt;. Conditional Unwrapping allows you to unwrap your optional property with a &lt;b&gt;if let&lt;/b&gt; statement, this means if the property is not nil, it will be unwrapped into the created constant &lt;code&gt;middle&lt;/code&gt; then you can use this constant in the if let statement block.&lt;/p&gt;




&lt;h4&gt;
  
  
  2. Closures 🚪
&lt;/h4&gt;

&lt;p&gt;Closures are functions that you can pass around in your code. And yes when I first came across closures in Swift I was completed lost 🥴 but trust me, it's easier than it looks, here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;num1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;num2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;num1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;num2&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;area&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;w&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;h&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;w&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;area&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;w&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;add&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;h&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Prints 30&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We defined a &lt;code&gt;add&lt;/code&gt; function that takes two parameters, and returns the result when they're added together, simple enough right? 😅&lt;/p&gt;

&lt;p&gt;We define another function called &lt;code&gt;area&lt;/code&gt; which takes in two parameters, the first parameter is a function that is expected to have 2 parameters which are integers and returns an integer. In the function body, we call the &lt;code&gt;w&lt;/code&gt; parameter which also calls the &lt;code&gt;add&lt;/code&gt; function because we pass the &lt;code&gt;add&lt;/code&gt; function as an argument when we called the &lt;code&gt;area(w: (Int, Int) -&amp;gt; Int, h: Int) -&amp;gt; Int&lt;/code&gt; function. The result from the &lt;code&gt;add&lt;/code&gt; function gets stored in the &lt;code&gt;w&lt;/code&gt; parameter and then the &lt;code&gt;h&lt;/code&gt; parameter is added on. I hope that wasn't too confusing, I'll probably write an in-depth blog about closures sometime soon. 😄 &lt;a href="https://docs.swift.org/swift-book/LanguageGuide/Closures.html" rel="noopener noreferrer"&gt;Swift Programming Docs - Learn more about Swift Closures.&lt;/a&gt;&lt;/p&gt;




&lt;h4&gt;
  
  
  3. Extensions 👨‍👧‍👦
&lt;/h4&gt;

&lt;p&gt;Extensions are used to add new functionality to an existing class, structure, enumeration, or protocol type. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="kd"&gt;extension&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;appendLastName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="nv"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;" "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;lastName&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"James"&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;fullName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendLastName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Bond"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fullName&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Prints "James Bond"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, we defined an &lt;code&gt;extension&lt;/code&gt; the extends the &lt;code&gt;String&lt;/code&gt; struct capabilities. We defined a method called &lt;code&gt;appendLastName&lt;/code&gt; which takes in a parameter named &lt;code&gt;lastName&lt;/code&gt; and we append it to the current string, which is &lt;code&gt;"James"&lt;/code&gt;. Not too hard, right? 🙃&lt;/p&gt;

&lt;p&gt;Think of extensions as learning a new skill set, when you've learned to code you essentially gain a new skill set, that skill set being that now you know how to code. Here's an example to demonstrate this scenario a little bit better.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="kd"&gt;struct&lt;/span&gt; &lt;span class="kt"&gt;Nicholas&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;canRead&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"I can read! 😄"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;extension&lt;/span&gt; &lt;span class="kt"&gt;Nicholas&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;func&lt;/span&gt; &lt;span class="nf"&gt;canCode&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"I can hack your facebook! 🤖"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="nv"&gt;nicholas&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;Nicholas&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;nicholas&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;canCode&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// Prints "I can hack your facebook! 🤖"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://docs.swift.org/swift-book/LanguageGuide/Extensions.html" rel="noopener noreferrer"&gt;Swift Programming Docs - Learn more about Swift Extensions&lt;/a&gt;&lt;/p&gt;




&lt;h4&gt;
  
  
  Challenges I faced 😓
&lt;/h4&gt;

&lt;p&gt;Something I didn't understand quite well were Enums. According to the Swift docs, enums are "a common type of group related values and enables you to work with those values in a type-safe way within your code" I'll probably have to work and practice more with Enums to gain a better understanding of them. You can learn more about Enums &lt;a href="https://docs.swift.org/swift-book/LanguageGuide/Enumerations.html" rel="noopener noreferrer"&gt;here.&lt;/a&gt;&lt;/p&gt;




&lt;h4&gt;
  
  
  Goals for next month
&lt;/h4&gt;

&lt;p&gt;Now that I have a solid understanding of Swift syntax, It's time to dive into making apps and applying all of my knowledge. I hope to gain a good understanding of how iOS apps are made by the end of the second month, I'll see there! 😉&lt;/p&gt;




&lt;h4&gt;
  
  
  Note ⚠️
&lt;/h4&gt;

&lt;p&gt;I was supposed to publish this blog a couple of weeks ago but didn't make time because of applying to universities and school work, I'll be sure to publish the next blog on time. 🙂&lt;/p&gt;

</description>
      <category>swift</category>
      <category>ios</category>
      <category>apple</category>
      <category>xcode</category>
    </item>
  </channel>
</rss>
