<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ network - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ network - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Thu, 11 Jun 2026 23:15:05 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/network/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How IPv4 Works – A Handbook for Developers ]]>
                </title>
                <description>
                    <![CDATA[ The Internet Protocol version 4 (IPv4) is one of the core protocols of standards-based internetworking methods in the Internet and other packet-switched networks. IPv4 is still the most widely deployed Internet protocol. Google’s IPv6 Statistics show... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-ipv4-works-a-handbook-for-developers/</link>
                <guid isPermaLink="false">68124752fa6fa6a9a91d9994</guid>
                
                    <category>
                        <![CDATA[ IPv4 ]]>
                    </category>
                
                    <category>
                        <![CDATA[ computer networks ]]>
                    </category>
                
                    <category>
                        <![CDATA[ networking ]]>
                    </category>
                
                    <category>
                        <![CDATA[ network ]]>
                    </category>
                
                    <category>
                        <![CDATA[ ip address ]]>
                    </category>
                
                    <category>
                        <![CDATA[ IP ]]>
                    </category>
                
                    <category>
                        <![CDATA[ handbook ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Omer Rosenbaum ]]>
                </dc:creator>
                <pubDate>Wed, 30 Apr 2025 15:52:50 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1746028336196/79d97781-a9b8-4be3-86a1-47322e9640ff.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>The Internet Protocol version 4 (IPv4) is one of the core protocols of standards-based internetworking methods in the Internet and other packet-switched networks. IPv4 is still the most widely deployed Internet protocol. <a target="_blank" href="https://www.google.com/intl/en/ipv6/statistics.html">Google’s IPv6 Statistics</a> show 44.29% of traffic to Google services on April 24, 2025 is over IPv6, implying 55.71% goes over IPv4.</p>
<p>This handbook will take you through every aspect of IPv4, from understanding IP addresses to examining packet headers and fragmentation. You'll learn:</p>
<ul>
<li><p>How IP addresses work and their different formats</p>
</li>
<li><p>Network addressing schemes from fixed-length to CIDR</p>
</li>
<li><p>Special IPv4 addresses and their uses</p>
</li>
<li><p>The structure and purpose of every field in the IPv4 header</p>
</li>
<li><p>How IPv4 handles packet fragmentation across different networks</p>
</li>
</ul>
<p>Whether you're a network engineer, software developer, or IT professional, understanding IPv4 is crucial for working with modern computer networks.</p>
<h3 id="heading-what-well-cover">What we’ll cover:</h3>
<ol>
<li><p><a class="post-section-overview" href="#heading-background">Background</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-understanding-ip-addresses">Understanding IP Addresses</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-network-id-and-host-id">Network ID and Host ID</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-determine-network-vs-host-portions">How to Determine Network vs. Host Portions</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-fixed-length-approach">Fixed-Length Approach</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-are-the-disadvantages-here">What are the disadvantages here? 🤔</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-classful-addressing">Classful Addressing</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-ip-address-assignment">IP Address Assignment</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-are-the-disadvantages-here-1">What are the disadvantages here? 🤔</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-cidr-classless-interdomain-routing">CIDR: Classless Interdomain Routing</a></p>
<ul>
<li><a class="post-section-overview" href="#heading-real-world-example">Real-world Example</a></li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-subnet-masks">Subnet Masks</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-interim-summary-ipv4-addresses">Interim Summary – IPv4 Addresses</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-test-yourself">Test Yourself</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-converting-between-prefix-notation-and-subnet-masks">Converting Between Prefix Notation and Subnet Masks</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-working-backwards-with-subnet-masks">Working Backwards with Subnet Masks</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-non-byte-aligned-prefixes">Non-Byte-Aligned Prefixes</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-determining-network-membership">Determining Network Membership</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-special-ipv4-addresses">Special IPv4 Addresses</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-the-this-host-address-0000">The "This Host" Address: 0.0.0.0</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-this-network-addresses">"This Network" Addresses</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-broadcast-addresses">Broadcast Addresses</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-loopback-addresses-1270008">Loopback Addresses: 127.0.0.0/8</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-summary-of-special-ipv4-addresses">Summary of Special IPv4 Addresses</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-ipv4-header">IPv4 Header</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-the-header-structure">The Header Structure</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-ipv4-header-interim-summary">IPv4 Header – Interim Summary</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-ipv4-fragmentation">IPv4 Fragmentation</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-why-fragmentation-is-needed">Why Fragmentation Is Needed</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-fragmentation-works-in-ip">How Fragmentation Works in IP</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-identification-field">Identification Field</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-fragment-offset">Fragment Offset</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-more-fragments-and-dont-fragment-flags">More Fragments and Don't Fragment Flags</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-fragmentation-example">Fragmentation Example</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-ipv4-fragmentation-summary">IPv4 Fragmentation – Summary</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-summary-ipv4">Summary – IPv4</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-addressing-and-network-structure">Addressing and Network Structure</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-ipv4-header-structure">IPv4 Header Structure</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-fragmentation">Fragmentation</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-final-words">Final Words</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-about-the-author">About the Author</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-additional-references">Additional References</a></p>
</li>
</ol>
<h2 id="heading-quick-notes-before-we-start">Quick notes before we start</h2>
<ol>
<li><p>You can find more content about computer networks on my YouTube channel: <a target="_blank" href="https://www.youtube.com/playlist?list=PL9lx0DXCC4BMS7dB7vsrKI5wzFyVIk2Kg">Computer Networks Playlist</a></p>
</li>
<li><p>I am working on a book about Computer Networks! Are you interested in reading the initial versions and providing feedback? Send me an email: <a target="_blank" href="mailto:gitting.things@gmail.com">gitting.things@gmail.com</a></p>
</li>
</ol>
<h2 id="heading-background">Background</h2>
<p>IP stands for "Internet Protocol", so IPv4 is Internet Protocol version 4. It was described in RFC 791 by IETF, published in September 1981, and first deployed for production in 1982 on SATNET (the Atlantic Packet Satellite Network), which was an early satellite network that formed an initial segment of the Internet.</p>
<p>IPv4 is connectionless and operates in a best-effort delivery model. This means it doesn't guarantee delivery, correct ordering of packets, or the validity of the data. It's designed to be fast and flexible.</p>
<h2 id="heading-understanding-ip-addresses">Understanding IP Addresses</h2>
<p>IP addresses are hierarchical, logical addresses that power most internet connections today. Each consists of <code>4</code> bytes, or <code>32</code> bits. They're usually written in dotted decimal notation, for example:</p>
<p><a target="_blank" href="https://www.youtube.com/watch?v=zlDkqP3lMmU"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1744039300370/348d757a-c6b0-4930-8e3a-ee753c45f3fa.png" alt="An example IPv4 address (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="331" height="96" loading="lazy"></a></p>
<p>Test yourself – Does the following address represent a valid IP address?</p>
<p><a target="_blank" href="https://www.youtube.com/watch?v=zlDkqP3lMmU"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1744039900249/587d8b94-1ac3-478c-87d9-4b0fd97023b2.png" alt="Is this a valid IPv4 address? (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="308" height="61" loading="lazy"></a></p>
<p>No. Since the dots separate different bytes, each value must be between <code>0</code> and <code>255</code>. Since the number <code>392</code> is bigger than <code>255</code>, it cannot be represented in a single byte.</p>
<p><a target="_blank" href="https://www.youtube.com/watch?v=zlDkqP3lMmU"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1744040039746/71392606-7ac8-441d-ac36-2cf05bb8d67f.png" alt="This is not a valid IPv4 address (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="371" height="96" loading="lazy"></a></p>
<h2 id="heading-network-id-and-host-id">Network ID and Host ID</h2>
<p>IP addresses have two parts: a <strong>network identifier</strong> (or network ID) that belongs to all hosts in the network and a <strong>host identifier</strong> (or host ID) that identifies the specific host in this network.</p>
<p>The network identifier will be the same for all hosts in the network, and is also called a "prefix". For example, consider a network identifier of <code>201.22.3</code>. Given that this is the network prefix, the following addresses:</p>
<pre><code class="lang-plaintext">201.22.3.15
201.22.3.91
</code></pre>
<p>Are part of the same network, as they share the same prefix. The first address belongs to host number <code>15</code> in this network, and the second belongs to host number <code>91</code>.</p>
<p>This address has a different prefix, or a different network identifier, and thus belongs to a different network:</p>
<pre><code class="lang-plaintext">201.22.14.50
</code></pre>
<p>In the examples above, there's a network identifier consisting of 3 bytes, or 24 bits, and a host identifier consisting of 1 byte, or 8 bits.</p>
<p><a target="_blank" href="https://www.youtube.com/watch?v=zlDkqP3lMmU"><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1744040184260/2511a5f3-3a98-40e4-aabe-7853e3febacf.png" alt="Network Identifier vs Host Identifier (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="1385" height="134" loading="lazy"></a></p>
<h2 id="heading-how-to-determine-network-vs-host-portions">How to Determine Network vs. Host Portions</h2>
<p>A question arises: how do you know which bits are part of the network ID, and which are part of the host ID? Several approaches have evolved over time to address this challenge.</p>
<h3 id="heading-fixed-length-approach">Fixed-Length Approach</h3>
<p>Let's consider this solution: For every IP address, the first, most-significant byte would represent the network ID, and the remaining three, least-significant bytes would represent the host ID. This way it's really easy to read IP addresses. For example for this address:</p>
<pre><code class="lang-plaintext">20.12.1.92
</code></pre>
<p>You know that it describes network <code>20</code>, and the host <code>12.1.92</code> inside that network. Any IP address that doesn't start with <code>20</code>, such as <code>22.1.2.3</code>, would reside in a different network, and any IP address that starts with <code>20</code>, like <code>20.1.2.3</code>, would be within the same network.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1744040959545/38c8766b-5ad2-4fb1-98b1-612c70fbe8ad.png" alt="Fixed-Length approach for IP addressing (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="640" height="378" loading="lazy"></p>
<h3 id="heading-what-are-the-disadvantages-here">What are the disadvantages here? 🤔</h3>
<p>With only one byte (8 bits) to represent the network ID, you only have 2^8, or <code>256</code>, different networks. Of course, there are far more networks than that in the real world. Even in the early days of the internet, universities and large companies each needed their own network identifiers.</p>
<p>In general, using a fixed length for the network ID and a fixed length for the host ID is not flexible enough. If you decide that the two most-significant bytes will represent the network ID and the two least-significant bytes will represent the host ID, you can represent up to 2^16, or <code>65,536</code> networks, which is also not enough. Furthermore, some networks, such as those of large companies, might require more than <code>65,536</code> host IDs.</p>
<h2 id="heading-classful-addressing">Classful Addressing</h2>
<p>The solution lies in providing some flexibility. Consider another approach called "classful addressing". In this approach, the number of bits dedicated for the network ID changes from one address to another, and you can tell the network ID by looking at the first, most-significant byte of the address.</p>
<ul>
<li><p>Any address starting with a number between <code>1</code> and <code>127</code> belongs to "Class A", meaning that its network ID consists of 1 byte, leaving 3 bytes for the host ID.</p>
</li>
<li><p>Any address starting with a number between <code>128</code> and <code>191</code> belongs to "Class B", which means that its network ID is 2 bytes long, and its host ID is also 2 bytes long.</p>
</li>
<li><p>Any address starting with a number between <code>192</code> and <code>223</code> belongs to "Class C", so it has 3 bytes of a network ID, and 1 byte of host ID.</p>
</li>
</ul>
<p>You can see the full representation of this approach in the table below:</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Class</td><td>First Byte Range</td><td>Network ID Size</td><td>Host ID Size</td></tr>
</thead>
<tbody>
<tr>
<td>A</td><td><code>1</code> - <code>127</code></td><td>1 byte</td><td>3 bytes</td></tr>
<tr>
<td>B</td><td><code>128</code> - <code>191</code></td><td>2 bytes</td><td>2 bytes</td></tr>
<tr>
<td>C</td><td><code>192</code> - <code>223</code></td><td>3 bytes</td><td>1 byte</td></tr>
<tr>
<td>D</td><td><code>224</code> - <code>239</code></td><td>(multicast)</td><td></td></tr>
<tr>
<td>E</td><td><code>240</code> - <code>255</code></td><td>(reserved)</td></tr>
</tbody>
</table>
</div><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1744088968355/e7f128c0-3173-4bb5-8872-3f820de6b354.png" alt="Classful addressing approach (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="1072" height="560" loading="lazy"></p>
<p>For example, what class does this address belong to?</p>
<pre><code class="lang-plaintext">(1) 130.12.204.5
</code></pre>
<p>Since it starts with <code>130</code>, which is between <code>128</code> and <code>191</code>, it belongs to "Class B". This means that its network ID is <code>130.12</code>, and its host ID is <code>204.5</code>. Let's mark it as "address number 1".</p>
<p>Do this address and the following address (2) belong to the same network?</p>
<pre><code class="lang-plaintext">(2) 130.90.2.40
</code></pre>
<p>No, since they have different network identifiers, they are not within the same network.</p>
<p>What class does the following address belong to?</p>
<pre><code class="lang-plaintext">(3) 200.1.1.9
</code></pre>
<p>It belongs to class C, as the value of its first byte, <code>200</code>, is between <code>192</code> and <code>223</code>. This means that its network identifier is <code>200.1.1</code>, and any address starting with this prefix will reside within the same network. This specific address describes host <code>9</code> within this network.</p>
<p>To complete the picture, addresses starting with a value between <code>224</code> and <code>239</code> belong to "Class D" – that is, multicast addresses – addresses that belong to multiple devices. Addresses starting with a value between <code>240</code> and <code>255</code> were reserved for future use. Addresses starting with <code>0</code> are special addresses.</p>
<h3 id="heading-ip-address-assignment">IP Address Assignment</h3>
<p>In the early internet, IPv4 addresses were assigned to organizations by the Internet Assigned Numbers Authority (IANA). As the internet grew, this responsibility was distributed to five Regional Internet Registries (RIRs) that handle address allocation for different geographic regions. Large organizations would receive blocks of addresses based on their needs, with address classes determining the size of these blocks.</p>
<h3 id="heading-what-are-the-disadvantages-here-1">What are the disadvantages here? 🤔</h3>
<p>While classful addressing allows for more flexibility compared to the fixed-length approach, even this approach isn't flexible enough.</p>
<p>Consider this scenario: A small startup company with just two founders needs a network identifier. Which class would they need?</p>
<p>Getting a class A or class B would be excessive, so they might get a class C – allowing <code>256</code> addresses. This is more than currently needed, but allows some expansion. What happens if the startup grows to more than <code>256</code> employees (and devices)?</p>
<p>At this point, they would need to get a class B address, giving no less than <code>65,536</code> addresses, when all they need is a bit over <code>256</code> addresses. This means wasting more than <code>60,000</code> addresses.</p>
<p>This became a real problem in the early 1990s as the internet was growing faster. The need for more IP addresses became apparent, and there was an impending exhaustion of the IPv4 address space. Cases where <code>60,000</code> addresses were wasted could no longer be tolerated.</p>
<h2 id="heading-cidr-classless-interdomain-routing">CIDR: Classless Interdomain Routing</h2>
<p>One of the measures to handle this shortage of addresses was to abandon classful addressing in 1993 and switch to another approach called CIDR – Classless Interdomain Routing. This approach is still used today.</p>
<p>CIDR allows for flexibility when choosing the network ID and the host ID. It lets network administrators create subnets of precisely the right size, rather than being limited to Classes A, B, or C.</p>
<p>Let's start with a simple example. In CIDR notation, we add a suffix indicating how many bits are used for the network portion:</p>
<pre><code class="lang-plaintext">(4) 200.8.3.1/16
</code></pre>
<p>This slash notation specifies how many bits describe the network ID. In example (4) above, the first <code>16</code> bits (or <code>2</code> bytes) are used for the network ID. So, in this case, <code>200.8</code> is the network identifier, and <code>3.1</code> is the host identifier. The fact that <code>200.8</code> is the network ID means that all addresses from <code>200.8.0.0</code> through <code>200.8.255.255</code> are in this network.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1744090490906/0a18b364-7ca2-4ed0-8f27-2103bcbdd579.png" alt="16-bit subnet mask address (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="374" height="65" loading="lazy"></p>
<p>Consider these additional addresses:</p>
<pre><code class="lang-plaintext">(5) 200.2.13.5
(6) 200.8.21.6
</code></pre>
<p>Given this address prefix of <code>16</code> bits, or <code>2</code> bytes, which of these addresses belong to the same network as example (4) (<code>200.8.3.1/16</code>)?</p>
<p>The first address (5) (<code>200.2.13.5</code>) does not belong to this network, as its first <code>16</code> bits – <code>200.2</code>, are different from the first <code>16</code> bits of the example address.</p>
<p>The second address (6) (<code>200.8.21.6</code>) does belong to the same network as that of the example address.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1744090582529/d314c9ca-73a3-4e48-92b8-b0a6c24ac7d3.png" alt="16-bit subnet mask address (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="376" height="238" loading="lazy"></p>
<h3 id="heading-real-world-example">Real-world Example</h3>
<p>In practice, an ISP might receive a large block like <code>104.16.0.0/12</code> from the RIR. This gives them control of all addresses from <code>104.16.0.0</code> to <code>104.31.255.255</code>. The ISP can then allocate smaller subnets to customers, such as giving a small business a <code>/24</code> subnet with <code>256</code> addresses, or a larger company a <code>/20</code> subnet with <code>4,096</code> addresses.</p>
<h2 id="heading-subnet-masks">Subnet Masks</h2>
<p>Another way to express the network prefix is by using a <a target="_blank" href="https://www.ipxo.com/blog/what-is-subnet-mask/">subnet mask</a>, like so:</p>
<pre><code class="lang-plaintext">255.255.0.0
</code></pre>
<p>When converted to binary, <code>255</code> in decimal equals eight <code>1</code>s in binary – so all bits are on. So if you translate this mask into binary, you get:</p>
<pre><code class="lang-plaintext">11111111 11111111 00000000 00000000
</code></pre>
<p>In other words, <code>16</code> bits are on, which means a network prefix of <code>16</code> bits. Both conventions (CIDR notation and subnet masks) are used very frequently.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1744090679551/5466e739-1e1b-4e34-a044-0d680ca9ad6e.png" alt="16-bit subnet mask address (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="1187" height="48" loading="lazy"></p>
<p>With CIDR, an address can reside in different networks given different network prefixes, or subnet masks. If you consider the same example address with a different prefix, say that of <code>8</code> bits – both additional addresses would belong to the same network, as they all share the first <code>8</code> bits – <code>200</code>.</p>
<p>How would you present a network prefix of <code>8</code> bits as a subnet mask? You need the first <code>8</code> bits to be on, so that means <code>255</code> in decimal, and the remaining bits are off, resulting in this subnet mask:</p>
<pre><code class="lang-plaintext">255.0.0.0
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1744141258583/c4f606ff-410b-4b1f-92c5-505b5309cfa8.png" alt="8-bit subnet mask address (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="1227" height="56" loading="lazy"></p>
<p>What happens if you use a network prefix of <code>24</code> bits? First, how would you express that as a subnet mask? You need <code>24</code> bits to be on, so that is 3 times 8 bits to be on, resulting in:</p>
<pre><code class="lang-plaintext">255.255.255.0
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1744297152994/0dae747f-2a10-4ad6-9e29-b21df15e6169.png" alt="24-bit subnet mask address (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="1411" height="85" loading="lazy"></p>
<p>Now, neither of the additional addresses reside within the same network as the example address, as they don't share its network ID of <code>200.8.3</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1744297174124/16ad2016-c358-474b-964c-4bde75359670.png" alt="CIDR (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="1515" height="379" loading="lazy"></p>
<p>Note that network prefixes do not have to represent full bytes. For example, you can use a network prefix of <code>12</code> bits, or <code>11</code> bits, or <code>22</code> bits. When the prefix length isn't a multiple of <code>8</code>, the subnet mask will have a value other than <code>0</code> or <code>255</code> in one of its positions.</p>
<p>This addresses the issue regarding the startup company. If a startup has <code>300</code> employees, they'd need to get a <code>23</code>-bits network ID, leaving <code>9</code> bits for hosts within their networks. This means 2^9, or <code>512</code> addresses, which should be sufficient.</p>
<h2 id="heading-interim-summary-ipv4-addresses">Interim Summary – IPv4 Addresses</h2>
<p>In this section, you've learned about IPv4 addresses. IP addresses are hierarchical, logical addresses that consist of <code>4</code> bytes. IP addresses have two parts: a network identifier that belongs to all hosts in the network, and a host identifier which identifies the specific host in the network.</p>
<p>You've explored various options for determining the network identifier and the host identifier:</p>
<ol>
<li><p>Fixed-length approach – too rigid and limited</p>
</li>
<li><p>Classful addressing approach – better but still wasteful</p>
</li>
<li><p>CIDR (Classless Interdomain Routing) – flexible and efficient</p>
</li>
</ol>
<p>CIDR provides much more flexibility and helps overcome the significant problem of IPv4 address shortage. However, CIDR is only one part of addressing the shortage of IPv4 addresses, with other solutions including NAT (Network Address Translation) and eventually, IPv6.</p>
<p>The next section will explore special IPv4 addresses and then examine the header of IPv4 packets.</p>
<h2 id="heading-test-yourself">Test Yourself</h2>
<p>Now practice the concepts you've learned and make sure you feel comfortable with them.</p>
<p>Take a moment to try answering the following questions before checking the answers.</p>
<h3 id="heading-converting-between-prefix-notation-and-subnet-masks">Converting Between Prefix Notation and Subnet Masks</h3>
<p>How would you represent a network prefix of <code>16</code> bits, written like this <code>/16</code>, as a subnet mask?</p>
<p>You need <code>16</code> bits that are on. When <code>8</code> bits are on you get <code>255</code> in decimal, so you'd use:</p>
<pre><code class="lang-plaintext">255.255.0.0
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1744465135834/ff449f60-e660-4fea-b427-994a87be2c89.png" alt="16-bit subnet mask address (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="1219" height="85" loading="lazy"></p>
<p>Given this network prefix, do these addresses belong to the same network?</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1744465178617/ef7ddeca-86b2-4bb2-8e1d-471ef4f64a45.png" alt="Do these addresses fit in the network defined before? (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="292" height="142" loading="lazy"></p>
<p>Yes, they do, as they share the same most-significant <code>16</code> bits, or two bytes</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1744465209149/25744a22-16b3-484d-9821-12920dd59be4.png" alt="These addresses fit in the same network (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="306" height="141" loading="lazy"></p>
<p>Does this address belong to the same network as that of the previous addresses?</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1744465232371/92bcb42c-5067-43e6-8cec-1eae9347d16a.png" alt="Additional address (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="314" height="78" loading="lazy"></p>
<p>Yes, it does. Again, it shares the same two most-significant bytes.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1744465259087/a4b9c525-3b4d-4501-bcf8-db62ebf47247.png" alt="This address also fits in the network defined before (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="298" height="208" loading="lazy"></p>
<p>What about this one? Does it belong to the same network as the previous addresses?</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1744465285214/f57fd6c2-7665-4565-943e-959b981fedc8.png" alt="Additional address. Does this address fit in the network defined before? (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="253" height="68" loading="lazy"></p>
<p>No, as the first two bytes are not <code>42.31</code> – this is a different network. So this address describes host <code>1.2</code>, within the network <code>42.32</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1744465302503/0fdd959f-2d10-4a56-826d-e71604ca5267.png" alt="No, this address does not belong to the same network as the other ones (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="307" height="290" loading="lazy"></p>
<h3 id="heading-working-backwards-with-subnet-masks">Working Backwards with Subnet Masks</h3>
<p>Let's try the other way around. You have this subnet mask:</p>
<pre><code class="lang-plaintext">255.255.255.0
</code></pre>
<p>How would you express it using a network prefix?</p>
<p>You have three occurrences of <code>255</code>, which means three times <code>8</code> bits that are on, so overall you have <code>24</code> bits that are on. So you can also write <code>/24</code>. This means <code>3</code> bytes.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1744465331643/b1f3ab4c-8e7e-449d-8879-fee3bf90ce1c.png" alt="24-bit subnet mask (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="1222" height="84" loading="lazy"></p>
<p>Given this subnet mask, do addresses (1) and (3) above belong to the same network?</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1744465436680/ca71584d-53dc-4116-a109-d32c11e997ef.png" alt="Do these addresses have the same network ID given a 24-bit subnet mask? (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="193" height="85" loading="lazy"></p>
<p>They do, as they both have the same most-significant three bytes – network <code>42.31.93</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1744465461745/c01f5958-f675-45c5-bc41-de857483e25d.png" alt="24-bit subnet mask (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="202" height="101" loading="lazy"></p>
<p>What about addresses (1) and (2)?</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1744465532664/a0ef8f73-27d5-4488-98a9-1dbeaf457797.png" alt="Do these addresses have the same network ID given a 24-bit subnet mask? (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="193" height="96" loading="lazy"></p>
<p>Given this network prefix, they don't belong to the same network. The first address belongs to network <code>42.31.93</code>, and the second address belongs to network <code>42.31.1</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1744465498737/6d4cb056-126a-422f-94bc-4392a996869c.png" alt="24-bit subnet mask (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="193" height="96" loading="lazy"></p>
<h3 id="heading-non-byte-aligned-prefixes">Non-Byte-Aligned Prefixes</h3>
<p>Network prefixes do not have to align to <code>8</code> bits, or full bytes. Let's say you have a network prefix of <code>14</code> bits. How would you convert that to a subnet mask?</p>
<p>Well, the first byte is clear: you have <code>8</code> bits on, so the first byte is <code>255</code>. What about the next one?</p>
<p>In binary, you'd want to have six additional 1s, and then 2 0s – so in binary you'd write:</p>
<pre><code class="lang-plaintext">11111100
</code></pre>
<p>Converting to decimal, this binary number represents <code>252</code>. So your subnet mask is:</p>
<pre><code class="lang-plaintext">255.252.0.0
</code></pre>
<p>Another way to make this conversion: You know that eight 1s in binary represent <code>255</code> in decimal. You also know that <code>11</code> in binary is <code>3</code>, so you can simply subtract <code>3</code> from <code>255</code> and get <code>252</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1744465576989/bb1a90c1-1563-4970-b0f5-e0f502e82563.png" alt="14-bit subnet mask (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="1212" height="75" loading="lazy"></p>
<p>Next, try the other way around. You have the following subnet mask:</p>
<pre><code class="lang-plaintext">255.255.224.0
</code></pre>
<p>How many bits represent the network prefix?</p>
<p>The first two bytes are clear: you have <code>16</code> bits. Converting the third byte to binary: <code>224</code> in decimal is <code>11100000</code> in binary. This means you have an additional three 1s, so you can write the subnet mask above as a prefix of <code>/19</code> bits – <code>16</code> bits for the two <code>255</code> bytes, and <code>3</code> additional bits for the <code>224</code> byte.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1744465642118/2587e3bc-0c88-48a9-b876-b96fd3a493d1.png" alt="19-bit subnet mask (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="1228" height="68" loading="lazy"></p>
<h3 id="heading-determining-network-membership">Determining Network Membership</h3>
<p>Let's consider the following addresses:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1744465744667/86337750-0f67-4ed7-b8c2-7d6fcf330a71.png" alt="Two IP addresses (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="195" height="96" loading="lazy"></p>
<p>Are they part of the same network? 🤔</p>
<p>It depends on the subnet mask.</p>
<p>If the network prefix is <code>/8</code>, then they are part of the same network, as they share the same network ID.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1744465761356/67c590e1-daf5-4276-96ff-a39ee914d2d3.png" alt="8-bit subnet mask (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="195" height="96" loading="lazy"></p>
<p>On the other hand, if the network prefix is <code>/16</code>, then they have different network IDs, and thus don't belong to the same network. But what happens with prefixes in between? Will they reside in the same network for a prefix of <code>/9</code>? <code>/14</code>?</p>
<p>The way to approach this question is to convert the second byte of these addresses to binary. For the first address, this byte is <code>24</code>, which in binary is:</p>
<pre><code class="lang-plaintext">00011000
</code></pre>
<p>For the second address, the second byte is <code>23</code>, which in binary is:</p>
<pre><code class="lang-plaintext">00010111
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1744465797029/fcbc4bd8-e273-4032-afb3-f10e2028738b.png" alt="12-bit subnet mask (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="308" height="229" loading="lazy"></p>
<p>You can see that the most significant <code>4</code> bits within the second byte are identical. If you add the first <code>8</code> bits of the address, you see that the most significant <code>12</code> bits of these addresses are the same.</p>
<p>So, if you have a network prefix of <code>/11</code>, do these addresses belong to the same network?</p>
<p>Yes, they do – their most significant <code>11</code> bits are identical.</p>
<p>What about <code>/13</code>?</p>
<p>No, with this network prefix, they don't share the same network identifier, as their <code>13</code>th bit is different.</p>
<p>This practice should help you feel comfortable with subnet masks and network prefixes. In the next section, you'll learn about special IP addresses and then examine the header of IP packets.</p>
<h2 id="heading-special-ipv4-addresses">Special IPv4 Addresses</h2>
<p>Now that you're comfortable with IP addresses and subnet masks, let's explore some IP addresses that have special meanings.</p>
<h3 id="heading-the-this-host-address-0000">The "This Host" Address: 0.0.0.0</h3>
<p>The address <code>0.0.0.0</code> means "this host" and is used in two scenarios:</p>
<p>First, when a machine boots up and doesn't yet have an IP address. IP addresses are logical addresses that need to be assigned to a machine. Prior to this assignment, a device has no IP address at all. If the device needs to communicate at this stage, it may use this special address, <code>0.0.0.0</code>.</p>
<p>Second, when writing network applications that need to listen for incoming connections on all network interfaces. For example, if a machine has two interfaces – one with the IP address <code>1.1.1.1</code>, and another with the address <code>2.2.2.2</code> – listening on the address <code>0.0.0.0</code> means accepting connections regardless of which network interface receives them.</p>
<h3 id="heading-this-network-addresses">"This Network" Addresses</h3>
<p>Another class of special addresses are those starting with zeros, where the zeros mean "this network."</p>
<p>For example, if you have a machine with the address:</p>
<pre><code class="lang-plaintext">12.34.55.55
</code></pre>
<p>And a network prefix of <code>16</code> bits, this machine can send a packet to another device on the network using its full address, for example <code>12.34.66.66</code>, or alternatively use the special zeros notation and send the packet to:</p>
<pre><code class="lang-plaintext">0.0.66.66
</code></pre>
<p>This means "send a packet to the host <code>66.66</code> on this network." Of course, the recipient must also know the relevant network prefix to correctly interpret this address.</p>
<h3 id="heading-broadcast-addresses">Broadcast Addresses</h3>
<p>The address <code>255.255.255.255</code>, where all bits are set to <code>1</code>, is the address of all hosts in the local network – the broadcast address. This is similar to the <a target="_blank" href="https://www.freecodecamp.org/news/the-complete-guide-to-the-ethernet-protocol/#heading-unicast-and-multicast-bits">broadcast address in Ethernet</a> (<code>FF:FF:FF:FF:FF:FF</code>). In both cases, all bits are set to <code>1</code>.</p>
<p>Using a proper network identifier where the host identifier is all set to 1s can be used to send a broadcast packet to remote networks. For example, consider a network <code>12.34.0.0/16</code> and another network with the network ID of <code>12.35.0.0/16</code>. If a machine at <code>12.34.55.55</code> wants to send a packet to all devices in the other network, it could use the destination address: <code>12.35.255.255</code>.</p>
<p>Even though this is allowed according to the IP specification (RFC), in practice this feature is often disabled as it can create security vulnerabilities.</p>
<h3 id="heading-loopback-addresses-1270008">Loopback Addresses: 127.0.0.0/8</h3>
<p>All addresses in the network <code>127.0.0.0/8</code> (that is, all addresses that start with <code>127</code>) are loopback addresses. Packets sent to any of these addresses are not put onto the physical network but are processed locally within the operating system. This is extremely useful for development and debugging.</p>
<p>For example, when developing a simple chat program, you need two clients that exchange data. One approach would be to use two different physical computers, but this is tedious – you'd need to write a message on one computer, check the other computer to see if it was received, then write a message on the second computer, and go back to the first to validate receipt.</p>
<p>A much simpler approach is to use a loopback address. Both clients can run on the same machine and connect with one another. You can run two different client programs on the same physical computer and exchange messages between them without needing an additional machine.</p>
<p>For instance, you might use the address <code>127.0.0.1</code>, with one client listening on port <code>1337</code> and the other on port <code>1338</code>. When client A sends a packet to client B, this packet never leaves your network card but remains within the operating system. Client B receives the packet from the loopback interface as if it had been received from the physical network.</p>
<p>After debugging is complete, your client code doesn't need to change – the only difference is that they will communicate using real IP addresses instead of the loopback address.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1744736895494/fd1e4a8d-a834-4bf4-b4b9-1e83cf851161.png" alt="Loopback operation (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="1024" height="1024" loading="lazy"></p>
<h3 id="heading-summary-of-special-ipv4-addresses">Summary of Special IPv4 Addresses</h3>
<p>To summarize the special IPv4 addresses you've learned about:</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Special Address</td><td>Meaning</td><td>Usage</td></tr>
</thead>
<tbody>
<tr>
<td><code>0.0.0.0</code></td><td>"This host"</td><td>Used during boot or to listen on all interfaces</td></tr>
<tr>
<td>Addresses starting with <code>0</code></td><td>"This network"</td><td>Sending to hosts on the local network</td></tr>
<tr>
<td><code>255.255.255.255</code></td><td>Broadcast</td><td>Sending to all hosts on the local network</td></tr>
<tr>
<td>Network ID with all 1s in host part</td><td>Directed broadcast</td><td>Sending to all hosts on a specific network</td></tr>
<tr>
<td><code>127.0.0.0/8</code></td><td>Loopback</td><td>Testing and debugging without using the physical network</td></tr>
</tbody>
</table>
</div><p>In the next section, you'll learn about the structure of the IPv4 header.</p>
<h2 id="heading-ipv4-header">IPv4 Header</h2>
<p>Now that you understand IP addresses, subnets, and special addresses, it's time to examine the IPv4 header structure in detail.</p>
<h3 id="heading-the-header-structure">The Header Structure</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745583720695/21521520-3029-4a0a-b4e7-fa484ca350ab.png" alt="IPv4 Header (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="1371" height="633" loading="lazy"></p>
<p>The diagram above shows the header of IPv4 as defined in RFC 791. Let's examine each field:</p>
<h4 id="heading-version-4-bits">Version (4 bits)</h4>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745589954987/cb357d49-73ab-43e6-93b5-c2b7c7e3eb4a.png" alt="Version field within IPv4 Header (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="1638" height="749" loading="lazy"></p>
<p>The header starts with the Version field, which consists of four bits. For an IPv4 packet, the version is <code>4</code>, so this field will always carry the value of <code>4</code> (or <code>0100</code> in binary).</p>
<p>❓ Why does the header start with the Version field? 🤔</p>
<p>(Note – when I start a sentence with the ❓mark – it’s a question addressed at you, and I encourage you to try and answer it before reading on).</p>
<p>The reason is that the remaining fields may differ according to the version. If a network device reads an IP packet and the version field carries the value of <code>4</code>, it will expect the remainder of the packet to follow the IPv4 structure. If it carries another value, such as <code>6</code>, the remaining fields are different, as in IPv6.</p>
<h4 id="heading-internet-header-length-ihl-4-bits">Internet Header Length (IHL) (4 bits)</h4>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745590070221/ca452338-299c-422c-aef4-8fe8569dd218.png" alt="IHL field within IPv4 Header (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="1637" height="754" loading="lazy"></p>
<p>This field indicates the length of the header itself.</p>
<p>❓ Why do we need to specify the length? 🤔</p>
<p>Unlike <a target="_blank" href="https://www.freecodecamp.org/news/the-complete-guide-to-the-ethernet-protocol/">Ethernet</a>, where the header size is fixed, the IPv4 header length can vary because of optional fields. For an IP packet without special options, the header consists of <code>20</code> bytes, which is the most common case.</p>
<p>The IHL field doesn't specify the length in bytes directly but in units of 4-byte words. So to specify a length of <code>20</code> bytes, the value would be <code>5</code> (5 × 4 = 20). This encoding allows the field to use only 4 bits while specifying header lengths up to <code>60</code> bytes (when IHL = <code>15</code>).</p>
<p>A common IPv4 packet therefore begins with the byte <code>0x45</code> in hexadecimal, meaning it's version <code>4</code> of the IP protocol, and the header is <code>20</code> bytes long.</p>
<h4 id="heading-type-of-service-tos-8-bits">Type of Service (TOS) (8 bits)</h4>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745590323255/e8a30561-bfbf-4bcd-a07c-3dbce88fc6c4.png" alt="TOS field within IPv4 Header (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="1638" height="753" loading="lazy"></p>
<p>The idea behind this field is that not all packets are equally important. You may want to give priority to some packets over others.</p>
<p>For example, packets carrying real-time data (like voice or video conferencing) are more time-sensitive than packets carrying, say, email or file downloads. If a router is currently experiencing high load, it should ideally prioritize time-sensitive packets.</p>
<p>The Type of Service field allows senders to indicate the priority of their packets. However, on the public internet, this field is often ignored by routers because any sender can set any priority value. In most cases, this field carries the value of <code>0</code>.</p>
<h4 id="heading-total-length-16-bits">Total Length (16 bits)</h4>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745590421285/07a4b428-3a97-4ea8-9006-5fd8bb215d95.png" alt="Total Length field within IPv4 Header (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="1632" height="744" loading="lazy"></p>
<p>This field specifies the total length of the IP packet, including both the header and the payload (data).</p>
<p>❓ Why is this needed to specify the length? 🤔</p>
<p>Unfortunately, the IP layer doesn’t necessarily know if some of the bytes in the packet are actually a padding of the second layer. I described this in detail in <a target="_blank" href="https://www.freecodecamp.org/news/the-complete-guide-to-the-ethernet-protocol/#heading-the-problem-with-the-type-length-field">a previous post</a>, where I showed that in Ethernet protocol, in some cases, <a target="_blank" href="https://www.freecodecamp.org/news/the-complete-guide-to-the-ethernet-protocol/#heading-the-problem-with-the-type-length-field">the receiving Ethernet entity cannot tell which bytes belong to the payload and which bytes are simply padding</a>. The IP layer needs to know precisely which bytes belong to the actual packet, hence the Total Length field.</p>
<p>❓What is the maximum size of an IPv4 packet? 🤔</p>
<p>Since this field is <code>16</code> bits long, an IPv4 packet may contain a maximum of 2^16-1 bytes, or <code>65,535</code> bytes, including the header. The minimum size is <code>20</code> bytes, consisting of just the header without options or payload.</p>
<h4 id="heading-fragmentation-fields-32-bits">Fragmentation Fields (32 bits)</h4>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745591136348/bb1035af-c967-4bb8-992c-c10e31b64cd1.png" alt="Fragmentation fields within IPv4 Header (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="1640" height="741" loading="lazy"></p>
<p>The next four bytes are dedicated to fragmentation control. I’ll cover these fields in a separate section, as they involve a complex topic deserving special attention.</p>
<h4 id="heading-time-to-live-8-bits">Time to Live (8 bits)</h4>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745591194176/3f3f98f6-b079-43d3-9ee3-b052b7f4f6d7.png" alt="TTL field within IPv4 Header (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="1638" height="743" loading="lazy"></p>
<p>Despite its name, this field doesn't actually measure time but rather the maximum number of routing hops a packet can traverse before being discarded.</p>
<p>To understand its purpose, consider this scenario: If Machine A sends a packet to Machine B through a series of routers, but there's a routing loop where Router 2 sends to Router 3, which sends to Router 4, which sends back to Router 2, the packet could circulate indefinitely, consuming bandwidth and never reaching its destination.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745775904428/72ba07f9-461d-483f-be16-773218d8f863.png" alt="A routing issue causing an infinite loop (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="1561" height="343" loading="lazy"></p>
<p>The TTL field prevents this by setting a limit on how many hops a packet can take:</p>
<ol>
<li><p>The sender sets an initial TTL value (often <code>64</code> or <code>128</code>)</p>
</li>
<li><p>Each router that handles the packet decrements the TTL by <code>1</code></p>
</li>
<li><p>If a router receives a packet with TTL = <code>1</code>, it decrements it to <code>0</code> and discards the packet</p>
</li>
<li><p>The router then sends an ICMP "Time Exceeded" message back to the original sender</p>
</li>
</ol>
<p>This doesn't solve the underlying problem of routing loops, but it prevents packets from circulating forever.</p>
<p>In IPv6, this field is renamed "Hop Limit," which more accurately describes its function.</p>
<h4 id="heading-protocol-8-bits">Protocol (8 bits)</h4>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745591243041/ab9be6ea-5f11-4bb1-b93f-f0d9deef0c6f.png" alt="Protocol field within IPv4 Header (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="1635" height="751" loading="lazy"></p>
<p>This field describes the payload of the IPv4 packet. For example:</p>
<ul>
<li><p>A value of <code>6</code> means the payload is TCP</p>
</li>
<li><p>A value of <code>17</code> means the payload is UDP</p>
</li>
</ul>
<p>This helps the receiving system know which protocol handler should process the packet's contents. It's similar to <a target="_blank" href="https://www.freecodecamp.org/news/the-complete-guide-to-the-ethernet-protocol/#heading-type-length-field-ethernet-ii-type-2-bytes">the Type field in Ethernet</a>, which specifies the protocol of the layer encapsulated within the Ethernet frame.</p>
<h4 id="heading-header-checksum-16-bits">Header Checksum (16 bits)</h4>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745591295127/9953fb34-2b2f-4c9f-bf39-7a18ceaf2b1a.png" alt="Header checksum field within IPv4 Header (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="1633" height="747" loading="lazy"></p>
<p>This is a 16-bit checksum used to verify the validity of the header only (that is, excluding the payload). The sender computes this value based on the fields of the header, and the receiver also computes it to validate that the header was received correctly.</p>
<p>❓The checksum must be recalculated by each router. Why is that? 🤔</p>
<p>Because the TTL field changes at each hop. For example, if a packet starts with TTL = <code>7</code>, each router will:</p>
<ol>
<li><p>Verify the current checksum based on TTL = <code>7</code></p>
</li>
<li><p>Decrement TTL to <code>6</code></p>
</li>
<li><p>Calculate a new checksum based on TTL = <code>6</code></p>
</li>
<li><p>Forward the packet with the new checksum</p>
</li>
</ol>
<p>If the checksum verification fails, the device drops the packet. This prevents packets with corrupted headers (which might have incorrect destination addresses, for instance) from being forwarded.</p>
<h4 id="heading-source-and-destination-addresses-32-bits-each">Source and Destination Addresses (32 bits each)</h4>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745591643443/b2409ba4-d2e3-468a-af2a-a71fc4ce4c30.png" alt="Source and Destination IP Addresses fields within IPv4 Header (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="1635" height="744" loading="lazy"></p>
<p>These fields contain the source and destination IPv4 addresses, respectively. Each is 4 bytes (32 bits) long, as you learned in the previous sections on IPv4 addressing.</p>
<h4 id="heading-options-variable-length">Options (Variable Length)</h4>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745591747762/66a3d602-4379-453a-b221-b4f694c3363c.png" alt="Options within IPv4 Header (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="1638" height="743" loading="lazy"></p>
<p>Most IPv4 packets don't include options, but when present, they can provide additional functionality:</p>
<ul>
<li><p><strong>Record Route</strong>: Each router that handles the packet adds its own address to this option, creating a trace of the packet's path</p>
</li>
<li><p><strong>Source Routing</strong>: Allows the sender to specify the route the packet should take:</p>
<ul>
<li><p>Strict Source Routing: The entire route must be followed exactly</p>
</li>
<li><p>Loose Source Routing: Certain routers must be traversed, but the exact path between them is flexible</p>
</li>
</ul>
</li>
</ul>
<h4 id="heading-padding">Padding</h4>
<p>In some cases, the header ends with padding bytes (usually <code>0</code>s).</p>
<p>❓Why does the IPv4 header have padding?🤔</p>
<p>As explained before, the IHL field specifies the header length in 4-byte units, so the total header length must be a multiple of 4 bytes. If options make the header length not divisible by 4, padding bytes (usually <code>0</code>) are added to reach the next multiple of 4.</p>
<p>For example, if you have 3 bytes of options, you would need 1 byte of padding to make the total header length a multiple of 4 bytes.</p>
<h3 id="heading-ipv4-header-interim-summary">IPv4 Header – Interim Summary</h3>
<p>You've now learned about the structure of the IPv4 header, with the exception of the fragmentation fields which I’ll cover in the next section.</p>
<p>The IPv4 header efficiently packs all the necessary routing and control information into a compact structure, typically 20 bytes long (without options). This design allows for fast processing by routers while providing the flexibility needed for internet communication. It is amazing how prominent IPv4 is, even so many years after its publication.</p>
<p>In the next section, you'll learn about IPv4 fragmentation.</p>
<h2 id="heading-ipv4-fragmentation">IPv4 Fragmentation</h2>
<p>In the previous section, you learned about most of the IPv4 header structure, with the exception of 32 bits dedicated to fragmentation. This topic deserves special attention, as it reveals important aspects of how IP packets travel across different networks.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745591136348/bb1035af-c967-4bb8-992c-c10e31b64cd1.png" alt="Fragmentation fields within IPv4 Header (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="1640" height="741" loading="lazy"></p>
<h3 id="heading-why-fragmentation-is-needed">Why Fragmentation Is Needed</h3>
<p>To understand what fragmentation is and why it's needed, consider the following network scenario:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745770107962/b3bc6c7a-2adb-4868-893c-ec9e51303567.png" alt="Two networks with different MTUs (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="1634" height="568" loading="lazy"></p>
<p>In this diagram, you have two different networks where Machine A resides in one network and Machine B resides in another. A router forwards packets between these two networks.</p>
<p>These two networks have different Maximum Transmission Units (MTUs). MTU refers to the maximum size of a frame that can be transmitted in a network. For example:</p>
<ul>
<li><p>Machine B is connected to an Ethernet network with an MTU of <code>1500</code> bytes</p>
</li>
<li><p>Machine A is connected to a different network with an MTU of <code>2000</code> bytes</p>
</li>
</ul>
<p>Different MTUs stem from the different protocols and hardware that different networks have. Ethernet has an MTU of <code>1500</code> bytes. This maximum size was chosen because RAM was expensive back in the late 1970s when Ethernet was planned, and a receiver would need more RAM if a frame could be bigger. Other networks were devised at different times where RAM prices might have been lower, or just have other considerations that affect the MTU.</p>
<p>Now, consider this scenario: Machine A wants to send a packet to Machine B. This packet is <code>1800</code> bytes long. From A's perspective, there's no problem since its network supports packets of this size. Machine A transmits the packet.</p>
<p>When the router receives this packet, it faces a problem: it cannot simply forward the packet to B's network because the packet is too big for the network's MTU. The router must <strong>fragment</strong> the packet – splitting it into smaller chunks of up to <code>1500</code> bytes, which will then be reassembled by Machine B.</p>
<h3 id="heading-how-fragmentation-works-in-ip">How Fragmentation Works in IP</h3>
<p>Let's examine the scenario further. The router needs to take an IP packet of <code>1800</code> bytes and split it into two fragments, each consisting of up to <code>1500</code> bytes. If Machine A sends another packet of <code>1800</code> bytes to Machine B, the router will have to split that one too – resulting in four different fragments that will be reassembled into two separate packets.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745770316245/b137efa8-ae1c-42cb-918a-f6d0ee7b2c3a.png" alt="Two IP packets, each consisting of two fragments (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="1097" height="258" loading="lazy"></p>
<p>When Machine B receives these fragments, it must ensure that it reassembles fragment #1 together with fragment #2 of packet A, and fragment #1 with fragment #2 of packet B – and not, for instance, fragment #1 of packet A with fragment #2 of packet B. It must also reassemble the fragments in the correct order – so structure a packet that consists of #1#2 and not #2#1.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745770377464/12aad8f1-0251-4289-bc9a-75084dbc1f7a.png" alt="Possible issues in reassembling packets from two fragments (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="1088" height="183" loading="lazy"></p>
<h3 id="heading-identification-field">Identification Field</h3>
<p>First, focus on making sure Machine B reassembles fragments of the same packet (for example, fragment #1 and fragment #2 of packet A in the example above, rather than fragment #1 of packet A and fragment #2 of packet B). This is achieved using the identification field of IPv4. Fragments belonging to the same packet will have the same identification value. For example, both fragments of packet A might have identification set to <code>100</code>, and both fragments of packet B might have identification of <code>200</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1745770785114/6f04e59b-adfc-44a9-bf6e-1118ab748160.png" alt="The identification fields ensures fragments of the same original packet are reassembled together (Source: https://youtube.com/BriefVid)" class="image--center mx-auto" width="1096" height="258" loading="lazy"></p>
<p>It's important to note that sharing identification values isn't sufficient for fragments to belong to the same packet. Fragments of the same packet must also share:</p>
<ul>
<li><p>The same source IP address</p>
</li>
<li><p>The same destination IP address</p>
</li>
<li><p>The same protocol value (indicating whether the payload is TCP, UDP, and so on)</p>
</li>
</ul>
<h3 id="heading-fragment-offset">Fragment Offset</h3>
<p>Since IP is a connectionless protocol, there's no guarantee that fragments will arrive at Machine B in the correct order. Fragment #2 of packet A may arrive before fragment #1. To handle this issue, each fragment carries an Offset field, which denotes the offset from the beginning of the original packet.</p>
<p>The Offset field consists of 13 bits, which means it can carry values from <code>0</code> to <code>8191</code> (2^13-1). This poses a potential problem, as the maximum size of an IP packet can be <code>65,535</code> bytes (since the Total Length field of the IP header consists of 16 bits).</p>
<p>To address this limitation, the value encoded in the Offset field is actually multiplied by <code>8</code> (2^3). This means the minimum size of a fragment is <code>8</code> bytes, with the exception of the last fragment.</p>
<p>❓Why do IP packets carry an offset in bytes divided by 8, instead of just a sequential fragment number?🤔</p>
<p>While using sequence numbers might seem simpler, it would create problems when packets need to be fragmented multiple times.</p>
<p>For example, if Computer A sends a packet to the first router, which fragments it into pieces of <code>1480</code> bytes and <code>320</code> bytes, and then these fragments are sent to another router that needs to fragment them again into even smaller pieces, how would you number them?</p>
<p>With byte offsets, the solution is straightforward – if the first fragment has an offset of <code>0</code> and the next one has an offset of <code>1480</code>, then if we need to split them into maximum <code>800</code>-byte fragments, we'd have:</p>
<ul>
<li><p>First fragment: <code>800</code> bytes with offset <code>0</code></p>
</li>
<li><p>Second fragment: <code>680</code> bytes with offset <code>800</code></p>
</li>
<li><p>Third fragment: <code>320</code> bytes with offset <code>1480</code></p>
</li>
</ul>
<h3 id="heading-more-fragments-and-dont-fragment-flags">More Fragments and Don't Fragment Flags</h3>
<p>When Machine B receives a fragment, it needs to know whether this is an entire packet by itself or if it should expect additional fragments. For this purpose, each IP fragment carries a More Fragments (<code>MF</code>) bit that is set to <code>1</code> for every fragment that is not the last fragment of the packet. For the last fragment, it's set to <code>0</code>.</p>
<p>In case the packet consists of a single fragment – the <code>MF</code> bit will be set to <code>0</code>, and the offset field will also hold the value <code>0</code> (that is, 13 bits of <code>0</code>s).</p>
<p>Another bit related to fragmentation is the Don't Fragment (<code>DF</code>) bit. When this flag is turned on, intermediate devices should not fragment the original packet, even if it exceeds the MTU. Instead, they should drop it and typically send an ICMP "Fragmentation Needed" message back to the source.</p>
<p>In our example, if Machine A sets the Don't Fragment bit to <code>1</code>, the router would drop the packet, and notify Machine A about it.</p>
<p>Note that right after the identification field and before the <code>DF</code> flag, there is a reserved bit set to <code>0</code>. This bit was reserved in case it is needed in the future, for a reason unknown to the original authors of IPv4.</p>
<h3 id="heading-fragmentation-example">Fragmentation Example</h3>
<p>Consider again our example above – with Machine A residing in a network where the MTU is <code>2000</code>, and Machine B residing in a network where the MTU is <code>1500</code>. Machine A sends a packet which is <code>1800</code> bytes long.</p>
<p>❓Can you fill the values in these tables?</p>
<p><strong>First Fragment:</strong></p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Total Length</td><td></td></tr>
</thead>
<tbody>
<tr>
<td>Identification</td><td></td></tr>
<tr>
<td>Don’t Fragment</td><td></td></tr>
<tr>
<td>More Fragments</td><td></td></tr>
<tr>
<td>Offset</td></tr>
</tbody>
</table>
</div><p><strong>Second Fragment:</strong></p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Total Length</td><td></td></tr>
</thead>
<tbody>
<tr>
<td>Identification</td><td></td></tr>
<tr>
<td>Don’t Fragment</td><td></td></tr>
<tr>
<td>More Fragments</td><td></td></tr>
<tr>
<td>Offset</td></tr>
</tbody>
</table>
</div><p>For our example above, the values of the relevant fragmentation fields in IP would be as follows:</p>
<p><strong>First Fragment:</strong></p>
<ul>
<li><p>Total Length: <code>1500</code> (including <code>20</code> bytes of IP header, so <code>1480</code> bytes of payload)</p>
</li>
<li><p>Identification: <code>1337</code> (arbitrary value)</p>
</li>
<li><p>Don't Fragment bit: <code>0</code> (off, to allow further fragmentation if needed)</p>
</li>
<li><p>More Fragments bit: <code>1</code> (on, as this is not the last fragment)</p>
</li>
<li><p>Offset: <code>0</code> (it's the first fragment)</p>
</li>
</ul>
<p><strong>Second Fragment:</strong></p>
<ul>
<li><p>Total Length: <code>340</code> (including <code>20</code> bytes of IP header, so <code>320</code> bytes of payload – together with the first fragment, we get to <code>1800</code> bytes of payload)</p>
</li>
<li><p>Identification: <code>1337</code> (same as first fragment, indicating they belong together)</p>
</li>
<li><p>Don't Fragment bit: <code>0</code> (off, to allow further fragmentation if needed)</p>
</li>
<li><p>More Fragments bit: <code>0</code> (off, as this is the last fragment)</p>
</li>
<li><p>Offset: <code>185</code> (1480/8 = 185, or <code>0xB9</code> in hexadecimal)</p>
</li>
</ul>
<h3 id="heading-ipv4-fragmentation-summary">IPv4 Fragmentation – Summary</h3>
<p>You've now learned about the final part of the IPv4 Header: fragmentation. Fragmentation is necessary to allow packets to travel across networks with different MTUs. The IPv4 header includes several fields specifically designed to support fragmentation:</p>
<ul>
<li><p>Identification (16 bits): Identifies which fragments belong together</p>
</li>
<li><p>Flags (3 bits): Including the "More Fragments" and "Don't Fragment" flags</p>
</li>
<li><p>Fragment Offset (13 bits): Indicates where in the original packet this fragment belongs</p>
</li>
</ul>
<p>With this knowledge, you now understand every bit and byte of the IPv4 header and how IP packets can traverse networks with different characteristics.</p>
<h2 id="heading-summary-ipv4">Summary – IPv4</h2>
<p>In this comprehensive guide to IPv4, you've learned about the fundamental building blocks of Internet communications. Let's recap the key concepts we covered:</p>
<h3 id="heading-addressing-and-network-structure">Addressing and Network Structure</h3>
<ul>
<li><p>IPv4 addresses are 32-bit numbers typically written in dotted decimal notation</p>
</li>
<li><p>Networks can be identified using various methods:</p>
<ul>
<li><p>Fixed-length approach (historically)</p>
</li>
<li><p>Classful addressing (A, B, C, D, E classes)</p>
</li>
<li><p>CIDR (modern approach allowing flexible network sizes)</p>
</li>
</ul>
</li>
<li><p>Special addresses serve specific purposes:</p>
<ul>
<li><p><code>0.0.0.0</code> for "this host"</p>
</li>
<li><p><code>127.0.0.0/8</code> for loopback</p>
</li>
<li><p><code>255.255.255.255</code> for broadcast</p>
</li>
</ul>
</li>
</ul>
<h3 id="heading-ipv4-header-structure">IPv4 Header Structure</h3>
<ul>
<li><p>The header contains crucial fields for packet routing and processing:</p>
<ul>
<li><p>Version and IHL for header interpretation</p>
</li>
<li><p>Type of Service for traffic prioritization</p>
</li>
<li><p>Total Length for packet size</p>
</li>
<li><p>Various fields for fragmentation control</p>
</li>
<li><p>TTL to prevent infinite routing loops</p>
</li>
<li><p>Protocol to identify the encapsulated protocol</p>
</li>
<li><p>Checksum for error detection</p>
</li>
<li><p>Source and destination addresses</p>
</li>
</ul>
</li>
</ul>
<h3 id="heading-fragmentation">Fragmentation</h3>
<ul>
<li><p>Allows IPv4 packets to traverse networks with different MTUs</p>
</li>
<li><p>Uses three key fields:</p>
<ul>
<li><p>Identification to group fragments</p>
</li>
<li><p>Flags to control fragmentation</p>
</li>
<li><p>Fragment Offset to reassemble packets</p>
</li>
</ul>
</li>
</ul>
<h3 id="heading-final-words">Final Words</h3>
<p>While IPv4 has limitations, particularly its address space constraints, its elegant design and robust features have allowed it to remain the backbone of the Internet for over four decades. Understanding IPv4 provides essential context for working with modern networks and helps in transitioning to newer protocols like IPv6.</p>
<h2 id="heading-about-the-author"><strong>About the Author</strong></h2>
<p><a target="_blank" href="https://www.linkedin.com/in/omer-rosenbaum-034a08b9/">Omer Rosenbaum</a> is <a target="_blank" href="https://swimm.io/">Swimm</a>’s Chief Technology Officer. He's the author of the Brief <a target="_blank" href="https://youtube.com/@BriefVid">YouTube Channel</a>. He's also a cyber training expert and founder of Checkpoint Security Academy. He's the author of <a target="_blank" href="https://www.freecodecamp.org/news/gitting-things-done-book/">Gitting Things Done</a> (in English) and <a target="_blank" href="https://data.cyber.org.il/networks/networks.pdf">Computer Networks (in Hebrew)</a>. You can find him on <a target="_blank" href="https://twitter.com/Omer_Ros">Twitter</a>.</p>
<h3 id="heading-additional-references"><strong>Additional References</strong></h3>
<ul>
<li><a target="_blank" href="https://www.youtube.com/playlist?list=PL9lx0DXCC4BMS7dB7vsrKI5wzFyVIk2Kg">Computer Networks Playlist - on my Brief channel</a></li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Troubleshoot Your Network on Linux – OSI Model Troubleshooting Guide ]]>
                </title>
                <description>
                    <![CDATA[ In the world of networking, you may find yourself troubleshooting problems such as difficulty connecting to other computers or to SSH, problems with IP tables, or being unable to access websites. However, have you ever attempted to troubleshoot your ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-troubleshoot-network-on-linux/</link>
                <guid isPermaLink="false">66b9f9cd01c4f505a2083107</guid>
                
                    <category>
                        <![CDATA[ Linux ]]>
                    </category>
                
                    <category>
                        <![CDATA[ network ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Nitheesh Poojary ]]>
                </dc:creator>
                <pubDate>Mon, 25 Mar 2024 17:34:59 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2024/03/taylor-vick-M5tzZtFCOfs-unsplash.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In the world of networking, you may find yourself troubleshooting problems such as difficulty connecting to other computers or to SSH, problems with IP tables, or being unable to access websites.</p>
<p>However, have you ever attempted to troubleshoot your network by applying the OSI Model? Through the use of a bottom-to-top methodology that is based on the Open Systems Interconnection (OSI) architecture, we will uncover the complexities of network troubleshooting, providing you with the knowledge and tools that are essential for effectively addressing a wide variety of networking difficulties.</p>
<h2 id="heading-what-is-the-osi-model-open-systems-interconnection">What is the OSI Model (Open Systems Interconnection)?</h2>
<p>The Open Systems Interconnection (OSI) model is a conceptual framework that categorizes the functions of network communications into seven distinct levels. To put it simply, the OSI standardizes how various computer systems can communicate with one another.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/03/Screenshot-2024-03-24-at-15.28.35.png" alt="Image" width="600" height="400" loading="lazy">
<em>seven layers of the OSI model</em></p>
<h2 id="heading-how-to-troubleshoot-a-website-by-applying-the-osi-model-principles">How to Troubleshoot a Website by Applying the OSI Model Principles</h2>
<p>Consider the following example of troubleshooting a website hosted on your server that is not working. We'll use Linux as our operating system. I believe that the divide and rule is a better technique for debugging. </p>
<p>The OSI model is one method for efficiently breaking down an issue so that you can methodically simplify the environment in order to discover a solution and conquer it.</p>
<h3 id="heading-physical-layer">Physical Layer</h3>
<p>As I previously stated, when it comes to debugging, it is usually preferable to begin from the bottom. The physical layer is the bottom layer in the OSI Model. The key components in this layer consist of ethernet cables, hubs, and switches. At this level, you should check the power supply and the status of devices, as well as examine interface statistics.</p>
<ul>
<li>The "ifconfig" tool provides a detailed overview of all the ethernet cards present in your system.</li>
<li>In addition, you have a choice of using the "IP link show" commands. If the result shows "down," it suggests that layer1 is not functioning.</li>
<li>Sometimes, ethernet connections may be physically connected to the server but not activated by default. To enable, use the command below.</li>
</ul>
<pre><code class="lang-bash">IP link <span class="hljs-built_in">set</span> eth0 up
</code></pre>
<ul>
<li>If you're looking for more detailed information, the ethtool utility can be quite helpful. This utility provides the ability to query and modify settings. It allows you to adjust parameters such as speed, port, auto-negotiation, PCI locations, and checksum offload.</li>
</ul>
<h3 id="heading-data-link-layer">Data Link Layer</h3>
<p>The data link layer enables the transmission of data between two devices that are connected to the same network. There are two components in this layer. The first component is the medium access control (MAC) layer, which includes the operation of hardware addressing and access control. </p>
<p>The second layer is the logical link layer, which enables the creation of a logical connection between different media. A common issue in this layer is the inability of two servers to establish connectivity. Tools such as ping, traceroute, arp, macof, and Wireshark are utilized for testing the data link layer.</p>
<p>This may help in verifying correct transmission and reception of data frames among devices within the same network group.</p>
<h3 id="heading-network-layer">Network Layer</h3>
<p>The network layer's job is to make it easy for data to move between two networks. Network devices that work at Layer 3 of the OSI model are routers. A router's main job is to make it easier for networks to talk to each other. Working with IP addresses is part of this layer. </p>
<p>In this stage, you should mostly look for problems with IP addresses. You can type "ip -br address show" to see the address. You can see if your network card has been given an IP address. You might not be getting dynamic IP addresses from DHCP if you use it to get them.</p>
<p>One common problem that often comes is the lack of an upstream gateway for a specific route or the absence of a default route. When an IP packet is transmitted to a different network, it needs to be directed to a gateway for additional processing. </p>
<p>Understanding the routing of packets to their final destinations is crucial for the gateway. The routing table contains the list of gateways for various routes and can be managed using the “ip route” commands. We can also check connectivity by sending pings to the default gateway or beyond gateway.</p>
<h3 id="heading-transport-layer">Transport Layer</h3>
<p>Protocols like Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) are used by the transport layer to control network traffic between systems and make sure that data flows efficiently. </p>
<p>The transport layer is in charge of sending data packets, looking for errors, controlling the flow of data, and putting them in the right order. You may run into problems in this layer, like ports that aren't listening. Your service might not start because the port is already being used. You can see what ports are open by running "commad "netstat -antlp | grep "LISTEN"".</p>
<p>One problem that often occurs is related to remote connectivity. Consider a scenario where your local system is unable to establish a connection with a distant port, specifically HTTP on port 80.  The <code>telnet</code> command tries to create a TCP connection with the specified host and port. This capability is ideal for conducting remote TCP connectivity testing. </p>
<p>To check a remote UDP port, you can utilize the "netcat" utility.</p>
<h3 id="heading-session-layer">Session Layer</h3>
<p>This layer is responsible for facilitating the initiation and termination of communication between the two devices (for example: authentication). The period of time during which communication is initiated and terminated is referred to as the session. </p>
<p>In this layer you should be investigating credentials, certificates of the servers, the session ID and cookies of the clients</p>
<h3 id="heading-presentation-layer">Presentation Layer</h3>
<p>The presentation layer of the OSI model is responsible for formatting and transforming data in a way that allows it to be presented to the user. </p>
<p>SSL or TLS encryption methods are key parts of this layer. Here, you should be examining for encryption and decryption issues.</p>
<h3 id="heading-application-layer">Application Layer</h3>
<p>The system takes input from the user and transmits output back to the user. The Bellow Protocols function at this level. </p>
<p>You should verify the configuration files on your server for any wrong settings. Additionally, it is essential to look at the log files on the servers to get more detailed information about the issues.</p>
<ul>
<li>File Transfer Protocol (FTP)</li>
<li>Simple Mail Transfer Protocol (SMTP)</li>
<li>Secure Shell (SSH)</li>
<li>Internet Message Access Protocol (IMAP)</li>
<li>Domain Name Service (DNS)</li>
<li>Hypertext Transfer Protocol (HTTP).</li>
</ul>
<h2 id="heading-conclusion"><strong>Conclusion</strong></h2>
<p>Troubleshooting network issues in Linux can be a daunting task, but by applying the principles of the OSI model, you can systematically diagnose and resolve problems with greater efficiency. </p>
<p>Starting from the bottom layer and working your way up, we've explored various tools and techniques tailored to each level of the OSI model.</p>
<p>Beginning with the physical layer, we inspected hardware components and used tools like <code>ifconfig</code> and <code>ip link show</code> to verify connectivity. Moving up to the data link layer, we focused on MAC addresses and used utilities like <code>ping</code> and <code>Wireshark</code> for testing. At the network layer, we delved into IP addressing and routing, employing commands such as <code>ip route</code> and <code>ping</code> to diagnose issues.</p>
<p>Transitioning to the transport layer, we addressed TCP and UDP related problems, utilizing commands like <code>netstat</code> and <code>telnet</code> to check for open ports and establish connections. Further up the stack, we discussed the importance of session management and encryption at the session and presentation layers respectively.</p>
<p>Finally, at the application layer, we examined specific protocols like FTP, SMTP, SSH, and HTTP, emphasizing the significance of configuration files and log analysis in resolving issues.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What is Serialization? ]]>
                </title>
                <description>
                    <![CDATA[ By George Offley During a recent project update meeting, my team talked about how we were going to use serialization to send data back and forth from this application.  An engineer who was looking to get more into software projects told me that they ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-is-serialization/</link>
                <guid isPermaLink="false">66d45edb680e33282da25e6b</guid>
                
                    <category>
                        <![CDATA[ computer networking ]]>
                    </category>
                
                    <category>
                        <![CDATA[ data ]]>
                    </category>
                
                    <category>
                        <![CDATA[ network ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 10 Jan 2022 21:00:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/12/erica-steeves-G_lwAp0TF38-unsplash.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By George Offley</p>
<p>During a recent project update meeting, my team talked about how we were going to use serialization to send data back and forth from this application. </p>
<p>An engineer who was looking to get more into software projects told me that they were unfamiliar with the term. </p>
<p>It's easy to miss essential processes like these that don’t come up until you dive into more extensive projects. This was the case for this person, as it was for me at one point. </p>
<p>So I wanted to write about it. I helped my colleague learn about serialization that day, and you’re going to learn about it today.</p>
<h2 id="heading-what-is-serialization">What is Serialization?</h2>
<p>Serialization is the process in which one service takes in a data structure, such as a dictionary in Python, wraps it up, and transmits it to another service for reading. That’s the simple definition. </p>
<p>Imagine that I need to send a message to someone. So I write down the text on an already assembled puzzle. I take apart the pieces, add some instructions on how to reassemble the puzzle, and send it along. </p>
<p>The message recipient then gets the pieces of the puzzle, puts them all back together, and now they have my message.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/01/serialization_basic.jpeg" alt="Image" width="600" height="400" loading="lazy">
<em>Basic serialization flow of events</em></p>
<p>The technical definition is a bit more fun. To wit, serialization is the process of converting a data object into a byte stream, and saving the state of the object to be stored on a disk or transmitted across a network. This cuts down the storage size needed and makes it easier to transfer information over a network.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/01/serialization_process.jpeg" alt="Image" width="600" height="400" loading="lazy">
<em>Serialization Process</em></p>
<h3 id="heading-marshaling-and-serialization-what-are-the-differences">Marshaling and Serialization - what are the differences?</h3>
<p>The process of <a target="_blank" href="https://en.wikipedia.org/wiki/Marshalling_(computer_science)">marshaling</a> might come to mind. Marshaling is the process of transforming the memory representation of an object into a suitable form for transmission. </p>
<p>Although marshaling and serialization are <em>loosely</em> synonymous, there is a crucial difference. For example, when creating a Golang program to read JSON data into a Golang data structure, you might use marshaling to translate JSON key values into Golang key values. </p>
<p>The difference is that marshaling might be used to translate data. In contrast, serialization sends or stores data in a byte stream and reassembles it in its original form. Both do serialization, but there is a difference in intent in these two processes.</p>
<p>You can see this struct I created for interacting with Twitter data below as an example of marshaling in action. In Golang, you can give hints called tags, easily converting this object into JSON data using Golang's built-in marshaling service.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/01/golang_marshall_example.png" alt="Image" width="600" height="400" loading="lazy">
<em>Golang Struct using JSON tags</em></p>
<h3 id="heading-what-is-endianness">What is Endianness?</h3>
<p>I’d also like to touch on the subject of <a target="_blank" href="https://en.wikipedia.org/wiki/Endianness">endianness</a> lightly. Endianness is a term used to describe the order of bytes in memory. </p>
<p>You can think of memory as a block where bites of data are stored. For serialization to work, the byte stream needs to transfer data types regardless of the changing endianness from one system to another. </p>
<p>You can see the little and big-endian differences below. It is essential that the endianness matches from one system to another or be converted somehow, as not all systems order their bits the same way.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/12/endian_dif.png" alt="Little and big endian courtesy of https://pvs-studio.com/en/blog/lessons/0019/ " width="600" height="400" loading="lazy">
<em>Little and big-endian Courtesy of https://pvs-studio.com/en/blog/lessons/0019/</em></p>
<h2 id="heading-use-cases-for-serialization">Use Cases for Serialization</h2>
<p>Our use case takes full advantage of these features. We plan to take in some information from the hardware we’re scanning, package up that information into a byte stream, and send it along with the network to another service that will reconstruct the data. </p>
<p>The process of reversing the serialization process and reconstructing the data back into its original form is called <strong>deserialization</strong>.</p>
<p>There are other use cases for this. For example, REST APIs or messaging protocols such as AMQP can use serialization to compress and send data. </p>
<p>AMQP is a messaging protocol where you send messages to an AMQP broker, and the receiving service is “listening” to this broker for a message. Backend engineers might know this well, as this is often used for sending data back and forth within distributed systems. </p>
<p>Many programming languages include the ability to spin up some serialization easily. So it is a language-agnostic topic.</p>
<h3 id="heading-serialization-example">Serialization Example</h3>
<p>Let’s give a quick example. This code uses the library <a target="_blank" href="https://github.com/celery/kombu">kombu</a> to send messages via AMQP. We’re using this to send messages from one software package to another over a network. This code is for a service sending a message to an AMQP broker:</p>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">send_message</span>(<span class="hljs-params">self, payload, sender_serializer</span>):</span>
...
    <span class="hljs-keyword">try</span>:
        producer.publish(
            {<span class="hljs-string">'payload'</span>: message},
            ...
            serializer = <span class="hljs-string">'json'</span>,
            ...
        )
        <span class="hljs-keyword">return</span>
</code></pre>
<p>Take note of the <code>publish</code> method. We are passing in the serialization method as an argument so that the library knows how to serialize the data we are passing in.</p>
<p>The data message is converted into a stream of bytes, which, if you look at it, just looks like a long string of letters and numbers, and we send the message. </p>
<p>The corresponding service will use the same serialization method to reconstruct the data in its original state. This is a significant feature as we are creating a suite of tools that need to be able to send messages to each other for them to work.</p>
<h2 id="heading-serialization-data-formats">Serialization Data Formats</h2>
<p>I use <a target="_blank" href="https://www.json.org/json-en.html">JSON</a> for serialization whenever the task at hand calls for it. However, you can also use a few others. </p>
<p>JSON has a lot of overhead, but the human readability makes it ideal for me. You can also use <a target="_blank" href="https://developers.google.com/protocol-buffers">Protobufs</a>, <a target="_blank" href="https://en.wikipedia.org/wiki/YAML">YAML</a>, or XML. Those are just some of the data object formats you can use.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>I’m glad I got this out of my system. I got to stop thinking about this, and, hopefully, someone learned something from it. </p>
<p>Serialization becomes essential when you’re putting together your communication pipeline. It’s good to know about this topic to feel confident approaching whatever tool you are using with the proper background knowledge.</p>
<p>-George</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ TCP vs. UDP — What's the Difference and Which Protocol is Faster? ]]>
                </title>
                <description>
                    <![CDATA[ If you're getting into computer networking, or if you've dug through the network settings of some applications, you've likely seen these terms: TCP and UDP. TCP, which stands for Transmission Control Protocol, and UDP, or User Datagram Protocol, are ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/tcp-vs-udp/</link>
                <guid isPermaLink="false">66ac88379e10a480c13037db</guid>
                
                    <category>
                        <![CDATA[ computer network ]]>
                    </category>
                
                    <category>
                        <![CDATA[ computer networking ]]>
                    </category>
                
                    <category>
                        <![CDATA[ internet ]]>
                    </category>
                
                    <category>
                        <![CDATA[ network ]]>
                    </category>
                
                    <category>
                        <![CDATA[ networking ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Kristofer Koishigawa ]]>
                </dc:creator>
                <pubDate>Mon, 28 Jun 2021 12:06:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/07/ian-battaglia-9drS5E_Rguc-unsplash.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>If you're getting into computer networking, or if you've dug through the network settings of some applications, you've likely seen these terms: TCP and UDP.</p>
<p>TCP, which stands for Transmission Control Protocol, and UDP, or User Datagram Protocol, are part of the internet protocol suite. TCP and UDP are different methods to send information across the internet.</p>
<p>But even knowing what they stand for, it's hard to know which protocol you should use, or why you would use one over the other.</p>
<p>In this article, we'll go over computer networking basics, the differences between TCP and UDP, when each is used, and more.</p>
<h2 id="heading-computer-networking-basics">Computer Networking Basics</h2>
<p>Before diving into how TCP and UDP work, it's helpful to know the basics about how the internet works.</p>
<p>Generally speaking, the internet is a network of connecting devices. Each device, whether it's your smartphone or a server, communicate through the internet protocol suite.</p>
<p>The internet protocol suite is a collection of different protocols, or methods, for devices to communicate with each other. Both TCP and UDP are major protocols within the internet protocol suite:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/07/internet-protocol-suite-diagram.gif" alt="Basic diagram of the internet protocol suite." width="600" height="400" loading="lazy">
<em><a target="_blank" href="https://www.sciencedirect.com/topics/computer-science/internet-protocol-suite">Source</a></em></p>
<p>Each device that's connected to the internet has a unique IP address. And whenever two devices communicate over the internet, they're likely using either TCP or UDP to do so.</p>
<p>Here's a brief comparison between the two:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/07/tcp-vs-udp-diagram.png" alt="Diagram comparing TCP and UDP" width="600" height="400" loading="lazy">
<em><a target="_blank" href="https://www.wowza.com/blog/udp-vs-tcp">Source</a></em></p>
<p>For an even higher-level overview of how the internet works, check out this five minute video:</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/7_LPdttKXPc" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
<h2 id="heading-what-is-tcp">What is TCP?</h2>
<p>TCP, or Transmission Control Protocol, is the most common networking protocol online. TCP is extremely reliable, and is used for everything from surfing the web (HTTP), sending emails (SMTP), and transferring files (FTP).</p>
<p>TCP is used in situations where it's necessary that all data being sent by one device is received by another completely intact.</p>
<p>For example, when you visit a website, TCP is used to guarantee that everything from the text, images, and code needed to render the page arrives. Without TCP, images or text could be missing, or arrive in the incorrect order, breaking the page.</p>
<p>TCP is a connection-oriented protocol, meaning that it establishes a connection between two devices before transferring data, and maintains that connection throughout the transfer process.</p>
<p>To establish a connection between two devices, TCP uses a method called a three-way handshake:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/07/tcp-three-way-handshake-simple.png" alt="Image" width="600" height="400" loading="lazy">
<em><a target="_blank" href="https://www.techopedia.com/definition/10339/three-way-handshake">Source</a></em></p>
<p>For example, to read this article on your device, your device first sent a message to the freeCodeCamp News server called an SYN (Synchronize Sequence Number).</p>
<p>Then the freeCodeCamp News server sends back an acknowledgement message called a SYN-ACK.</p>
<p>When your device receives the SYN-ACK from the server, it sends an ACK acknowledgment message back, which establishes the connection.</p>
<p>Once a TCP connection is established between two devices, the protocol guarantees that all data is transmitted.</p>
<p>Going back to the example of your device and freeCodeCamp News, once the three-way handshake is complete, the News server can start sending all the data your device's web browser needs to render this article.</p>
<p>All devices break up data into small packets before sending them over the internet. Those packets then need to be reassembled on the other end.</p>
<p>So when the freeCodeCamp News server sends the HTML, CSS, images, and other code for this article, it breaks everything into small packets of data before sending them to your device. Your device then reassembles those packets into the files and images it needs to render this article.</p>
<p>TCP ensures that these packets all arrive to your device. If any packets are lost along the way, TCP makes it easy for your device to let the server know it's missing data, and for the server to resend those packets.</p>
<p>Once your device receives all the data it needs to render the article, TCP automatically terminates the connection between the two devices with a method similar to the three-way handshake, this time using FIN and ACK packets.</p>
<h2 id="heading-what-is-udp">What is UDP?</h2>
<p>UDP, or User Datagram Protocol, is another one of the major protocols that make up the internet protocol suite. UDP is less reliable than TCP, but is much simpler.</p>
<p>UDP is used for situations where some data loss is acceptable, like live video/audio, or where speed is a critical factor like online gaming.</p>
<p>While UDP is similar to TCP in that it's used to send and receive data online, there are a couple of key differences.</p>
<p>First, UDP is a connectionless protocol, meaning that it does not establish a connection beforehand like TCP does with its three-way handshake.</p>
<p>Next, UDP doesn't guarantee that all data is successfully transferred. With UDP, data is sent to any device that happens to be listening, but it doesn't care if some of it is lost along the way. This is one of the reasons why UDP is also known as the "fire-and-forget" protocol.</p>
<p>A good way to think about these differences is that TCP is like a conversation between two people. Person A asks person B to talk. Person B says sure, that's fine. Person A agrees and they both start speaking.</p>
<p>UDP is more like a protester outside with a megaphone. Everyone who is paying attention to the protester should hear most of what they're saying. But there's no guarantee that everyone in the area will hear what the protester is saying, or that they're even listening.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/07/udp-and-tcp-comparison.jpg" alt="A diagram comparing UDP and TCP connections" width="600" height="400" loading="lazy">
<em>UDP vs TCP — <a target="_blank" href="https://www.dpstele.com/snmp/transport-requirements-udp-tcp.php">Source</a></em></p>
<h2 id="heading-which-is-faster-tcp-or-udp">Which is Faster – TCP or UDP?</h2>
<p>In general, UDP is the faster protocol.</p>
<p>UDP is much simpler, and doesn't try to establish a connection between devices before sending data, or verify that all the data even arrived. It simply sends out data to any device that requests it, and keeps doing that until the other device disconnects or there is no more data left to send.</p>
<p>Think drinking from a hose rather than sipping from a bottle. You'll quench your thirst either way, but will probably end up with a damp shirt using the former method.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/07/tcp-vs-udp-meme.png" alt="A meme showing one person drinking from a water bottle to represent TCP, and another person pouring water from a bottle onto their face to represent UDP." width="600" height="400" loading="lazy">
_Not a hose, but still pretty accurate. Also imagine that the TCP bottle keeps asking if you received water while you drink from it. <a target="_blank" href="https://www.reddit.com/r/ProgrammerHumor/comments/9gcwgw/tcp_vs_udp/e63axmd/">Source</a>_</p>
<p>But being faster doesn't mean that UDP is the better protocol overall. It just means that it's better in certain situations.</p>
<p>As mentioned earlier, TCP is necessary in situations where it's vital that all data packets are sent in order, and that all packets arrive. The web just wouldn't function without TCP.</p>
<p>And while TCP is slower because of the way it establishes connections, and due to the checks for missing packets, it can still be blazing fast. Because they're on the web and use HTTP, sites like YouTube or Netflix all use TCP to send data to your devices.</p>
<p>TCP also allows for buffering, so your browser can request and load more data as you watch, allowing for smooth playback and for you to skip ahead to other parts of the video.</p>
<p>UDP is the better choice for live video and audio or online games where speed is more important than potential data loss.</p>
<p>When you make a call over Google Meet or Zoom, your video and audio are being transmitted over UDP. If some packets are lost along the way, it'll just appear as a bit of lag or clipped video/audio.</p>
<p>If you play video games, you might think that the way TCP ensures all data packets arrive at the other device would make it the ideal choice. But in reality, all the checking and resending data that TCP does just adds latency.</p>
<p>Game developers have found other clever ways to ensure that player input and state are as accurate as possible. If you're interested in reading more about why UDP is preferred for online gaming, check out <a target="_blank" href="https://gafferongames.com/post/udp_vs_tcp/">this article</a>.</p>
<h2 id="heading-fin">FIN</h2>
<p>I hope this article helped you understand some of the nuances between TCP and UDP. And if someone asks which is faster, tell 'em what you read here: "UDP is faster, <em>but</em>..."</p>
<p>And if you like what you read, let me know over on <a target="_blank" href="https://twitter.com/kriskoishigawa">Twitter</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Ping Definition ]]>
                </title>
                <description>
                    <![CDATA[ In computer science, networking, and gaming, ping can refer to a few different things. Most commonly ping refers to the act of sending a packet or signal to another device and listening for a response. This is usually done to measure the speed of the... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/ping-definition/</link>
                <guid isPermaLink="false">66c35c9971e87702d4e5b724</guid>
                
                    <category>
                        <![CDATA[ computer networking ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Computers ]]>
                    </category>
                
                    <category>
                        <![CDATA[ network ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Tech Terms ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Tue, 20 Apr 2021 06:33:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/04/alina-grubnyak-ZiQkhI7417A-unsplash.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In computer science, networking, and gaming, ping can refer to a few different things.</p>
<p>Most commonly ping refers to the act of sending a packet or signal to another device and listening for a response. This is usually done to measure the speed of the network, or to determine the status of a computer or server.</p>
<p>The term ping was coined in the early 1980s by Mike Muuss, who chose the word because of its similarities to the way sonar works and sounds. Muuss also developed the first ping program to diagnose network issues.</p>
<p>A version of the ping program should be installed by default on all modern operating systems.</p>
<p>To use ping, just open the command line for your system and type <code>ping</code> followed by an IP address or a host name, then press enter. To exit the ping utility, just press CTRL + C.</p>
<p>For example, if you run <code>ping www.freecodecamp.org</code>, you'll see something like this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/04/image-109.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/04/image-110.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Each line shows information for each probe or ping packet that's sent out. Some of the post important information is at the end of the line. This shows the time in milliseconds it took to send out a packet and receive it back from the other server or computer.</p>
<p>And when you stop the ping utility, you'll see a summary of all the ping attempts:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/04/image-111.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Ping can also refer to the latency or response time of a network itself. This definition is usually used in online gaming, where ping represents the response time between the gaming client (a console or PC), and the game's servers.</p>
<p>In this context, high ping (&gt;= 150ms) means that there will be a large delay between a player's action in the game and the game's response. And low ping (around 20-50ms) means that the time between a player's action and the game's response is minimal.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ P2P Definition ]]>
                </title>
                <description>
                    <![CDATA[ P2P, or peer-to-peer, is a general term that describes a network or form of communication where two devices communicate directly. Usually when you visit a website, your browser sends a request to a server. The server then sends you back all the files... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/p2p-definition/</link>
                <guid isPermaLink="false">66c35c73c7095d76345eaff4</guid>
                
                    <category>
                        <![CDATA[ network ]]>
                    </category>
                
                    <category>
                        <![CDATA[ networking ]]>
                    </category>
                
                    <category>
                        <![CDATA[ payments ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Tech Terms ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Tue, 06 Apr 2021 09:03:00 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/6075550b776bd507fe31ed37.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>P2P, or peer-to-peer, is a general term that describes a network or form of communication where two devices communicate directly.</p>
<p>Usually when you visit a website, your browser sends a request to a server. The server then sends you back all the files (HTML, CSS, images, and so on) for your browser to render the website.</p>
<p>But if the server has a problem, you wouldn't be able to get all those files, and can't visit the site.</p>
<p>In a peer-to-peer network, a bunch of computers connect to each other and all act as small servers. If one computer in a peer-to-peer network goes offline, the other computers can fill in for it.</p>
<p>Several years ago, Spotify was one of the largest peer-to-peer networks. Back then, they leveraged P2P networking as a way to provide their service using their customer's bandwith. Now Spotify uses central servers that they control.</p>
<p>P2P can also be applied to other things like payments. In this context, it means that the payment gets sent directly to the other person. But the payment might still pass through a company's central servers, unlike a P2P network.</p>
<p>For example, if you send $20 to your friend with a P2P payments app like Venmo, they will receive the money instantly. Your friend can then transfer the money from Venmo to their bank account, or send it to someone else.</p>
<p>But if you use a traditional money wiring service, you will need your friend's bank information to send the money directly to their account. Also, the transfer might have fees, and take several days.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What is a LAN? The Local Area Network Explained in Plain English ]]>
                </title>
                <description>
                    <![CDATA[ A local area network (LAN) is really nothing more than a structure for organizing and protecting network communications for all the devices running within a single home or office. Let me break that down a bit. When I say, within a single home or offi... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-is-a-lan-local-area-network-explained-in-plain-english/</link>
                <guid isPermaLink="false">66b99667d9d170feecefbba8</guid>
                
                    <category>
                        <![CDATA[ computer networking ]]>
                    </category>
                
                    <category>
                        <![CDATA[ network ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ David Clinton ]]>
                </dc:creator>
                <pubDate>Mon, 20 Jul 2020 20:24:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/07/server-311338_640.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>A local area network (LAN) is really nothing more than a structure for organizing and protecting network communications for all the devices running within a single home or office.</p>
<p>Let me break that down a bit. When I say, <em>within a single home or office</em>, I mean all the devices that are connected through either a physical or wireless connection to a network router. That router might be a WiFi access point or the modem your internet service provider (ISP) gave you. </p>
<p>By <em>organizing</em> I mean each device is given an identifying address, and its access to the internet beyond your local network is defined. </p>
<p>And by <em>protecting</em> I mean that, generally, traffic requests directed at your devices from external networks will be scanned and filtered to help prevent unauthorized and potentially dangerous access. </p>
<p>Based in part on <a target="_blank" href="https://www.amazon.com/gp/product/1617294934/ref=as_li_tl?ie=UTF8&amp;camp=1789&amp;creative=9325&amp;creativeASIN=1617294934&amp;linkCode=as2&amp;tag=projemun-20&amp;linkId=1a460c0cd9a39e01821133b90632cba8">content from my Linux in Action book</a>, I'll try to explain how all that works.</p>
<h1 id="heading-ipv4-addressing">IPv4 addressing</h1>
<p>Here's how that might look. The Router in this image has a <em>public</em> IP address of 183.23.100.34 to which all incoming and outgoing traffic is associated. </p>
<p>At the same time, the router acts as a Dynamic Host Configuration Protocol (DHCP) server, assigning <em>private</em> IP addresses to all the PCs, laptops, smartphones, and servers in the house. The devices will use those addresses whenever they talk to each other.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/07/lan-figure1.png" alt="Image" width="600" height="400" loading="lazy">
<em>A typical local area network (LAN) topography</em></p>
<p>Notice how all the local devices are described as using something called "NAT IP addresses." NAT stands for Network Address Translation, and it's the method used for organizing devices within a private LAN. </p>
<p>But why? What's wrong with giving all devices the same kind of public IP address the router has?</p>
<p>In the beginning, there was IPv4. IPv4 addresses are 32-bit numbers made up of four 8-bit octets separated by dots. Here's what that might look like:</p>
<pre><code><span class="hljs-number">192.168</span><span class="hljs-number">.1</span><span class="hljs-number">.10</span>
</code></pre><h1 id="heading-subnet-notation">Subnet notation</h1>
<p>Because it’s critically important to make sure systems know what kind of subnet a network address is on, we need a standard notation that can accurately communicate which octets are part of the network and which are available for devices. </p>
<p>There are two commonly used standards: Classless Inter-Domain Routing (CIDR) notation and netmask. </p>
<p>Using CIDR, one network might be represented as 192.168.1.0/24. The /24 tells you that the first three octets (8×3=24) make up the network portion, leaving only the fourth octet for device addresses. The second network (or subnet), in CIDR, would be described as 192.168.2.0/24.</p>
<p>These same two networks could also be described through a netmask of 255.255.255.0. That means all 8 bits of each of the first three octets are used by the network, but none of the fourth.</p>
<h1 id="heading-understanding-private-networks">Understanding private networks</h1>
<p>In theory, the IPv4 protocol allows for around four billion unique addresses, ranging from 1.0.0.0 to 255.255.255.255. </p>
<p>But even if all four billion of those addresses were practically available, it still wouldn't come close to covering each of the billions of cell phones, billions of laptop and desktop computers, and billions more network-connected cars, appliances, and Internet of Things devices that are already out there. To say nothing of the billions more that're coming soon.</p>
<p>So network engineers set aside three ranges of IPv4 addresses to be used exclusively in private networks. Devices using any address from those ranges will not be directly reachable from the public internet and will not be able to access internet resources. These are the three ranges:</p>
<pre><code>Between <span class="hljs-number">10.0</span><span class="hljs-number">.0</span><span class="hljs-number">.0</span> and <span class="hljs-number">10.255</span><span class="hljs-number">.255</span><span class="hljs-number">.255</span>
Between <span class="hljs-number">172.16</span><span class="hljs-number">.0</span><span class="hljs-number">.0</span> and <span class="hljs-number">172.31</span><span class="hljs-number">.255</span><span class="hljs-number">.255</span>
Between <span class="hljs-number">192.168</span><span class="hljs-number">.0</span><span class="hljs-number">.0</span> and <span class="hljs-number">192.168</span><span class="hljs-number">.255</span><span class="hljs-number">.255</span>
</code></pre><p>Remember what the "T" in NAT stood for? It was "Translation." What that means is that a NAT-enabled router will take the private IP addresses used in traffic requests between the LAN and the internet and <em>translate</em> them to the router's own public address. The router, true to its name, will then <em>route</em> those requests to their appropriate destinations.</p>
<p>This simple redesign of network addressing saved many billions of addresses for use with devices - like cell phones - that weren't part of a private network. All those laptops, PCs, and so on running in all those homes and offices would conveniently (and seamlessly) share their routers' public IPs.</p>
<p>Problem solved? Well, not quite. You see, even with all that efficient use of addresses, there still won't be enough for the explosion of public-facing devices coming online. To manage that problem, more network engineers came up with the <em>IPv6</em> protocol. Here's what an IPv6 address might look like:</p>
<pre><code><span class="hljs-number">2002</span>:<span class="hljs-number">0</span>df6:<span class="hljs-number">0001</span>:<span class="hljs-number">004</span>b:<span class="hljs-number">0100</span>:<span class="hljs-number">6</span>c2e:<span class="hljs-number">0370</span>:<span class="hljs-number">7234</span>
</code></pre><p>That looks nasty, doesn't it? And it looks like it's a much bigger number than that wimpy IPv4 example from before.</p>
<p>Yup and yup. I've gotten pretty good at remembering some kinds of IPv4 addresses, but I've never even tried to "download" one of these monsters. </p>
<p>For one thing, it's hexadecimal, meaning it uses the numbers between 0 and 9 <em>and</em> the first six letters of the alphabet (a-f)! Besides that, there are eight octets rather than four, and the address is 128-bit rather than 32-bit.</p>
<p>All of which means that, once the protocol is fully implemented, we won't be at risk of running out of addresses for a very, very long time (meaning: forever). And what <em>that</em> means is that, from the perspective of address allocation, there's no longer any need for private NAT networks. </p>
<p>Although, for security considerations, you'll still want to give your devices some protection within your LAN.</p>
<p><em>There's much more administration goodness in the form of books, courses, and articles available at my <a target="_blank" href="https://bootstrap-it.com/">bootstrap-it.com</a>.</em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ An introduction to HTTP: Exploring Telecommunication in Computer Systems ]]>
                </title>
                <description>
                    <![CDATA[ By Cher Don Get to know the Open Systems Interconnection model Overview Throughout this series, we will be tackling the basics such as:(Part 1) How does DNS work?(Part 2) Network Stack, OSI Model [You are here!](Part 3) HTTP Methods and Formats(Part... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/an-introduction-to-http-understanding-the-open-systems-interconnection-model-9dd06233d30e/</link>
                <guid isPermaLink="false">66c3443793db2451bd44140b</guid>
                
                    <category>
                        <![CDATA[ https ]]>
                    </category>
                
                    <category>
                        <![CDATA[ network ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 10 Sep 2018 16:29:27 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*7pzeTboIfH5UxaFnVnGhnA.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Cher Don</p>
<h4 id="heading-get-to-know-the-open-systems-interconnection-model">Get to know the Open Systems Interconnection model</h4>
<p><img src="https://cdn-media-1.freecodecamp.org/images/AboxQNs-z1kZCMDrUuPqdsHzdyVLBBE5MeFL" alt="Image" width="800" height="418" loading="lazy"></p>
<h3 id="heading-overview">Overview</h3>
<p>Throughout this series, we will be tackling the basics such as:<br><a target="_blank" href="https://medium.freecodecamp.org/an-introduction-to-http-domain-name-system-servers-b3e7060eca98">(Part 1) How does DNS work?</a><br>(Part 2) Network Stack, OSI Model <em>[You are here!]</em><br>(Part 3) HTTP Methods and Formats<br>(Part 4) Client Identification<br>(Part 5) Basic/Digest Authentication<br>(Part 6) HTTPS working with SSL/TLS</p>
<h3 id="heading-osi-model">OSI Model</h3>
<p>The Open Systems Interconnection (OSI) Model is a standardized model for telecommunication in computer systems. It does not regard the underlying technology, but instead the layers involved in communication. Let us explore the different layers within the OSI Model:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/Yc4ZTugFjR4A1zuGQqAQbN6Ez77yBttblRUI" alt="Image" width="800" height="450" loading="lazy">
<em>Typical 5-layered OSI Model</em></p>
<h3 id="heading-1-application-layer">1. Application Layer</h3>
<p>This layer allows applications to communicate over the network once the connection has been established, such as from the Web Browser (Application) to the Server. Examples of protocols in this layer include HTTP and TELNET.</p>
<h4 id="heading-hypertext-transfer-protocol-http">HyperText Transfer Protocol (HTTP)</h4>
<p>A set of rules for transferring files over the Internet. For example, when you enter the URL into the browser, the browser sends an HTTP request for the webpage. The host would then return the webpage, together with all the elements that are within, such as images, text, videos, styling fonts, etc.</p>
<h3 id="heading-2-transport-layer">2. Transport Layer</h3>
<p>This layer is responsible for the host-to-host communication of messages. Examples of protocols in this layer include TCP and UDP.</p>
<h4 id="heading-transmission-control-protocol-tcp">Transmission Control Protocol (TCP)</h4>
<p>The most common connection-oriented protocol. It defines how to establish and maintain a network conversation. It is responsible for establishing a connection (called a <em>socket</em>) between the client and the host in a 3-way handshake.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/aZwDUnYpTUmP4-20iIQpxYRqP2PGJRAI52N5" alt="Image" width="568" height="203" loading="lazy"></p>
<p>The user requesting the data will send a SYN data packet to the server, requesting <em>synchronization</em>. The server will then respond with a SYN-ACK to the user, indicating that it has <em>acknowledged</em> the data packet, and would like to connect as well. The connection is hence established when the user sends the last ACK to the server.</p>
<p>TCP is the most common due to its elegance, in which it is able to offer the following:</p>
<p><strong>Connection-oriented communication</strong><br> Establish a handshake protocol between end-points to ensure connection before data is exchanged, and transmit as a data stream (data packets).</p>
<p><strong>Reliability</strong><br>Using checksums, it ensures that the data packets transmitted and received are the same. If there are missing/corrupted packets, it will request for re-transmission of the data packets by sending a NACK message to the sender.</p>
<p><strong>Order</strong><br>The data packets are numbered and transmitted. As such, TCP will ensure that the received packets are re-ordered before delivering the application.</p>
<p><strong>Flow Control</strong><br>The rate of data transmission is regulated to improve efficiency while preventing buffer overruns/underruns, where data is sent faster than the receiver is able to process it, and vice versa.<br>The mechanics behind it are explained below in the <a class="post-section-overview" href="#c804">TCP Slow Start</a> section.</p>
<p><strong>Multiplexing</strong><br>Basically, it is able to send over multiple streams of information concurrently over the same socket. These are done through different ports on the socket. We will discuss the differences between <a class="post-section-overview" href="#8aeb">Multiplexing and Pipelining</a> further along in the article.</p>
<h4 id="heading-user-datagram-protocol-udp">User Datagram Protocol (UDP)</h4>
<p>While similar to TCP, it is a connection-less protocol. It is the complete opposite of TCP, making it unreliable and unordered. Dropped packets will not be re-transmitted, causing gaps in the data.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/-YFU7rjDOESeBDk4iwsJJ3DXbF7kTF4FPKPQ" alt="Image" width="500" height="479" loading="lazy"></p>
<p>However, that makes it best for time-sensitive applications, such as voice calls over the internet (VoIP). This is because it does not require the 3-way handshake before transmitting, making it fast. In addition, dropped data packets are not a problem in VoIP, as the human ear is very good at handling the short gaps that are typical with dropped packets.</p>
<h3 id="heading-3-network-layer">3. Network Layer</h3>
<p>This layer is responsible for providing data routing paths for network connections. Basically, it moves data packets across the network with the most logical path.</p>
<h4 id="heading-internet-protocol-ip">Internet Protocol (IP)</h4>
<p>Defines the structure of the data packets, as well as labeling it with the source and destination information.</p>
<p>The source and destination information are in the form of IP Addresses, in which can be in the form <code>104.16.121.127</code>(IPv4), or <code>2001:db8:0:1234:0:567:8:1</code>(IPv6).</p>
<h3 id="heading-4-link-physical-layer">4. Link/ Physical Layer</h3>
<p>This layer is the root of the OSI model, where information is transmitted either in the Local Area Network (LAN) for the Link Layer, and a physical signal such as electrical, mechanical medium in the form of code words or symbols in the Physical Layer.</p>
<h3 id="heading-visualising-routes">Visualising Routes</h3>
<p>Using <code>tracert google.com</code>, the route can be traced from the client-side (your computer) to the host (google.com).</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/hcYgb-j6sNT4L3em4eSD-K5DzC798H6zwYDn" alt="Image" width="800" height="426" loading="lazy"></p>
<p>From above, you can see the route starting from my device <code>192.168.1.254</code> to the router <code>10.243.128.1</code>, before passing through the Internet Service Provider (ISP) located in Portugal, and so forth.</p>
<h3 id="heading-complementary-layers">Complementary Layers</h3>
<h4 id="heading-tcpip-model">TCP/IP Model</h4>
<p><img src="https://cdn-media-1.freecodecamp.org/images/75nPgdIHhsTD5xSIbj1bTjRlNryTU3291Ndo" alt="Image" width="731" height="411" loading="lazy">
<em>TCP will request for re-transmission of dropped data packets, and re-order them</em></p>
<p>IP is only responsible for the structure of the data packet. As such, it will not make amends if the data packet is corrupted, or dropped. This is where TCP comes into play, numbering the data packets before sending over to the client. At the client’s side, TCP will request for re-transmission of lost/corrupted packets, and then rearrange the packets of data.</p>
<h4 id="heading-httptcp-model">HTTP/TCP Model</h4>
<p>As we have mentioned earlier, HTTP can now make requests via the connection made by <a class="post-section-overview" href="#259f">TCP Handshake</a>. But how do they complement each other?</p>
<p><strong>HTTP Persistent Connections</strong><br>This would allow multiple HTTP request/response on a single TCP connection, as opposed to opening a new connection upon every request/response.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/-F9J9R9grtdhm7aQ1Y1ptqz1xL8Ft8c4x-0T" alt="Image" width="290" height="142" loading="lazy">
<em>Sample response for Persistent Connection</em></p>
<p>This is done through the HTTP Header, where <code>Connection: Keep-Alive</code>. On default, the connection will only close upon another response where <code>Connection: Close</code> is sent after 30 seconds of idle.</p>
<p><strong>TCP Slow Start</strong><br>As mentioned before, TCP supports <a class="post-section-overview" href="#e64e">flow control</a>. This is done through TCP Slow Start, which is a form of prevention for network congestion.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/rV1aQqU5LxUsUJaX1-jDTn1VVCpKORoM10lb" alt="Image" width="800" height="574" loading="lazy"></p>
<p>The sender has a congestion window (CWND) and the receiver has a receiver window (RWND). If the data is larger than the congestion/receiver window, there would be a buffer under/overrun respectively.</p>
<p>To prevent that, the sender will begin by sending a data packet with a small congestion window (CWND = 1), to slowly probe the receiver for its receiver window.</p>
<p>The receiver will respond with an acknowledge, prompting the sender to double the data packets each time until no acknowledge is received. At this point, the optimum number of data packets has been discovered, allowing other congestion control algorithms to keep the connection at this speed.</p>
<p><strong>Working Together</strong><br>Hence, TCP Slow Start is able to figure out the optimum number of data packets to send before the connection is closed. This will allow the amount of data sent from the host to the client to be optimized without the risk of buffer overrun (data is sent faster than it can be received).</p>
<h3 id="heading-other-http-features">Other HTTP Features</h3>
<h4 id="heading-http-pipelining">HTTP Pipelining</h4>
<p><img src="https://cdn-media-1.freecodecamp.org/images/Lw7lr7o1l1yyIyMDwRugYYE0DR4jjgNoxFuE" alt="Image" width="800" height="556" loading="lazy"></p>
<p>This feature in version HTTP/1.1 allows multiple requests to be sent at once on the same socket, without waiting for a response. However, it has been replaced by TCP Multiplexing in the newer version of HTTP/2.</p>
<p>The key difference is that although both allow for multiple requests all at once on the same socket, Pipelining would still require responses to be sent in order. It means that if the items requested are in the order (A, B, C), the client would not receive item C if item B has not been delivered properly.</p>
<p>In Multiplexing, the order does not matter. This would allow quicker delivery time.</p>
<p>These methods are best used for the idempotent method, which are methods that respond independently of the number of times requested — for example, requesting a web page multiple times will respond to the same web page.</p>
<h4 id="heading-parallel-connections">Parallel Connections</h4>
<p>Ever opened a webpage and seen multiple components of the webpage (video bar, thumbnails, buttons) load simultaneously?</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/kSoqraJbI4QgwnlADZzo32d5E2dQb2408ODU" alt="Image" width="800" height="571" loading="lazy">
_Multiple components loading simultaneously | Photo courtesy of [Cloudflare Mobile SDK](https://www.cloudflare.com/products/mobile-sdk/" rel="noopener" target="<em>blank" title=")</em></p>
<p>This is made possible with Parallel Connections, where there is more than one TCP Connection established at the same time, allowing these components to load concurrently instead of one after another.</p>
<p>However, although it might seem to load faster, it might be held back by the client’s limited bandwidth. If all Parallel Connections are competing for the limited bandwidth, each component will load proportionately slower, resulting in zero advantage in total loading speed.</p>
<h3 id="heading-conclusion">Conclusion</h3>
<p>With the OSI Model, we can easily understand the big picture of networks, and how they interact with each other from hardware to software.</p>
<p>In general, it is a great teaching tool as well as a reference for troubleshooting. The model is also useful for design, as it investigates the functions at every layer, forcing one to ponder over the design layer by layer.</p>
<p>What I have gone through so far is the OSI 5-Layer Model, whereas there is also the <a target="_blank" href="https://www.webopedia.com/quick_ref/OSI_Layers.asp">OSI 7-Layer Model</a> which also deals with Identification, Authentication and Data Encryption.</p>
<p>This is Part 2 of the HTTP Introductions Series. You can read the first article about the importance of DNS Servers in <a target="_blank" href="https://medium.freecodecamp.org/an-introduction-to-http-domain-name-system-servers-b3e7060eca98">Part 1</a>. Let’s explore the structure of HTTP Requests next in Part 3!</p>
<p>Hi! I’m <a target="_blank" href="https://www.freecodecamp.org/news/an-introduction-to-http-understanding-the-open-systems-interconnection-model-9dd06233d30e/undefined">Cher Don</a>, currently pursuing a Major in Data Science. I’m the CTO of <a target="_blank" href="https://www.linkedin.com/company/paralegal-bot/">Paralegal Bot</a>, and you can find my website below. Thanks for reading!</p>
<p><a target="_blank" href="http://www.piqued.co"><strong>Piqued;</strong></a><br><a target="_blank" href="http://www.piqued.co">_Quality Content We offer the best content for difficult to grasp concepts. We've been there, and felt the same you do…_www.piqued.co</a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Visualize the programming language influence graph ]]>
                </title>
                <description>
                    <![CDATA[ By Peter Gleeson A network visualization tutorial with Gephi and Sigma.js Here’s a preview of what we’ll be making today: the programming languages influence graph. Check out the link to explore the “design influence” relationships between over 250 p... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-visualize-the-programming-language-influence-graph-7f1b765b44d1/</link>
                <guid isPermaLink="false">66d460a6b6b7f664236cbe41</guid>
                
                    <category>
                        <![CDATA[ Gephi ]]>
                    </category>
                
                    <category>
                        <![CDATA[ data ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Data Science ]]>
                    </category>
                
                    <category>
                        <![CDATA[ network ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ technology ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Tutorial ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Sat, 30 Dec 2017 14:38:25 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*B2TjLzIuTc7OgugSSt-VAA.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Peter Gleeson</p>
<h4 id="heading-a-network-visualization-tutorial-with-gephi-and-sigmajs">A network visualization tutorial with Gephi and Sigma.js</h4>
<p>Here’s a preview of what we’ll be making today: <a target="_blank" href="http://programming-languages.herokuapp.com/">the programming languages influence graph</a>. Check out the link to explore the “design influence” relationships between over 250 programming languages past and present!</p>
<h3 id="heading-your-turn">Your turn!</h3>
<p>In today’s hyper-connected world, networks are an ubiquitous aspect of modern life.</p>
<p>Take the start of my day so far — I used London’s <strong>transport network</strong> to travel into town. Then I went into a <strong>branch</strong> of my favourite coffee shop and used my Chromebook to connect to their <strong>Wi-Fi network</strong>. Next, I logged in to the various <strong>social networking</strong> sites I frequent.</p>
<p>It’s no secret that some of the most influential companies of the last few decades owe their success to the power of networks.</p>
<p>Facebook, Twitter, Instagram, LinkedIn and other social media platforms rely on the small-world properties of social networks. This lets them connect their users with each other (and advertisers) effectively.</p>
<p>Google owes much of its current success to their early dominance of the search engine market — enabled in part through their ability to return relevant results with the help of their <a target="_blank" href="https://en.wikipedia.org/wiki/PageRank">Page Rank network algorithm</a>.</p>
<p>Amazon’s efficient distribution network allows them to offer same-day delivery in some major cities.</p>
<p>Networks are also super-important in fields such as Artificial Intelligence and Machine Learning. <a target="_blank" href="http://neuralnetworksanddeeplearning.com/">Neural networks</a> are a very active field of research. Many feature detection algorithms, essential in Computer Vision, rely heavily on <a target="_blank" href="http://www.sci.utah.edu/~gerig/CS7960-S2010/handouts/Shi-Malik-CVPR-1997.pdf">using networks to model different parts of images</a>.</p>
<p>A wide range of scientific phenomena can also be understood in terms of network models. This includes <a target="_blank" href="https://en.wikipedia.org/wiki/Quantum_graph">quantum mechanics</a>, <a target="_blank" href="https://en.wikipedia.org/wiki/Metabolic_pathway">biochemical pathways</a>, and <a target="_blank" href="https://en.wikipedia.org/wiki/Ecological_network">ecological</a> and <a target="_blank" href="https://web.stanford.edu/~jacksonm/socialnetecon-chapter.pdf">socio-economic systems</a>.</p>
<p>Given their undeniable importance, then, how can we better understand networks and their properties?</p>
<p>The mathematical study of networks is known as “<a target="_blank" href="http://mathworld.wolfram.com/Graph.html">graph theory</a>”, and is one of the more accessible branches of mathematics. This article aims to provide an introduction, assuming little prior knowledge or experience.</p>
<p>We’ll be using Python 3.x and some awesome open-source software called <a target="_blank" href="https://gephi.org/">Gephi</a> to put together a network visualization of how a range of programming languages past and present are linked by influence.</p>
<h3 id="heading-but-first">But first…</h3>
<p>What exactly is a network?</p>
<p>The examples described above give us some clues. Transport networks are made up of <strong>destinations</strong> connected by <strong>routes</strong>. Social networks are made up of <strong>individuals</strong>, connected through their <strong>relationships</strong> to one another. Google’s search engine algorithms evaluate the “rank” of different <strong>webpages</strong> by looking at which pages <strong>link</strong> out to others.</p>
<p>More generally, a network is any system that can be described in terms of <strong>nodes</strong> and <strong>edges</strong>, or in colloquial terms, “dots and lines”.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/wX7gSLvSAawXdKmCwDAecCgiCwDaESN4-d8v" alt="Image" width="512" height="394" loading="lazy">
<em>An example of nodes (languages) connected by edges (design influence)</em></p>
<p>Some systems are readily abstracted in this manner. Social networks are perhaps the most obvious example. Computer filesystems are another — folders and files are linked by their “parent” and “child” relationships.</p>
<p>But the real power of networks comes from the fact that many, many systems can be abstracted and modelled in network terms, even if at first it isn’t obvious how.</p>
<h3 id="heading-representing-networks">Representing networks</h3>
<p>We need to go a little beyond pen-and-paper sketches to analyze and describe networks mathematically. How can we turn pictures of dots and lines into numbers we can crunch?</p>
<p>One solution is to draw up an <strong>adjacency matrix</strong> to represent our network.</p>
<p>Matrices are one of those concepts that might sound a little intimidating if you’re not familiar with them, but fear not. Think of them as grids of numbers which can be used to perform many calculations all at once. Here’s an example below:</p>
<pre><code>      Python Java Scala C#
Python     <span class="hljs-number">0</span>    <span class="hljs-number">1</span>     <span class="hljs-number">0</span>  <span class="hljs-number">0</span>
Java       <span class="hljs-number">0</span>    <span class="hljs-number">0</span>     <span class="hljs-number">0</span>  <span class="hljs-number">1</span>
Scala      <span class="hljs-number">0</span>    <span class="hljs-number">1</span>     <span class="hljs-number">0</span>  <span class="hljs-number">0</span>
C#         <span class="hljs-number">0</span>    <span class="hljs-number">1</span>     <span class="hljs-number">0</span>  <span class="hljs-number">0</span>
</code></pre><p>In this matrix, the intersection of each row and column is either 0 or 1, depending on whether or not the respective languages are linked. You can check this against the illustration above!</p>
<p>For most purposes, the adjacency matrix is a good way of representing a network mathematically. From a computational perspective, however, it can sometimes be a bit cumbersome.</p>
<p>For instance, with even a relatively modest number of nodes (say 1000), there will be a much larger number of elements in the matrix (e.g., 1000² = 1,000,000).</p>
<p>Many real-world systems yield <strong>sparse networks</strong>. In these networks, most nodes only connect to a small proportion of all the others.</p>
<p>If we represented a 1000-node sparse network in computer memory as an adjacency matrix, we’d have 1,000,000 bytes of data stored in RAM. Most will be zeros. There’s got to be a more efficient way of going about this.</p>
<p>An alternative approach is to work with <strong>edge lists</strong> instead. These are exactly what they say they are. They are simply a list of which node pairs link to each other.</p>
<p>For example, the programming languages network above can be represented as follows:</p>
<pre><code>Java, Python
Java, Scala
Java, C#
C#, Java
</code></pre><p>For larger networks, this is a much more computationally efficient means of representing them. It is of course possible to generate an adjacency matrix from an edge list (and vice versa). It’s not like we have to pick one or the other.</p>
<p>Another means of representing networks are <a target="_blank" href="https://en.wikipedia.org/wiki/Adjacency_list">adjacency lists</a>. This lists every node followed by the nodes it links to. For example:</p>
<pre><code>Java: Python, Scala, C#
C#: Java
</code></pre><h3 id="heading-collecting-data-making-connections">Collecting data, making connections</h3>
<p>Any network model and visualisation will only be as good as the data used to construct it. This means, as well as ensuring the data is both accurate and complete, we also need to justify a means of inferring edges between nodes.</p>
<p>In many respects, this is <em>the</em> critical step. Any subsequent analysis and inferences made about the network depend on being able to justify the “linkage criterion”.</p>
<p>For example, in <a target="_blank" href="https://en.wikipedia.org/wiki/Social_network_analysis">social network analysis</a>, you might link people based upon whether they follow one another on social media. In molecular biology, you might link genes based upon their <a target="_blank" href="https://en.wikipedia.org/wiki/Gene_co-expression_network">co-expression</a>.</p>
<p>Often, the method used to link nodes will allow for <strong>weights</strong> to be assigned to the edges, giving a measure of “strength”.</p>
<p>For instance, in the context of online retail, you could link products based upon how often they are purchased together. Products that are frequently bought together would be linked by a higher <strong>weighted edge</strong> than products which are only sometimes bought together. Products that are bought together no more often than would be expected by chance wouldn’t be linked at all.</p>
<p>As you might imagine, the methods for linking nodes to one another can be as sophisticated as you like.</p>
<p>However, for this tutorial we’ll be using a simpler means of connecting programming languages. We’re gonna rely on the accuracy of Wikipedia.</p>
<p>For our purposes, this should be fine. Wikipedia’s success is testament that it must be doing something right. The open-source, collaborative method by which articles are written should ensure some degree of objectivity.</p>
<p>Also, its relatively consistent page structure makes it a convenient playground for trying out web-scraping techniques.</p>
<p>Another bonus is the extensive, <a target="_blank" href="https://www.mediawiki.org/wiki/API:Main_page">well-documented Wikipedia API</a>, which makes information retrieval easier still. Let’s get started.</p>
<h3 id="heading-step-1-installing-gephi">Step 1 — Installing Gephi</h3>
<p>Gephi is available on Linux, Mac and Windows. You can download it <a target="_blank" href="https://gephi.org/users/download/">here</a>.</p>
<p>For this project, I was using Lubuntu. If you’re on Ubuntu/Debian, then you can follow the steps below to get Gephi up and running. Otherwise, the installation process will likely be much the same as whatever you’re familiar with.</p>
<p>Download the latest version (at the time of writing this was v.0.9.1) of Gephi for your system. When it’s ready, you’ll need to extract the files.</p>
<pre><code>cd Downloads
tar -xvzf gephi<span class="hljs-number">-0.9</span><span class="hljs-number">.1</span>-linux.tar.gz
cd gephi<span class="hljs-number">-0.9</span><span class="hljs-number">.1</span>/bin./gephi
</code></pre><p>You may need to check your version of the Java JRE. Gephi requires a recent version. On my relatively fresh install of Lubuntu, I simply installed the default-jre, and everything worked from there.</p>
<pre><code>apt install <span class="hljs-keyword">default</span>-jre
./gephi
</code></pre><p>There’s one more step before you’re ready to get underway. In order to export the graph to the Web, you can use the <a target="_blank" href="http://sigmajs.org/">Sigma.js</a> plugin for Gephi.</p>
<p>From Gephi’s menu bar, choose the “Tools” option, and select “Plugins”.</p>
<p>Click on the “Available Plugins” tab and select “SigmaExporter” (I also installed JSON Exporter, because it’s another useful plugin to have around).</p>
<p>Hit the “Install” button and you’ll be walked through the process. You’ll need to restart Gephi once you’re done.</p>
<h3 id="heading-step-2-writing-the-python-script">Step 2 — Writing the Python script</h3>
<p>This tutorial will use Python 3.x, plus a few modules to make life easier. Using the pip module installer, run the following command:</p>
<pre><code>pip3 install wikipedia
</code></pre><p>Now, in a new directory, create a file called something like <code>script.py</code>, and open it up in your favourite code editor/IDE. Below is an outline of the main logic:</p>
<ol>
<li>First, you’ll need a <a target="_blank" href="https://en.wikipedia.org/wiki/List_of_programming_languages">list of programming languages</a> to include.</li>
<li>Next, go through that list and retrieve the HTML of the relevant Wikipedia article.</li>
<li>From this, extract a list of programming languages that each language has influenced. This will be a rough-and-ready linkage criterion.</li>
<li>While you’re at it, it’d be nice to grab some metadata about each language.</li>
<li>Finally, you’ll want to write all the data you’ve collected to a .csv file</li>
</ol>
<p>The full script can be found in <a target="_blank" href="https://gist.github.com/anonymous/2a6c841fe04ebc6d55acc259b4ac4f72">this gist</a>.</p>
<h4 id="heading-import-some-modules">Import some modules</h4>
<p>In <code>script.py</code>, start by importing a few modules which will make things easier:</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> csv
<span class="hljs-keyword">import</span> wikipedia
<span class="hljs-keyword">import</span> urllib.request
<span class="hljs-keyword">from</span> bs4 <span class="hljs-keyword">import</span> BeautifulSoup <span class="hljs-keyword">as</span> BS
<span class="hljs-keyword">import</span> re
</code></pre>
<p>OK — begin by making a list of nodes to include. This is where the <a target="_blank" href="https://github.com/goldsmith/Wikipedia">Wikipedia</a> module comes in handy. It makes accessing the <a target="_blank" href="https://www.mediawiki.org/wiki/API:Main_page">Wikipedia API</a> super-easy.</p>
<p>Add the following code:</p>
<pre><code class="lang-python">pageTitle = <span class="hljs-string">"List of programming languages"</span>
nodes = list(wikipedia.page(pageTitle).links)
print(nodes)
</code></pre>
<p>If you save and run this script, you’ll see it prints out all the links from the <a target="_blank" href="https://en.wikipedia.org/wiki/List_of_programming_languages">“List of programming languages”</a> Wikipedia article. Nice!</p>
<p>However, it’s always sensible to manually inspect any automatically collected data. A quick glance will reveal that, as well as many actual programming languages, the script has also picked up a few extra links.</p>
<p>For example, you might see “<a target="_blank" href="https://en.wikipedia.org/wiki/List_of_markup_languages">List of markup languages</a>”, “<a target="_blank" href="https://en.wikipedia.org/wiki/Comparison_of_programming_languages">Comparison of programming languages</a>” and others in there.</p>
<p>Although Gephi lets you remove nodes you’d rather not include, it wouldn’t hurt to “clean” the data before proceeding. If anything, this will save time later on.</p>
<pre><code class="lang-python">removeList = [
    <span class="hljs-string">"List of"</span>,
    <span class="hljs-string">"Lists of"</span>,
    <span class="hljs-string">"Timeline"</span>,
    <span class="hljs-string">"Comparison of"</span>,
    <span class="hljs-string">"History of"</span>,
    <span class="hljs-string">"Esoteric programming language"</span>
    ]

nodes = [i <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> nodes <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> any(r <span class="hljs-keyword">in</span> i <span class="hljs-keyword">for</span> r <span class="hljs-keyword">in</span> removeList)]
</code></pre>
<p>These lines define a list of substrings to be removed from the data. The script then goes through the data, removing any elements that contain any of the unwanted substrings.</p>
<p>In Python, this requires just one line of code!</p>
<h4 id="heading-some-helper-functions">Some helper functions</h4>
<p>Now you can start scraping Wikipedia to build up an edge list (and collect any metadata). To make this easier, first define a few functions.</p>
<h4 id="heading-grabbing-html">Grabbing HTML</h4>
<p>The first function uses the <a target="_blank" href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/">BeautifulSoup</a> module to get hold of the HTML for each language’s Wikipedia page.</p>
<pre><code class="lang-python">base = <span class="hljs-string">"https://en.wikipedia.org/wiki/"</span>

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">getSoup</span>(<span class="hljs-params">n</span>):</span>
    <span class="hljs-keyword">try</span>:
        <span class="hljs-keyword">with</span> urllib.request.urlopen(base+n) <span class="hljs-keyword">as</span> response:
            soup = BS(response.read(),<span class="hljs-string">'html.parser'</span>)
            table = soup.find_all(<span class="hljs-string">"table"</span>,class_=<span class="hljs-string">"infobox vevent"</span>)[<span class="hljs-number">0</span>]                <span class="hljs-keyword">return</span> table
     <span class="hljs-keyword">except</span>:
         <span class="hljs-keyword">pass</span>
</code></pre>
<p>This function uses the urllib.request module to get hold of the HTML for the page at <code>“https://en.wikipedia.org/wiki/” + “programming language”</code>.</p>
<p>This is then passed to BeautifulSoup, which reads and parses the HTML into an object we can use to search for information.</p>
<p>Next, use the <code>find_all()</code> method to extract the HTML element you’re interested in.</p>
<p>Here, this will be the summary table at the top of each programming language article. How can these be identified?</p>
<p>The easiest way is to visit one of the programming language pages. Here, you can simply use the browser’s Developer Tools to inspect the elements of interest.</p>
<p>The summary table has the HTML tag <code>&lt;tab</code>le&gt; and the CSS cl<code>asses "in</code>fobox<code>" and "v</code>event", so you can use these to identify the table in the HTML.</p>
<p>Specify this with the arguments:</p>
<ul>
<li><code>"table"</code> and</li>
<li><code>class_="infobox vevent"</code></li>
</ul>
<p><code>find_all()</code> returns a list of all elements that match the criteria. In order to actually specify the element you’re interested in, add the index <code>[0]</code>. If the function is successful, it returns the <code>table</code> object. Otherwise, it returns <code>None</code>.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/IrVevOkpMM7vIAcU21xwTYBfEllSPVaIzI72" alt="Image" width="315" height="416" loading="lazy">
<em>The data we’re after is in this HTML element!</em></p>
<p>With any automated data collection procedure, it’s always important to handle exceptions thoroughly. If not, then in the best case scenario the script crashes and you’ll need to start over.</p>
<p>In the worst case, you’ll end up with a data set riddled with inconsistencies and errors. This will make it a nightmare to work with down the line.</p>
<h4 id="heading-retrieve-metadata">Retrieve metadata</h4>
<p>The next function uses the <code>table</code> object to look for some metadata. Here, it searches the table for the year the language first appeared.</p>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">getYear</span>(<span class="hljs-params">t</span>):</span>
    <span class="hljs-keyword">try</span>:
        t = t.get_text()
        year = t[t.find(<span class="hljs-string">"appear"</span>):t.find(<span class="hljs-string">"appear"</span>)+<span class="hljs-number">30</span>]
        year = re.match(<span class="hljs-string">r'.*([1-3][0-9]{3})'</span>,year).group(<span class="hljs-number">1</span>)
        <span class="hljs-keyword">return</span> int(year)
    <span class="hljs-keyword">except</span>:
        <span class="hljs-keyword">return</span> <span class="hljs-string">"Could not determine"</span>
</code></pre>
<p>This short function takes the <code>table</code> object as its argument, and uses BeautifulSoup’s <code>get_text()</code> function to produce a string.</p>
<p>The next step is to create a substring called <code>year</code>. This takes the 30 characters after the first appearance of the word <code>"appear"</code>. This string should contain the year the language first appeared.</p>
<p>In order to extract just the year, use a <strong>regular expression</strong> (courtesy of the <code>re</code> module) to match any characters that begin with a digit between 1 and 3, and are followed by three digits.</p>
<pre><code class="lang-python">re.match(<span class="hljs-string">r'.*([1-3][0-9]{3})'</span>,year)
</code></pre>
<p>If this is successful, the function returns <code>year</code> as an integer. Otherwise, it returns a sad-looking “Could not determine”. You might wish to scrape further metadata — such as paradigm, designer or typing discipline.</p>
<h4 id="heading-collecting-links">Collecting links</h4>
<p>One more function for you — this time, you’ll feed in the <code>table</code> object for a given language, and hopefully receive out a list of other programming languages.</p>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">getLinks</span>(<span class="hljs-params">t</span>):</span>
    <span class="hljs-keyword">try</span>:
        table_rows = t.find_all(<span class="hljs-string">"tr"</span>)
        <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">0</span>,len(table_rows)<span class="hljs-number">-1</span>):
            <span class="hljs-keyword">try</span>:
                <span class="hljs-keyword">if</span> table_rows[i].get_text() == <span class="hljs-string">"\nInfluenced\n"</span>:
                    out = []
                    <span class="hljs-keyword">for</span> j <span class="hljs-keyword">in</span> table_rows[i+<span class="hljs-number">1</span>].find_all(<span class="hljs-string">"a"</span>):
                        <span class="hljs-keyword">try</span>:
                            out.append(j[<span class="hljs-string">'title'</span>])
                        <span class="hljs-keyword">except</span>:
                            <span class="hljs-keyword">continue</span>
                    <span class="hljs-keyword">return</span> out
            <span class="hljs-keyword">except</span>:
                <span class="hljs-keyword">continue</span>
        <span class="hljs-keyword">return</span>
    <span class="hljs-keyword">except</span>:
        <span class="hljs-keyword">return</span>
</code></pre>
<p>Woah, look at all that nesting… What is actually going on here then?</p>
<p>This function makes use of the fact that the <code>table</code> objects have a consistent structure. The information in the table is stored in rows (the relevant HTML tag is <code>&lt;</code>tr&gt; ). One of these rows will contain the<code>text</code>"\nInfluenced\n"`. The first part of the function finds which row this is.</p>
<p>Once this row has been found, you can then be pretty sure the next row contains links to each of the programming languages influenced by the current one. Find these links using <code>find_all("a")</code> — where the argument <code>"a"</code> corresponds to the HTML tag <code>&lt;a&gt;</code>.</p>
<p>For each link <code>j</code>, append its <code>["title"]</code> attribute to a list called <code>out</code>. The reason to be interested in the <code>["title"]</code> attribute is because this will match <em>exactly</em> the language’s name as stored in <code>nodes</code>.</p>
<p>For example, Java is stored in <code>nodes</code> as <code>"Java (programming language)"</code>, so you need to use this exact name throughout the data set.</p>
<p>If successful, <code>getLinks()</code> returns a list of programming languages. The rest of the function deals with exception handling, in case something should go wrong at any stage.</p>
<h4 id="heading-collecting-the-data">Collecting the data</h4>
<p>At last, you’re almost ready to sit back and let the script do its thing. It will collect the data and store it in two list objects.</p>
<pre><code class="lang-python">edgeList = [[<span class="hljs-string">"Source,Target"</span>]]
meta = [[<span class="hljs-string">"Id"</span>,<span class="hljs-string">"Year"</span>]]
</code></pre>
<p>Now write a loop that will apply the functions defined earlier to every item in <code>nodes</code>, and store the outputs in <code>edgeList</code> and <code>meta</code>.</p>
<pre><code class="lang-python"><span class="hljs-keyword">for</span> n <span class="hljs-keyword">in</span> nodes:
    <span class="hljs-keyword">try</span>:
        temp = getSoup(n)
    <span class="hljs-keyword">except</span>:
        <span class="hljs-keyword">continue</span>
    <span class="hljs-keyword">try</span>:
        influenced = getLinks(temp)
        <span class="hljs-keyword">for</span> link <span class="hljs-keyword">in</span> influenced:
            <span class="hljs-keyword">if</span> link <span class="hljs-keyword">in</span> nodes:
                edgeList.append([n+<span class="hljs-string">","</span>+link])
                print([n+<span class="hljs-string">","</span>+link])
    <span class="hljs-keyword">except</span>:
        <span class="hljs-keyword">continue</span>
    year = getYear(temp)
    meta.append([n,year])
</code></pre>
<p>This function takes each language in <code>nodes</code> and attempts to retrieve the summary table from its Wikipedia page.</p>
<p>Then, it retrieves all the languages the table lists as having been influenced by the language in question.</p>
<p>For each language that also appears in the <code>nodes</code> list, append an element to <code>edgeList</code> in the form of <code>["source,target"]</code>. In this way, you’ll build up an edge list to feed into Gephi.</p>
<p>For debugging purposes, print each element added to <code>edgeList</code> — just to be sure everything’s working as it should. If you were being extra thorough, you could add print statements to the <code>except</code> clauses, too.</p>
<p>Next, get the language’s name and year, and append these to the <code>meta</code> list.</p>
<h4 id="heading-writing-to-csv">Writing to CSV</h4>
<p>Once the loop has run, the final step is to write the contents of <code>edgeList</code> and <code>meta</code> to comma separated value (CSV) files. This is easily done with the <code>csv</code> module imported earlier.</p>
<pre><code class="lang-python"><span class="hljs-keyword">with</span> open(<span class="hljs-string">"edge_list.csv"</span>,<span class="hljs-string">"w"</span>) <span class="hljs-keyword">as</span> f: 
    wr = csv.writer(f)
    <span class="hljs-keyword">for</span> e <span class="hljs-keyword">in</span> edgeList:
        wr.writerow(e)

<span class="hljs-keyword">with</span> open(<span class="hljs-string">"metadata.csv"</span>,<span class="hljs-string">"w"</span>) <span class="hljs-keyword">as</span> f2:
    wr = csv.writer(f2)
    <span class="hljs-keyword">for</span> m <span class="hljs-keyword">in</span> meta:
        wr.writerow(m)
</code></pre>
<p>Done! Save the script, and from the terminal run:</p>
<p><code>$ python3 script.py</code></p>
<p>You should see the script printing out each source-target pair as it builds up the edge list. Make sure your internet connection is steady, and sit back while the script does its magic.</p>
<h3 id="heading-step-3-graph-building-with-gephi">Step 3 — Graph building with Gephi</h3>
<p>Hopefully you got Gephi installed and running earlier. Now you can create a new project and use the data you gathered to build a directed graph. This will show how different programming languages have influenced one another!</p>
<p>Start by creating a new project in Gephi, and switch to the “Data Laboratory” view. This provides a spreadsheet-like interface for handling data in Gephi. The first thing to do is import the edge list.</p>
<ul>
<li>Click “Import spreadsheet”.</li>
<li>Choose the <code>edge_list.csv</code> file generated by the Python script. Ensure that Gephi knows to use the commas as the separator.</li>
<li>Choose “Edge List” from the List type.</li>
<li>Click “Next” and check that you are importing both Source and Target columns as strings.</li>
</ul>
<p>This should update the Data Lab with a list of nodes. Now, import the <code>metadata.csv</code> file. This time, make sure to choose “Nodes list” from the List type.</p>
<p>Switch over to the “Preview” tab, and see how the network looks.</p>
<p>Ah… It’s just a little bit… monochrome. And messy. Like a plate of spaghetti. Let’s fix this.</p>
<h4 id="heading-making-it-pretty">Making it pretty</h4>
<p>There are all sorts of ways you can work on the presentation, and here’s where a little bit of creative freedom comes in. With network visualisations, there are essentially three things to take into consideration:</p>
<ol>
<li><strong>Positioning</strong> There are several algorithms which can generate layout patterns for a network. A popular choice is the <a target="_blank" href="https://schneide.wordpress.com/tag/fruchterman-reingold/">Fruchterman-Reingold algorithm</a>, which is available in Gephi.</li>
<li><strong>Sizing</strong> The size of nodes in a graph can be used to represent some interesting property. Often, this is a <strong>centrality measure</strong>. There are <a target="_blank" href="https://en.wikipedia.org/wiki/Centrality">many ways of measuring centrality</a>, but they all reflect the “importance” of a given node, in terms of how well-connected it is to the rest of the network.</li>
<li><strong>Coloring</strong> It is also possible to use color to show some property of a node. Often, color is used to indicate <strong>community structure</strong>. This is broadly defined as a “group of nodes which are more connected with each other than with the rest of the graph”. In a social network, this can reveal friendship, family or professional groups. There are several <a target="_blank" href="https://en.wikipedia.org/wiki/Community_structure#Algorithms_for_finding_communities">algorithms which can detect community structure</a>. Gephi comes with the <a target="_blank" href="https://en.wikipedia.org/wiki/Louvain_Modularity">Louvain method</a> built-in.</li>
</ol>
<p>To make these changes, you will need to calculate some statistics. Switch to the “Overview” window. Here you will see a panel on the right. It should contain a “Statistics” tab. Open this, and you will see a range of options.</p>
<p>Gephi comes with many inbuilt statistical capabilities. For each of them, clicking “Run” will generate a report that will reveal insights about the network.</p>
<p>Some useful ones to know include:</p>
<ul>
<li><strong>Average degree</strong> The average language is connected to about four others. The report also shows a <a target="_blank" href="https://en.wikipedia.org/wiki/Degree_distribution">degree distribution</a> graph. This reveals that most languages have very few connections, while a small proportion have many. This suggests that this is a <strong>scale-free</strong> <strong>network</strong>. Much research has been done on <a target="_blank" href="http://barabasi.com/f/124.pdf">scale-free networks</a>, and the processes that generate them.</li>
<li><strong>Diameter</strong> This network has a diameter of 12 — meaning this is the “widest” number of connections between any two languages. The average path length is just under four. This means that, on average, any two languages are separated by four edges. These figures give a measure of the “size” of the network.</li>
<li><strong>Modularity</strong> This is a score that shows how “compartmentalized” the network is. Here, the modularity score is about 0.53. This is relatively high, suggesting there are distinct modules within this network. Again, this indicates something interesting about the underlying system. Languages tend to fall into distinct “influence groups”.</li>
</ul>
<p>Anyhow, to modify the appearance of the network, head over to the left panel.</p>
<p>In the “Layout” tab, you can select which layout algorithm to use. Hit “Run” and watch the graph shift about in real-time! See which layout algorithm you think works best.</p>
<p>Above the Layout tab is the “Appearance” tab. Here, you can play with different settings for the node and edge colors, sizes and labels. These can be configured based upon attributes (including the stats you get Gephi to calculate).</p>
<p>As a suggestion, you could:</p>
<ul>
<li>Color the nodes by their Modularity attribute. This colors them according to their community membership.</li>
<li>Size the nodes by their Degree. Better connected nodes will appear larger than less connected ones.</li>
</ul>
<p>However, you should experiment and come up with a layout you like best.</p>
<p>Once you’re happy with the appearance of your graph, it is time to move on to the final step — exporting to Web!</p>
<h3 id="heading-step-4-sigmajs">Step 4 — Sigma.js</h3>
<p>Already you have built a network visualisation that can be explored in Gephi. You could choose to take a screenshot, or save the graph in SVG, PDF or PNG format.</p>
<p>However, if you installed the Sigma.js plugin earlier, then why not export the graph to HTML? This will create an interactive visualisation that you can host online, or upload to GitHub and share with others.</p>
<p>To do this, select “Export &gt; Sigma.js template…” from Gephi’s menu bar.</p>
<p>Fill in the details as required. Make sure to choose which directory you export the project to. You can change the title, legend, description, hover behavior and many other details. When you’re ready, click “OK”.</p>
<p>Now, if you navigate to the directory you exported the project to, you will see a folder containing all the files generated by Sigma.js.</p>
<p>Open up <code>index.html</code> in your favorite browser. Ta-da! There’s your network! If you know a little CSS and JavaScript, you can dive into the various generated files to tweak the output as you wish.</p>
<p>And that concludes this tutorial!</p>
<h3 id="heading-summary">Summary</h3>
<ul>
<li>Many systems can be modelled and visualised as networks. Graph theory is a branch of math that provides tools to help understand network structures and properties.</li>
<li>You used Python to scrape data from Wikipedia to build a programming languages influence graph. The linkage criterion was whether a given language was listed as an influence on another’s design.</li>
<li>Gephi and Sigma.js are open-source tools that allow you to analyze and visualize networks. They allow you to export the network in image, PDF or Web formats.</li>
</ul>
<p>Thanks for reading — I look forward to any comments or questions you might have! For a fantastic resource to learn more about graph theory, see <a target="_blank" href="https://en.wikipedia.org/wiki/Albert-L%C3%A1szl%C3%B3_Barab%C3%A1si">Albert-László Barabási</a>’s interactive <a target="_blank" href="http://barabasi.com/networksciencebook/">online book</a>.</p>
<p>The full code for this tutorial can be found <a target="_blank" href="https://gist.github.com/anonymous/2a6c841fe04ebc6d55acc259b4ac4f72">here</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
