<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Aayush Singh</title>
    <description>The latest articles on DEV Community by Aayush Singh (@singhaayush).</description>
    <link>https://dev.to/singhaayush</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2096263%2F73dbd016-ddd4-49b4-aaa9-85fb5e30ef17.jpg</url>
      <title>DEV Community: Aayush Singh</title>
      <link>https://dev.to/singhaayush</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/singhaayush"/>
    <language>en</language>
    <item>
      <title>Diving into RDBMS &amp; Data Integrity</title>
      <dc:creator>Aayush Singh</dc:creator>
      <pubDate>Sun, 13 Jul 2025 17:45:14 +0000</pubDate>
      <link>https://dev.to/singhaayush/diving-into-rdbms-data-integrity-3klk</link>
      <guid>https://dev.to/singhaayush/diving-into-rdbms-data-integrity-3klk</guid>
      <description>&lt;p&gt;This blog is the second part of my series on learning Database Management Systems (DBMS). In the first blog, I covered the basics of DBMS, and in this post, we will delve into the details of Relational Database Management Systems (RDBMS). I highly encourage you to read my previous blog before continuing with this one. So let’s get started!😁&lt;/p&gt;




&lt;h3&gt;
  
  
  What is RDBMS?
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;Relational Database Management System (RDBMS)&lt;/strong&gt; is a type of database management system that stores data in the form of &lt;strong&gt;tables&lt;/strong&gt; (also called &lt;strong&gt;relations&lt;/strong&gt;). Each table consists of &lt;strong&gt;rows&lt;/strong&gt; (records) and &lt;strong&gt;columns&lt;/strong&gt; (attributes), and the data is organized so that relationships between different tables can be easily established using &lt;strong&gt;keys&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Real-life Analogy&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Think of an RDBMS like an &lt;strong&gt;Excel workbook&lt;/strong&gt; where each sheet (table) holds data about a specific topic (like students, courses, teachers). You can &lt;strong&gt;link&lt;/strong&gt; different sheets using common columns like &lt;code&gt;Student_ID&lt;/code&gt; or &lt;code&gt;Course_ID&lt;/code&gt; — this linking is what makes it "relational."&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Features of RDBMS&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Uses tables&lt;/strong&gt; to store structured data&lt;/li&gt;
&lt;li&gt;Supports &lt;strong&gt;primary keys&lt;/strong&gt; and &lt;strong&gt;foreign keys&lt;/strong&gt; to enforce data integrity&lt;/li&gt;
&lt;li&gt;Allows &lt;strong&gt;SQL querying&lt;/strong&gt; for data manipulation&lt;/li&gt;
&lt;li&gt;Supports &lt;strong&gt;normalization&lt;/strong&gt; to remove redundancy&lt;/li&gt;
&lt;li&gt;Ensures &lt;strong&gt;data consistency and integrity&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Relational Terminologies
&lt;/h3&gt;

&lt;p&gt;Before diving deeper into relational databases, it's important to understand some basic terms used in RDBMS. These terms describe how data is structured and organized inside a relational database.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Relation (Table)&lt;/strong&gt;&lt;br&gt;
A &lt;strong&gt;relation&lt;/strong&gt; is simply a &lt;strong&gt;table&lt;/strong&gt; in an RDBMS. It represents a collection of related data entries and consists of rows and columns. Each relation has a &lt;strong&gt;unique name&lt;/strong&gt; and stores data about a particular type of object or entity.&lt;br&gt;
Example: A &lt;code&gt;Student&lt;/code&gt; table is a relation that holds data about students.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Tuple (Row / Record)&lt;/strong&gt;&lt;br&gt;
A &lt;strong&gt;tuple&lt;/strong&gt; is a single &lt;strong&gt;row&lt;/strong&gt; in a table. It represents one complete set of related data or a &lt;strong&gt;record&lt;/strong&gt;.&lt;br&gt;
Example: A single row in the &lt;code&gt;Student&lt;/code&gt; table that stores data of one student is a tuple.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cardinality&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Cardinality&lt;/strong&gt; refers to the &lt;strong&gt;number of tuples (rows)&lt;/strong&gt; in a relation.&lt;br&gt;
Example: If there are 50 students in the &lt;code&gt;Student&lt;/code&gt; table, its cardinality is 50.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Attribute (Column /Field)&lt;/strong&gt;&lt;br&gt;
An &lt;strong&gt;attribute&lt;/strong&gt; is a &lt;strong&gt;column&lt;/strong&gt; in a table. It describes a specific property or characteristic of the data stored in each row. Attributes are also referred to as &lt;strong&gt;fields&lt;/strong&gt;.&lt;br&gt;
Example: In a &lt;code&gt;Student&lt;/code&gt; table, columns like &lt;code&gt;Student_ID&lt;/code&gt;, &lt;code&gt;Name&lt;/code&gt;, and &lt;code&gt;Age&lt;/code&gt; are attributes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Domain&lt;/strong&gt;&lt;br&gt;
A &lt;strong&gt;domain&lt;/strong&gt; refers to the &lt;strong&gt;set of valid values&lt;/strong&gt; an attribute can take. For example, the domain of the &lt;code&gt;Age&lt;/code&gt; attribute could be all integer values from 15 to 100.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Degree&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Degree&lt;/strong&gt; is the &lt;strong&gt;number of attributes (columns)&lt;/strong&gt; in a relation.&lt;br&gt;
Example: If the &lt;code&gt;Student&lt;/code&gt; table has 4 columns (&lt;code&gt;Student_ID&lt;/code&gt;, &lt;code&gt;Name&lt;/code&gt;, &lt;code&gt;Age&lt;/code&gt;, &lt;code&gt;Email&lt;/code&gt;), then its degree is 4.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Properties of Relational tables
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Cells contains atomic values&lt;/li&gt;
&lt;li&gt;Values in a column are of the same kind&lt;/li&gt;
&lt;li&gt;Each row is unique&lt;/li&gt;
&lt;li&gt;No two tables can have the same name in a relational schema.&lt;/li&gt;
&lt;li&gt;Each column has a unique name&lt;/li&gt;
&lt;li&gt;The sequence of rows is insignificant&lt;/li&gt;
&lt;li&gt;The sequence of columns is insignificant.&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Data Anomalies&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;When a database is not properly structured, it can lead to &lt;strong&gt;data anomalies&lt;/strong&gt; — unexpected issues that arise when inserting, updating, or deleting data. These problems often occur when all the data is stored in &lt;strong&gt;a single large table&lt;/strong&gt; instead of being divided into related tables.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Do Data Anomalies Occur?
&lt;/h3&gt;

&lt;p&gt;Data anomalies typically occur when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A table has &lt;strong&gt;repeated data&lt;/strong&gt; (redundancy)&lt;/li&gt;
&lt;li&gt;Multiple types of data are stored together (like student + course + teacher in one table)&lt;/li&gt;
&lt;li&gt;The database is &lt;strong&gt;not normalized&lt;/strong&gt;, meaning it hasn't been structured properly into separate tables with relationships&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Types of Data Anomalies
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Insertion Anomaly&lt;/strong&gt;&lt;br&gt;
Occurs when you &lt;strong&gt;can’t insert&lt;/strong&gt; data into a table without inserting something else unnecessarily.&lt;br&gt;
&lt;strong&gt;Example:&lt;/strong&gt; If a new course is being introduced but no students have enrolled yet, you can't insert the course without leaving student-related fields blank.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Update Anomaly&lt;/strong&gt;&lt;br&gt;
Occurs when the same piece of data is stored in &lt;strong&gt;multiple places&lt;/strong&gt;, and not all copies are updated correctly.&lt;br&gt;
&lt;strong&gt;Example:&lt;/strong&gt; If a teacher's name is updated in one row but not in others, the database now holds inconsistent data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deletion Anomaly&lt;/strong&gt;&lt;br&gt;
Occurs when deleting one piece of data &lt;strong&gt;accidentally removes other useful information&lt;/strong&gt;.&lt;br&gt;
&lt;strong&gt;Example:&lt;/strong&gt; If the last student enrolled in a course is deleted from the table, the course information may also get deleted.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  How to Solve Data Anomalies?
&lt;/h3&gt;

&lt;p&gt;The most effective way to solve data anomalies is by using &lt;strong&gt;Normalization&lt;/strong&gt;. It is a process that involves:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Splitting large tables&lt;/strong&gt; into smaller, related tables&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Removing redundancy&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Organizing data into logical groupings&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We’ll explore normalization and &lt;strong&gt;normal forms (1NF, 2NF, 3NF, BCNF)&lt;/strong&gt; in upcoming sections of this blog.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Functional Dependencies (FDs)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In relational database design, &lt;strong&gt;Functional Dependency (FD)&lt;/strong&gt; is a very important concept that helps us understand how attributes (columns) relate to one another. It forms the &lt;strong&gt;foundation of normalization&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is a Functional Dependency?
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;Functional Dependency&lt;/strong&gt; exists when the value of one attribute &lt;strong&gt;uniquely determines&lt;/strong&gt; the value of another attribute in a relation (table).&lt;/p&gt;

&lt;p&gt;Let’s say we have a relation &lt;strong&gt;R&lt;/strong&gt;, and attributes &lt;strong&gt;A&lt;/strong&gt; and &lt;strong&gt;B&lt;/strong&gt;. We say:&lt;br&gt;
&lt;strong&gt;A → B&lt;/strong&gt; (A functionally determines B)&lt;br&gt;
This means: if two rows have the same value for attribute A, they &lt;strong&gt;must&lt;/strong&gt; have the same value for attribute B.&lt;/p&gt;

&lt;h3&gt;
  
  
  Simple Example
&lt;/h3&gt;

&lt;p&gt;Consider a &lt;code&gt;Student&lt;/code&gt; table:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Student_ID&lt;/th&gt;
&lt;th&gt;Name&lt;/th&gt;
&lt;th&gt;Course&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;101&lt;/td&gt;
&lt;td&gt;Alice&lt;/td&gt;
&lt;td&gt;DBMS&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;102&lt;/td&gt;
&lt;td&gt;Bob&lt;/td&gt;
&lt;td&gt;OS&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;101&lt;/td&gt;
&lt;td&gt;Alice&lt;/td&gt;
&lt;td&gt;DBMS&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Student_ID → Name&lt;/code&gt;
Because if &lt;code&gt;Student_ID&lt;/code&gt; is the same, the &lt;code&gt;Name&lt;/code&gt; must also be the same.&lt;/li&gt;
&lt;li&gt;But &lt;code&gt;Name → Student_ID&lt;/code&gt; is &lt;strong&gt;not valid&lt;/strong&gt;, because two students can have the same name.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Why Functional Dependencies Matter
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;They help us find &lt;strong&gt;candidate keys&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;They guide &lt;strong&gt;table splitting&lt;/strong&gt; in normalization&lt;/li&gt;
&lt;li&gt;They help eliminate &lt;strong&gt;data redundancy and anomalies&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Attribute Closure
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Attribute closure&lt;/strong&gt; of a set of attributes &lt;strong&gt;X&lt;/strong&gt;, denoted as &lt;strong&gt;X⁺&lt;/strong&gt;, is the set of all attributes that can be &lt;strong&gt;functionally determined&lt;/strong&gt; from X using the given set of functional dependencies.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It helps you &lt;strong&gt;check if a set of attributes is a super key&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;It helps you &lt;strong&gt;determine the minimal cover&lt;/strong&gt; of FDs&lt;/li&gt;
&lt;li&gt;It is used in &lt;strong&gt;finding candidate keys&lt;/strong&gt; during schema design&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Step-by-Step Example
&lt;/h3&gt;

&lt;p&gt;Let’s say we have a relation &lt;strong&gt;R(A, B, C, D)&lt;/strong&gt;&lt;br&gt;
And the functional dependencies (FDs) are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A → B&lt;/li&gt;
&lt;li&gt;B → C&lt;/li&gt;
&lt;li&gt;A → D&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let’s find the &lt;strong&gt;closure of A (A⁺)&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Start with A⁺ = {A}&lt;br&gt;
&lt;strong&gt;Step 2:&lt;/strong&gt; A → B → add B ⇒ A⁺ = {A, B}&lt;br&gt;
&lt;strong&gt;Step 3:&lt;/strong&gt; B → C → add C ⇒ A⁺ = {A, B, C}&lt;br&gt;
&lt;strong&gt;Step 4:&lt;/strong&gt; A → D → add D ⇒ A⁺ = {A, B, C, D}&lt;/p&gt;

&lt;p&gt;So, &lt;strong&gt;A⁺ = {A, B, C, D}&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That means &lt;strong&gt;A is a super key&lt;/strong&gt;, because it determines all attributes in the relation.&lt;/p&gt;

&lt;h3&gt;
  
  
  General Algorithm to Find Closure
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Start with X⁺ = X (initial set)&lt;/li&gt;
&lt;li&gt;Repeatedly apply all FDs where:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;If &lt;code&gt;Y → Z&lt;/code&gt; and &lt;code&gt;Y ⊆ X⁺&lt;/code&gt;, then add &lt;code&gt;Z&lt;/code&gt; to &lt;code&gt;X⁺&lt;/code&gt;

&lt;ol&gt;
&lt;li&gt;Stop when no more attributes can be added&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Armstrong’s Axioms
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Armstrong’s Axioms&lt;/strong&gt; are a set of rules or &lt;strong&gt;inference laws&lt;/strong&gt; used to &lt;strong&gt;derive all valid functional dependencies&lt;/strong&gt; from a given set. These rules are sound and complete, meaning they will only derive correct FDs and can derive all correct FDs.&lt;/p&gt;

&lt;p&gt;They form the &lt;strong&gt;theoretical foundation&lt;/strong&gt; for reasoning about functional dependencies in relational databases.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Do We Need Armstrong’s Axioms?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;To &lt;strong&gt;generate new functional dependencies&lt;/strong&gt; from a known set&lt;/li&gt;
&lt;li&gt;To &lt;strong&gt;prove&lt;/strong&gt; whether a particular FD holds&lt;/li&gt;
&lt;li&gt;To &lt;strong&gt;simplify&lt;/strong&gt; and &lt;strong&gt;minimize&lt;/strong&gt; functional dependencies&lt;/li&gt;
&lt;li&gt;To help in &lt;strong&gt;finding candidate keys&lt;/strong&gt; and in &lt;strong&gt;normalization&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Core Armstrong’s Axioms (3 Basic Rules)
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reflexivity&lt;/strong&gt;&lt;br&gt;
If Y is a subset of X, then X → Y&lt;br&gt;
Example: If X = {A, B}, then X → A and X → B are valid&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Augmentation&lt;/strong&gt;&lt;br&gt;
If X → Y, then XZ → YZ (add same attributes to both sides)&lt;br&gt;
Example: If A → B, then AC → BC&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Transitivity&lt;/strong&gt;&lt;br&gt;
If X → Y and Y → Z, then X → Z&lt;br&gt;
Example: If A → B and B → C, then A → C&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Additional (Derived) Rules
&lt;/h3&gt;

&lt;p&gt;Using the core axioms, we can derive more useful rules:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Union&lt;/strong&gt;: If X → Y and X → Z, then X → YZ&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Decomposition&lt;/strong&gt;: If X → YZ, then X → Y and X → Z&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pseudo-Transitivity&lt;/strong&gt;: If X → Y and YZ → W, then XZ → W&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are not part of the original axioms but can be &lt;strong&gt;proved&lt;/strong&gt; using them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Summary Table
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Axiom&lt;/th&gt;
&lt;th&gt;Rule Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Reflexivity&lt;/td&gt;
&lt;td&gt;If Y ⊆ X, then X → Y&lt;/td&gt;
&lt;td&gt;AB → A&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Augmentation&lt;/td&gt;
&lt;td&gt;If X → Y, then XZ → YZ&lt;/td&gt;
&lt;td&gt;A → B ⟹ AC → BC&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Transitivity&lt;/td&gt;
&lt;td&gt;If X → Y and Y → Z, then X → Z&lt;/td&gt;
&lt;td&gt;A → B, B → C ⟹ A → C&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Union&lt;/td&gt;
&lt;td&gt;If X → Y and X → Z, then X → YZ&lt;/td&gt;
&lt;td&gt;A → B, A → C ⟹ A → BC&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Decomposition&lt;/td&gt;
&lt;td&gt;If X → YZ, then X → Y and X → Z&lt;/td&gt;
&lt;td&gt;A → BC ⟹ A → B, A → C&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Pseudo-Transitivity&lt;/td&gt;
&lt;td&gt;If X → Y and YZ → W, then XZ → W&lt;/td&gt;
&lt;td&gt;A → B, BC → D ⟹ AC → D&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  When to Use Armstrong’s Axioms
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;During &lt;strong&gt;attribute closure calculation&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;To &lt;strong&gt;simplify or minimize&lt;/strong&gt; a set of FDs&lt;/li&gt;
&lt;li&gt;To prove whether an FD logically follows from a given set&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Keys in RDBMS
&lt;/h3&gt;

&lt;p&gt;In relational databases, &lt;strong&gt;keys&lt;/strong&gt; are crucial because they help &lt;strong&gt;uniquely identify rows&lt;/strong&gt; (tuples) and &lt;strong&gt;maintain data integrity&lt;/strong&gt;. Without keys, it would be difficult to retrieve, relate, or update data accurately.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is a Key?
&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;key&lt;/strong&gt; is one or more attributes (columns) that can &lt;strong&gt;uniquely identify&lt;/strong&gt; a record in a table.&lt;br&gt;
Different types of keys serve different purposes in database design.&lt;/p&gt;

&lt;h3&gt;
  
  
  Types of Keys in RDBMS
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Super Key&lt;/strong&gt;&lt;br&gt;
A &lt;strong&gt;super key&lt;/strong&gt; is any set of attributes that can uniquely identify a tuple (row) in a table.&lt;br&gt;
It may contain &lt;strong&gt;extra (redundant)&lt;/strong&gt; attributes.&lt;br&gt;
Example: &lt;code&gt;{Student_ID}&lt;/code&gt;, &lt;code&gt;{Student_ID, Email}&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Candidate Key&lt;/strong&gt;&lt;br&gt;
A &lt;strong&gt;minimal super key&lt;/strong&gt; — meaning it uniquely identifies a record, and if you remove any attribute, it no longer does.&lt;br&gt;
A table can have &lt;strong&gt;multiple candidate keys&lt;/strong&gt;.&lt;br&gt;
Example: &lt;code&gt;{Student_ID}&lt;/code&gt;, &lt;code&gt;{Email}&lt;/code&gt; (if both are unique)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Primary Key&lt;/strong&gt;&lt;br&gt;
One of the &lt;strong&gt;candidate keys&lt;/strong&gt; is selected as the &lt;strong&gt;primary key&lt;/strong&gt;.&lt;br&gt;
It &lt;strong&gt;cannot have NULL values&lt;/strong&gt; and must be &lt;strong&gt;unique&lt;/strong&gt; for each row.&lt;br&gt;
Example: &lt;code&gt;Student_ID&lt;/code&gt; is chosen as the primary key&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Alternate Key&lt;/strong&gt;&lt;br&gt;
A candidate key &lt;strong&gt;not chosen&lt;/strong&gt; as the primary key is called an &lt;strong&gt;alternate key&lt;/strong&gt;.&lt;br&gt;
Example: If &lt;code&gt;Email&lt;/code&gt; is a candidate key but not the primary key, it’s an alternate key.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Composite Key&lt;/strong&gt;&lt;br&gt;
A key that consists of &lt;strong&gt;two or more attributes&lt;/strong&gt; that together uniquely identify a record.&lt;br&gt;
Example: In a &lt;code&gt;Student_Course&lt;/code&gt; table, the combination of &lt;code&gt;Student_ID&lt;/code&gt; and &lt;code&gt;Course_ID&lt;/code&gt; can form a composite key.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Foreign Key&lt;/strong&gt;&lt;br&gt;
A &lt;strong&gt;foreign key&lt;/strong&gt; is an attribute in one table that &lt;strong&gt;refers to the primary key&lt;/strong&gt; of another table.&lt;br&gt;
It is used to establish a &lt;strong&gt;relationship&lt;/strong&gt; between two tables.&lt;br&gt;
Example: &lt;code&gt;Department_ID&lt;/code&gt; in the &lt;code&gt;Employee&lt;/code&gt; table refers to the &lt;code&gt;Department&lt;/code&gt; table.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Summary Table
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Key Type&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Example&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Super Key&lt;/td&gt;
&lt;td&gt;Any set of attributes that uniquely identifies a row&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{Student_ID, Email}&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Candidate Key&lt;/td&gt;
&lt;td&gt;Minimal super key (no redundant attributes)&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;{Student_ID}&lt;/code&gt;, &lt;code&gt;{Email}&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Primary Key&lt;/td&gt;
&lt;td&gt;Chosen candidate key; cannot be null&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Student_ID&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Alternate Key&lt;/td&gt;
&lt;td&gt;Candidate key not selected as primary key&lt;/td&gt;
&lt;td&gt;&lt;code&gt;Email&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Composite Key&lt;/td&gt;
&lt;td&gt;Key formed by combining two or more attributes&lt;/td&gt;
&lt;td&gt;&lt;code&gt;{Student_ID, Course_ID}&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Foreign Key&lt;/td&gt;
&lt;td&gt;Attribute linking to primary key of another table&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;Department_ID&lt;/code&gt; in &lt;code&gt;Employee&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h3&gt;
  
  
  Normalization &amp;amp; Normal Forms
&lt;/h3&gt;

&lt;p&gt;When a database is poorly structured, it can suffer from problems like &lt;strong&gt;data redundancy&lt;/strong&gt;, &lt;strong&gt;update anomalies&lt;/strong&gt;, and &lt;strong&gt;inconsistency&lt;/strong&gt;. This is where &lt;strong&gt;normalization&lt;/strong&gt; comes in.&lt;/p&gt;

&lt;h3&gt;
  
  
  Normalization?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Normalization&lt;/strong&gt; is a process in relational database design that organizes data into &lt;strong&gt;well-structured tables&lt;/strong&gt; to minimize redundancy and avoid anomalies.&lt;br&gt;
It involves dividing a large table into smaller, related tables and defining relationships between them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Normalize?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;To eliminate &lt;strong&gt;duplicate data&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;To reduce &lt;strong&gt;insertion, update, and deletion anomalies&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;To maintain &lt;strong&gt;data integrity&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;To make the database &lt;strong&gt;easier to maintain&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Normal Forms
&lt;/h3&gt;

&lt;p&gt;Normalization is done through a series of &lt;strong&gt;normal forms&lt;/strong&gt; — each with specific rules. Let's understand the first three main normal forms (commonly used in practice):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;First Normal Form (1NF)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A table is in 1NF if:&lt;/li&gt;
&lt;li&gt;All values in each column are &lt;strong&gt;atomic&lt;/strong&gt; (indivisible)&lt;/li&gt;
&lt;li&gt;There are &lt;strong&gt;no repeating groups&lt;/strong&gt; or arrays&lt;/li&gt;
&lt;li&gt;Example: A student should not have multiple phone numbers stored in a single column like &lt;code&gt;12345, 67890&lt;/code&gt;. Instead, store them in separate rows.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Second Normal Form (2NF)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A table is in 2NF if:&lt;/li&gt;
&lt;li&gt;It is already in &lt;strong&gt;1NF&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Every non-prime attribute&lt;/strong&gt; is &lt;strong&gt;fully functionally dependent&lt;/strong&gt; on the &lt;strong&gt;entire primary key&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Mainly applies to &lt;strong&gt;composite keys&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Removes &lt;strong&gt;partial dependency&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Example: In a &lt;code&gt;Student_Course&lt;/code&gt; table with primary key &lt;code&gt;(Student_ID, Course_ID)&lt;/code&gt;, &lt;code&gt;Student_Name&lt;/code&gt; should not depend only on &lt;code&gt;Student_ID&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Third Normal Form (3NF)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A table is in 3NF if:&lt;/li&gt;
&lt;li&gt;It is already in &lt;strong&gt;2NF&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;There is &lt;strong&gt;no transitive dependency&lt;/strong&gt; between non-key attributes&lt;/li&gt;
&lt;li&gt;Removes dependencies like: A → B, B → C, so A → C (which is transitive)&lt;/li&gt;
&lt;li&gt;Example: In a table where &lt;code&gt;Student_ID → Department_ID&lt;/code&gt; and &lt;code&gt;Department_ID → Department_Name&lt;/code&gt;, you should split the tables to avoid storing &lt;code&gt;Department_Name&lt;/code&gt; repeatedly.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Boyce-Codd Normal Form (BCNF)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A stricter version of 3NF&lt;/li&gt;
&lt;li&gt;Every determinant must be a &lt;strong&gt;candidate key&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Normal Form&lt;/th&gt;
&lt;th&gt;Key Rules&lt;/th&gt;
&lt;th&gt;Purpose&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1NF&lt;/td&gt;
&lt;td&gt;Atomic values, no repeating groups&lt;/td&gt;
&lt;td&gt;Basic structure&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2NF&lt;/td&gt;
&lt;td&gt;No partial dependency on composite keys&lt;/td&gt;
&lt;td&gt;Eliminates redundancy&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3NF&lt;/td&gt;
&lt;td&gt;No transitive dependency among non-key attributes&lt;/td&gt;
&lt;td&gt;Ensures clear relationships&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;BCNF&lt;/td&gt;
&lt;td&gt;Every determinant is a candidate key&lt;/td&gt;
&lt;td&gt;Advanced, strict 3NF&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h3&gt;
  
  
  Indexing in RDBMS
&lt;/h3&gt;

&lt;p&gt;As your database grows, searching for data can become slow. This is where &lt;strong&gt;indexing&lt;/strong&gt; comes into play. It helps make data &lt;strong&gt;retrieval faster&lt;/strong&gt; — just like how an index in a book helps you find topics quickly.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Indexing?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Indexing&lt;/strong&gt; is a database technique used to &lt;strong&gt;speed up data retrieval&lt;/strong&gt; operations on a table.&lt;br&gt;
An &lt;strong&gt;index&lt;/strong&gt; is a data structure (usually a B-tree or hash) that allows the database to find rows more quickly without scanning the entire table.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Use Indexing?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Speeds up &lt;strong&gt;SELECT&lt;/strong&gt; queries significantly&lt;/li&gt;
&lt;li&gt;Helps in &lt;strong&gt;sorting and searching&lt;/strong&gt; large datasets&lt;/li&gt;
&lt;li&gt;Improves performance when using &lt;strong&gt;WHERE&lt;/strong&gt;, &lt;strong&gt;JOIN&lt;/strong&gt;, &lt;strong&gt;ORDER BY&lt;/strong&gt;, etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Real-Life Analogy
&lt;/h3&gt;

&lt;p&gt;Think of a database table as a &lt;strong&gt;book&lt;/strong&gt; and an index as the &lt;strong&gt;table of contents&lt;/strong&gt;. Without an index, you would have to flip through every page to find what you need. With an index, you can go directly to the right page.&lt;/p&gt;

&lt;h3&gt;
  
  
  Types of Indexes
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Primary Index&lt;/strong&gt;&lt;br&gt;
Created automatically on the &lt;strong&gt;primary key&lt;/strong&gt;. Ensures uniqueness and fast lookup.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Secondary Index&lt;/strong&gt;&lt;br&gt;
Created manually on &lt;strong&gt;non-primary key&lt;/strong&gt; columns to improve performance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Composite Index&lt;/strong&gt;&lt;br&gt;
An index on &lt;strong&gt;multiple columns&lt;/strong&gt;. Useful when queries filter on more than one column.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Clustered Index&lt;/strong&gt;&lt;br&gt;
Sorts the actual data rows according to the index. A table can have &lt;strong&gt;only one&lt;/strong&gt; clustered index.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Non-Clustered Index&lt;/strong&gt;&lt;br&gt;
Stores pointers to the data instead of sorting it. A table can have &lt;strong&gt;multiple&lt;/strong&gt; non-clustered indexes.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Things to Keep in Mind
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Indexes speed up reads&lt;/strong&gt; but can &lt;strong&gt;slow down writes&lt;/strong&gt; (INSERT, UPDATE, DELETE)&lt;/li&gt;
&lt;li&gt;Over-indexing can &lt;strong&gt;waste storage&lt;/strong&gt; and affect performance&lt;/li&gt;
&lt;li&gt;Use indexing &lt;strong&gt;strategically&lt;/strong&gt; for frequently queried columns&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Type of Index&lt;/th&gt;
&lt;th&gt;Description&lt;/th&gt;
&lt;th&gt;Use Case&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Primary Index&lt;/td&gt;
&lt;td&gt;Automatically created on primary key&lt;/td&gt;
&lt;td&gt;Uniquely identify rows&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Secondary Index&lt;/td&gt;
&lt;td&gt;Manually created on other columns&lt;/td&gt;
&lt;td&gt;Improve query speed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Composite Index&lt;/td&gt;
&lt;td&gt;On multiple columns&lt;/td&gt;
&lt;td&gt;Queries involving multiple conditions&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Clustered Index&lt;/td&gt;
&lt;td&gt;Sorts actual data rows&lt;/td&gt;
&lt;td&gt;Faster range queries&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Non-Clustered Index&lt;/td&gt;
&lt;td&gt;Stores pointers to rows&lt;/td&gt;
&lt;td&gt;Multiple fast lookups on big tables&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;p&gt;Thanks For Reading 🤗&lt;/p&gt;

</description>
      <category>database</category>
      <category>computerscience</category>
      <category>beginners</category>
      <category>sql</category>
    </item>
    <item>
      <title>Introduction to DBMS: Why and How We Store Data</title>
      <dc:creator>Aayush Singh</dc:creator>
      <pubDate>Mon, 30 Jun 2025 17:13:57 +0000</pubDate>
      <link>https://dev.to/singhaayush/introduction-to-dbms-why-and-how-we-store-data-mk5</link>
      <guid>https://dev.to/singhaayush/introduction-to-dbms-why-and-how-we-store-data-mk5</guid>
      <description>&lt;p&gt;&lt;strong&gt;DBMS&lt;/strong&gt;, or &lt;strong&gt;Database Management System&lt;/strong&gt;, is a fundamental concept in the world of data handling and software systems.&lt;br&gt;
Before we dive deep into this topic, let’s first understand some basic terminologies that will give you a clear picture of what DBMS is and why it matters.&lt;/p&gt;




&lt;h2&gt;
  
  
  Basic Terminologies
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data&lt;/strong&gt; — Raw facts and figures without any context, such as numbers, text, or symbols stored in a database.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Information&lt;/strong&gt; — Processed and organized data that is meaningful and useful for decision-making.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Database&lt;/strong&gt; — A structured collection of data that enables easy access, management, and updates. It is generally stored and accessed electronically from a computer system.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Database Management System (DBMS)&lt;/strong&gt; — Software that facilitates efficient storage, retrieval, and management of data within a database.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Why Use a DBMS?
&lt;/h2&gt;

&lt;p&gt;You might be wondering: &lt;strong&gt;Why DBMS? Why not store data in a file system or even in an Excel sheet?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The reason lies in the powerful features that a DBMS offers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It supports data &lt;strong&gt;querying&lt;/strong&gt;, &lt;strong&gt;reporting&lt;/strong&gt;, and &lt;strong&gt;analytics&lt;/strong&gt; to enable informed decision-making.&lt;/li&gt;
&lt;li&gt;It provides &lt;strong&gt;structured querying capabilities&lt;/strong&gt;, allowing for &lt;strong&gt;faster and more efficient data access&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;It ensures &lt;strong&gt;data integrity, consistency&lt;/strong&gt;, and &lt;strong&gt;security&lt;/strong&gt;, which are hard to manage in a plain file system.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Three Views of a Database in DBMS&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. &lt;strong&gt;Internal View (Physical Level)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This is the lowest level of abstraction that defines how the data is physically stored in memory (files, indexes, etc.). This level is managed by the DBMS and is invisible to users and even most developers.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. &lt;strong&gt;Conceptual View (Logical Level)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This level shows the logical structure of the entire database — what data is stored and how different data items relate to each other. This level is maintained by database administrators and is common for all users. It hides the internal view but reveals how data is logically organized.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. &lt;strong&gt;External View (View Level)&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This is the highest level of abstraction, showing only a part of the database that a specific user or application needs. Different users can have different external views, depending on their roles or permissions.&lt;/p&gt;

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




&lt;h2&gt;
  
  
  Data Independence
&lt;/h2&gt;

&lt;p&gt;Data Independence is the ability to change the structure of a database at one level without affecting the structure at the next higher level. It ensures that changes in how data is stored (physical level) or how it's organized (logical level) do not force changes in the applications using that data.&lt;br&gt;
There are two types of data independence:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Logical Data Independence – changing the logical schema without affecting external views.&lt;/li&gt;
&lt;li&gt;Physical Data Independence – changing physical storage without affecting the logical schema.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Instance and Schemas
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Instance - An instance is the actual content or data stored in the database at a particular moment in time. An instance changes frequently as data is inserted, updated, or deleted.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Schemas - A schema is the overall design or structure of the database — it defines how the data is organized, including tables, fields, relationships, and constraints. The schema is defined once when the database is created and usually does not change frequently.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Types of Data Bases
&lt;/h2&gt;

&lt;p&gt;Databases come in different types based on how data is stored, organized, and accessed. Here are some of the most common types:&lt;/p&gt;

&lt;p&gt;1.&lt;strong&gt;Relational Database&lt;/strong&gt; - Stores data in tables (rows and columns) with relationships between them using keys.&lt;/p&gt;

&lt;p&gt;Example: MySQL, PostgreSQL, Oracle.&lt;/p&gt;

&lt;p&gt;Use Case: Banking systems, inventory management, e-commerce websites.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Analogy: Like an Excel spreadsheet where rows are records and columns are fields.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;2.&lt;strong&gt;Hierarchical Database&lt;/strong&gt; - Stores data in a tree-like structure with parent-child relationships.&lt;/p&gt;

&lt;p&gt;Example: IBM Information Management System (IMS).&lt;/p&gt;

&lt;p&gt;Use Case: File systems, legacy applications.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Analogy: Like folders inside folders on your computer.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;3.&lt;strong&gt;Network Database&lt;/strong&gt; - Similar to hierarchical but allows many-to-many relationships between records using graph-like structure.&lt;/p&gt;

&lt;p&gt;Example: Integrated Data Store (IDS), CODASYL.&lt;/p&gt;

&lt;p&gt;Use Case: Telecom and complex network applications.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Analogy: Like a web where one page can link to many others and vice versa.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;4.&lt;strong&gt;Object-Oriented Database&lt;/strong&gt; - Stores data in the form of objects, like in object-oriented programming.&lt;/p&gt;

&lt;p&gt;Example: db4o, ObjectDB.&lt;/p&gt;

&lt;p&gt;Use Case: Applications using C++, Java, Python with complex data types.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Analogy: Like storing not just the data, but also the behavior (methods) of the object.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;5.&lt;strong&gt;Document-Oriented (NoSQL) Database&lt;/strong&gt; - Stores data as documents (usually JSON or XML), allowing flexible schema.&lt;/p&gt;

&lt;p&gt;Example: MongoDB, CouchDB.&lt;/p&gt;

&lt;p&gt;Use Case: Real-time analytics, content management systems, modern web apps.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Analogy: Like folders of dynamic, self-contained documents.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;6.&lt;strong&gt;Columnar Database&lt;/strong&gt; - Stores data column-wise instead of row-wise for faster analytics.&lt;/p&gt;

&lt;p&gt;Example: Apache Cassandra, HBase.&lt;/p&gt;

&lt;p&gt;Use Case: Big Data analytics, data warehousing.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Like flipping a spreadsheet and focusing on one column at a time for analysis.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;7.&lt;strong&gt;Key-Value Store&lt;/strong&gt; - Stores data as key-value pairs, great for fast lookups.&lt;/p&gt;

&lt;p&gt;Example: Redis, DynamoDB.&lt;/p&gt;

&lt;p&gt;Use Case: Caching, session storage, high-speed real-time systems.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Analogy: Like a dictionary where each word (key) has a definition (value).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Beside them a new and growing class of databases tailored for semantic and AI-driven workloads is evolving which is called as &lt;strong&gt;Vector Databases&lt;/strong&gt;. &lt;strong&gt;Vector Databases Stores and queries high-dimensional embeddings using ANN indexing (e.g., Pinecone, Milvus, Chroma). Especially useful for semantic search, AI retrieval (RAG), image/text similarity .&lt;/strong&gt; While they stand alongside relational, NoSQL, and graph databases, their ability to combine with other models places them firmly in the evolving landscape of multi-model/hybrid databases.&lt;/p&gt;




&lt;h2&gt;
  
  
  ER Diagram
&lt;/h2&gt;

&lt;p&gt;An ER (Entity-Relationship) Diagram is a visual representation of the data and the relationships between different entities in a database. It helps in designing a database by showing entities (like tables), their attributes (fields), and how they are connected.&lt;/p&gt;

&lt;h3&gt;
  
  
  Entity
&lt;/h3&gt;

&lt;p&gt;An Entity is a real-world object or concept that can be distinctly identified and has data stored about it in a database. Each entity has attributes (properties) that describe it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Example: In a school database, entities can be Student, Teacher, or Course.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There are two types of entity &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Tangible- Entities which physically exist in real world. E.g. - Car, Pen, locker.&lt;/li&gt;
&lt;li&gt;Intangible- Entities which exist logically. E.g. – Account, video.&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;In ER diagram we cannot represent an entity, as entity is an instant not schema, and ER diagram is designed to understand schema. In a relational model entity is represented by a row or a tuple or a record in a table.&lt;/p&gt;
&lt;/blockquote&gt;

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

&lt;h3&gt;
  
  
  Entity set
&lt;/h3&gt;

&lt;p&gt;An entity set is a collection of similar types of entities (i.e., multiple entities of the same kind stored together in a table). An entity set is the entire table — all the rows (entities) that represent the same type of thing. Just like a "Student" table is an entity set made up of many "Student" entities.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Based on the above table&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"John" is one entity.&lt;/li&gt;
&lt;li&gt;"Marry" is another entity.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Together, they belong to the Customer entity set.&lt;/p&gt;

&lt;h3&gt;
  
  
  Attributes
&lt;/h3&gt;

&lt;p&gt;An attribute is a property or characteristic of an entity. In databases, attributes are represented as columns in a table. If an entity is a row, then each attribute is a column that stores information about that row.&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Here are the attributes of the above customer entity set&lt;/em&gt; &lt;strong&gt;CustomerID&lt;/strong&gt;, &lt;strong&gt;FirstName&lt;/strong&gt;, &lt;strong&gt;LastName&lt;/strong&gt;, &lt;strong&gt;BirthDate&lt;/strong&gt;. Each column is an attribute, and it holds a specific piece of information about every customer.&lt;/li&gt;
&lt;li&gt;In an ER diagram attributes are represented by ellipse or oval connected to rectangle.&lt;/li&gt;
&lt;li&gt;While in a relational model they are represented by independent column. e.g. EmpNo, EmpName, Salary&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

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

&lt;h3&gt;
  
  
  Types of Attributes
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Simple Attribute&lt;/strong&gt; - Cannot be divided further. eg: Age, Email&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Think of it as: One solid value.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Composite Attribute&lt;/strong&gt; - Can be divided into smaller parts. eg: Name → can be split into First Name and Last Name&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Think of it like: Full Name = First Name + Last Name&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Derived Attribute - Can be calculated from other attributes. eg: Age can be derived from Date of Birth&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Think of it like: Not stored directly, just calculated when needed.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Single-valued Attribute - Holds only one value per entity. eg: Student_ID, Date of Birth&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Just a regular field, not a list&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Multi-valued Attribute - Can have multiple values for one entity. eg: Phone Numbers (a student can have more than one)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Key Attribute - Uniquely identifies an entity (usually the Primary Key) eg: Student_ID&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It's the ID card of each row&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Relationship / Association
&lt;/h3&gt;

&lt;p&gt;A relationship in DBMS is an association between two or more entities. It shows how entities are connected or related to each other in the real world. &lt;br&gt;
If an entity is a table (like Student or Course), then a relationship shows how those tables are connected — for example, which student is studying which course.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Entities: Student, Course&lt;/li&gt;
&lt;li&gt;Relationship: Study&lt;/li&gt;
&lt;/ul&gt;

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

&lt;blockquote&gt;
&lt;p&gt;📊 In an ER diagram, relationships are shown as diamonds, with lines connecting the related entities. While in relational model &lt;br&gt;
sometimes through foreign key and other time by a separate table.&lt;/p&gt;
&lt;/blockquote&gt;

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




&lt;h3&gt;
  
  
  Component of Relationships.
&lt;/h3&gt;

&lt;p&gt;In an ER (Entity-Relationship) diagram, a relationship connects two or more entities. But every relationship is more than just a connection — it has important components that describe how it works. Let’s understand the three main components of a relationship:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Name&lt;/strong&gt; - The name simply identifies what the relationship means or represents in real life. For example: In a school database, the relationship between Student and Course can be named "Enrolled" — indicating which student is enrolled in which course. A meaningful name makes your ER diagram easy to read and understand. It's like labeling arrows in a flowchart. Every relation must have a unique name. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Degree&lt;/strong&gt; – It can be defined as the number of entity sets (relations/tables) associated (participating) in the relationship set. Most of the relationship sets in a database system are binary. Occasionally, however, relationship sets involve more than two entity sets. In short, the degree tells us how many entities are connected and helps in choosing the right design structure. It has three types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Unary Relationship&lt;/strong&gt; – One single entity set participates in a relationship, meaning two entities of the same entity set are related to each other.
Example: A member in a team may be the supervisor of another member in the same team.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Binary Relationship&lt;/strong&gt; – Two entity sets participate in a relationship. It is the most common type of relationship.
Example: Student enrolled in Course.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ternary Relationship&lt;/strong&gt; – Three different entity sets participate in a single relationship. It is used when a relationship logically requires all three entities.
Example: A Doctor prescribes a Medicine to a Patient.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Structural constraints (Cardinalities Ratios, Participation)&lt;/strong&gt; – These constraints define the rules of how entities participate in relationships. They help in understanding the nature of the relationship between entities and are mainly of two types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cardinality Ratios&lt;/strong&gt; – This defines the number of instances of one entity that can be associated with instances of another entity. It determines the type of relationship:

&lt;ul&gt;
&lt;li&gt;One-to-One (1:1) – One instance of an entity A is related to at most one instance of entity B, and vice versa.
Example: One person has one passport.&lt;/li&gt;
&lt;li&gt;One-to-Many (1:N) – One instance of entity A is related to multiple instances of entity B, but one instance of B is related to only one instance of A.
Example: One teacher teaches many students.&lt;/li&gt;
&lt;li&gt;Many-to-One (N:1) – Many instances of entity A are related to one instance of entity B.
Example: Many employees work in one department.&lt;/li&gt;
&lt;li&gt;Many-to-Many (M:N) – Many instances of entity A can be related to many instances of entity B.
Example: Students enroll in many courses and courses have many students.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Participation&lt;/strong&gt; – It defines whether all entities in an entity set must participate in a relationship or not. It is of two types:

&lt;ul&gt;
&lt;li&gt;Total Participation – Every instance of the entity set must participate in the relationship.
Example: Every employee must belong to at least one department.&lt;/li&gt;
&lt;li&gt;Partial Participation – Some instances of the entity set may not participate in the relationship.
Example: Some students may not enroll in any course.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;/li&gt;

&lt;/ul&gt;




&lt;h4&gt;
  
  
  Advantages of ER Diagrams
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Simple and Clear Visualization&lt;/strong&gt; – ER diagrams provide a graphical representation of entities, relationships, and attributes, which makes database design easier to understand.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Helps in Logical Database Design&lt;/strong&gt; – They are excellent tools for planning and organizing database structures before implementation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Improves Communication&lt;/strong&gt; – ER diagrams help developers, database designers, and stakeholders communicate and collaborate effectively.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Error Detection&lt;/strong&gt; – It becomes easier to identify inconsistencies, missing entities, or unnecessary relationships at an early stage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Documentation Purpose&lt;/strong&gt; – ER diagrams serve as useful documentation for maintaining and updating the database over time.&lt;/li&gt;
&lt;/ul&gt;




&lt;h4&gt;
  
  
  Disadvantages of ER Diagrams
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Not Suitable for Complex Logic&lt;/strong&gt; – They are not ideal for representing complex constraints or business logic like triggers or stored procedures.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scalability Issues&lt;/strong&gt; – For very large systems, ER diagrams can become overly complex and hard to manage or read.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No Standard Symbols&lt;/strong&gt; – Different organizations or tools may use different notations, which can create confusion.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lack of Support for Some Data Models&lt;/strong&gt; – ER diagrams are primarily used for relational databases and may not represent NoSQL or object-oriented models effectively.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Loss of information content&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  What’s Next?
&lt;/h3&gt;

&lt;p&gt;Now that we've covered the basics in this blog, get ready to dive deeper!&lt;br&gt;
In the next blog, we’ll explore &lt;strong&gt;Relational Database Management Systems&lt;/strong&gt; (RDBMS) and break down some complex concepts in a simple and beginner-friendly way.&lt;/p&gt;

&lt;p&gt;To stay updated with the series, follow me on &lt;a href="https://x.com/saayush615" rel="noopener noreferrer"&gt;X&lt;/a&gt; and &lt;a href="https://www.linkedin.com/in/singhaayush079/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Thank you for reading! &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>database</category>
      <category>beginners</category>
      <category>sql</category>
    </item>
    <item>
      <title>Let’s Talk to the Internet: Understanding the Application Layer</title>
      <dc:creator>Aayush Singh</dc:creator>
      <pubDate>Sun, 13 Apr 2025 10:10:59 +0000</pubDate>
      <link>https://dev.to/singhaayush/lets-talk-to-the-internet-understanding-the-application-layer-12fe</link>
      <guid>https://dev.to/singhaayush/lets-talk-to-the-internet-understanding-the-application-layer-12fe</guid>
      <description>&lt;p&gt;Welcome back to our final blog in the Computer Networking for Beginners series! So far, we’ve taken a journey from the &lt;strong&gt;Physical Layer&lt;/strong&gt; all the way up to the &lt;strong&gt;Transport Layer&lt;/strong&gt;. Now, it's time to explore the top-most layer that interacts directly with us—the users.&lt;/p&gt;

&lt;p&gt;Let’s dive into the &lt;strong&gt;Application Layer&lt;/strong&gt; — the layer where everything we do online actually begins and ends.&lt;/p&gt;




&lt;h2&gt;
  
  
  What is the Application Layer?
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;Application Layer&lt;/strong&gt; is the 7th and final layer of the OSI model. It’s the part of the network that users interact with directly. Whenever you browse a website, send an email, or upload a photo, you’re using the Application Layer.&lt;/p&gt;

&lt;p&gt;Think of it like the cashier counter at a supermarket—after all the backend operations (stocking, billing system, barcodes, etc.), it’s where you interact directly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;- Position in OSI Model:&lt;/strong&gt; Top layer&lt;br&gt;&lt;br&gt;
&lt;strong&gt;- Position in TCP/IP Model:&lt;/strong&gt; Merged with Presentation and Session Layers&lt;/p&gt;


&lt;h2&gt;
  
  
  Role of the Application Layer
&lt;/h2&gt;

&lt;p&gt;The Application Layer provides &lt;strong&gt;services directly to user applications&lt;/strong&gt;. It allows software like browsers, email clients, and messaging apps to communicate over the network.&lt;/p&gt;

&lt;p&gt;It &lt;strong&gt;does not&lt;/strong&gt; define the actual application (like Chrome or WhatsApp), but rather the &lt;strong&gt;protocols&lt;/strong&gt; and services that applications use to communicate.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Responsibilities:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Identify communication partners&lt;/li&gt;
&lt;li&gt;Determine resource availability&lt;/li&gt;
&lt;li&gt;Synchronize communication&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  Popular Application Layer Protocols
&lt;/h2&gt;

&lt;p&gt;Here are some common protocols you’ve probably used without even realizing it:&lt;/p&gt;
&lt;h3&gt;
  
  
  HTTP / HTTPS
&lt;/h3&gt;

&lt;p&gt;Used for web browsing.&lt;br&gt;&lt;br&gt;
Example: When you visit a website, your browser uses &lt;strong&gt;HTTP/HTTPS&lt;/strong&gt; to fetch data.&lt;/p&gt;
&lt;h3&gt;
  
  
  FTP / SFTP
&lt;/h3&gt;

&lt;p&gt;Used to transfer files over the internet.&lt;br&gt;&lt;br&gt;
Example: Uploading or downloading files to/from a server.&lt;/p&gt;
&lt;h3&gt;
  
  
  SMTP, POP3, IMAP
&lt;/h3&gt;

&lt;p&gt;Used for sending and receiving emails.&lt;br&gt;&lt;br&gt;
Example: Gmail uses these to send and sync your emails.&lt;/p&gt;
&lt;h3&gt;
  
  
  DNS
&lt;/h3&gt;

&lt;p&gt;Translates domain names to IP addresses.&lt;br&gt;&lt;br&gt;
Example: Typing &lt;code&gt;www.google.com&lt;/code&gt; gets converted to an IP behind the scenes.&lt;/p&gt;
&lt;h3&gt;
  
  
  DHCP
&lt;/h3&gt;

&lt;p&gt;Automatically assigns IP addresses to devices on a network.&lt;/p&gt;


&lt;h2&gt;
  
  
  🌐 The World Wide Web (WWW)
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;World Wide Web (WWW)&lt;/strong&gt; is one of the most common ways users interact with the Application Layer. It’s the system of interlinked documents and resources that we access using the internet — through web browsers, websites, and online services.&lt;/p&gt;

&lt;p&gt;Let’s explore the key components that make the web work:&lt;br&gt;&lt;br&gt;
&lt;strong&gt;HTTP, HTTPS, URL, Browser, DNS, Client-Server Model, and Cookies.&lt;/strong&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  HTTP (HyperText Transfer Protocol)
&lt;/h3&gt;

&lt;p&gt;HTTP is the protocol used for transferring web pages over the internet. When you visit a website, your browser sends an &lt;strong&gt;HTTP request&lt;/strong&gt; to the server, and the server sends back an &lt;strong&gt;HTTP response&lt;/strong&gt; with the requested page.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Example:
Typing &lt;code&gt;http://example.com&lt;/code&gt; tells the browser to use HTTP to fetch the page from the server.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  HTTPS (HTTP Secure)
&lt;/h3&gt;

&lt;p&gt;HTTPS is a secure version of HTTP that uses encryption (SSL/TLS) to protect data during transmission. It ensures that your data (like login info or payment details) cannot be read or tampered with by attackers.&lt;/p&gt;

&lt;p&gt;🔒 Sites with HTTPS show a lock symbol in the browser — meaning your connection is secure.&lt;/p&gt;
&lt;h3&gt;
  
  
  URL (Uniform Resource Locator)
&lt;/h3&gt;

&lt;p&gt;A URL is the web address you type in the browser. It tells the browser what protocol to use, which server to contact, and what resource to fetch.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example Breakdown:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://www.example.com/about
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;https&lt;/code&gt; → Protocol
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;www.example.com&lt;/code&gt; → Domain name
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/about&lt;/code&gt; → Resource path&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Browser
&lt;/h3&gt;

&lt;p&gt;A browser is a client application (like Chrome, Firefox, or Safari) that lets users access and interact with websites. It uses HTTP/HTTPS to communicate with servers and displays the content (HTML, CSS, JS) to the user.&lt;/p&gt;

&lt;p&gt;Browsers also manage cookies, cache, and security settings.&lt;/p&gt;

&lt;h3&gt;
  
  
  DNS (Domain Name System)
&lt;/h3&gt;

&lt;p&gt;DNS is like the &lt;strong&gt;phonebook of the internet&lt;/strong&gt;. It translates domain names like &lt;code&gt;www.google.com&lt;/code&gt; into IP addresses like &lt;code&gt;142.250.182.4&lt;/code&gt; — which are needed to locate servers.&lt;/p&gt;

&lt;p&gt;Without DNS, users would have to remember IP addresses instead of easy-to-remember domain names.&lt;/p&gt;

&lt;h3&gt;
  
  
  Client
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;client&lt;/strong&gt; is the device or software (like a browser) that initiates a request. In the web world, your browser acts as the client when you visit a website.&lt;/p&gt;

&lt;p&gt;Clients send requests and wait for responses from servers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Server
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;server&lt;/strong&gt; is a powerful computer that stores website data. It receives requests from clients and sends back responses — like web pages, images, or data.&lt;/p&gt;

&lt;p&gt;Example: When you visit &lt;code&gt;www.netflix.com&lt;/code&gt;, your browser (client) talks to a Netflix server to fetch videos or show your dashboard.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cookies
&lt;/h3&gt;

&lt;p&gt;Cookies are small text files stored by the browser on your device. They help websites remember you and your preferences.&lt;/p&gt;

&lt;p&gt;Examples of cookie usage:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Keeping you logged in&lt;/li&gt;
&lt;li&gt;Saving language or theme preferences&lt;/li&gt;
&lt;li&gt;Tracking site usage (analytics)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Cookies can be &lt;strong&gt;secure, HttpOnly, and encrypted&lt;/strong&gt; to enhance privacy.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cache
&lt;/h3&gt;

&lt;p&gt;Cache is a temporary storage used by browsers to store copies of previously accessed data (like images, scripts, or entire web pages) so that future requests for that data can be served faster.&lt;/p&gt;

&lt;p&gt;Think of it like a shortcut — instead of re-downloading the same logo or webpage each time, your browser saves a copy and loads it locally.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;br&gt;
When you visit a news site, the logo and stylesheets are cached by your browser. Next time you visit, the browser doesn’t ask the server again — it loads them directly from your local cache.&lt;/p&gt;

&lt;p&gt;Fun Fact:&lt;br&gt;
Sometimes, outdated cache can cause a page to not show the latest changes. That’s why we hit Ctrl + Shift + R (Hard Refresh) to force the browser to reload everything fresh.&lt;/p&gt;

&lt;p&gt;This entire system — involving &lt;strong&gt;clients, servers, DNS, HTTP/HTTPS, URLs, and browsers&lt;/strong&gt; — works together to bring websites and web apps to life. All of these live at the &lt;strong&gt;Application Layer&lt;/strong&gt;, making the &lt;strong&gt;WWW&lt;/strong&gt; a real-world application of networking concepts.&lt;/p&gt;


&lt;h2&gt;
  
  
  Real-World Analogy: Visiting a Website
&lt;/h2&gt;

&lt;p&gt;Let’s say you open your browser and go to &lt;code&gt;www.example.com&lt;/code&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Your browser uses &lt;strong&gt;DNS&lt;/strong&gt; to find the IP address of the website.&lt;/li&gt;
&lt;li&gt;It then uses &lt;strong&gt;HTTP or HTTPS&lt;/strong&gt; to send a request to that IP.&lt;/li&gt;
&lt;li&gt;The website responds, and the page is displayed.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;All this magic happens through protocols in the Application Layer!&lt;/p&gt;


&lt;h2&gt;
  
  
  Application Layer in OSI vs TCP/IP Model
&lt;/h2&gt;

&lt;p&gt;In the &lt;strong&gt;OSI Model&lt;/strong&gt;, the Application Layer is separate from the &lt;strong&gt;Presentation&lt;/strong&gt; and &lt;strong&gt;Session&lt;/strong&gt; layers.&lt;/p&gt;

&lt;p&gt;But in the &lt;strong&gt;TCP/IP Model&lt;/strong&gt;, these three are combined into one &lt;strong&gt;Application Layer&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;So:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;OSI: Application + Presentation + Session  
TCP/IP: Application Layer (combined)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Application Layer Security Basics
&lt;/h2&gt;

&lt;p&gt;The Application Layer is also where &lt;strong&gt;security matters most&lt;/strong&gt; to users. Here are some security concepts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;HTTPS:&lt;/strong&gt; Secures communication between browser and website&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Authentication:&lt;/strong&gt; Verifying users before granting access&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Encryption:&lt;/strong&gt; Protects data from eavesdropping&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These ensure safe communication over the internet.&lt;/p&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;Application Layer&lt;/strong&gt; is like the &lt;strong&gt;front door to the internet&lt;/strong&gt; — it’s what users actually experience. Whether you're browsing websites, streaming videos, sending emails, or chatting online, it all happens here.&lt;/p&gt;

&lt;p&gt;In this blog, we explored the real-world technologies like &lt;strong&gt;HTTP, HTTPS, DNS, URLs, browsers, cookies, and cache&lt;/strong&gt; that bring the &lt;strong&gt;World Wide Web&lt;/strong&gt; to life. Understanding this layer gives you a new appreciation for everything you do online.&lt;/p&gt;

&lt;p&gt;🎉 With this, we wrap up our &lt;strong&gt;6-part beginner-friendly blog series on Computer Networking&lt;/strong&gt;.  &lt;/p&gt;

&lt;p&gt;A huge thank you to &lt;strong&gt;everyone who held on through the series&lt;/strong&gt; — from the basics and physical layer all the way to the application layer. I hope it made networking simpler and more fun for you!&lt;/p&gt;

&lt;p&gt;I'll continue posting new blogs in the coming days — on different tech topics to help you learn and grow.  &lt;/p&gt;

&lt;p&gt;If you found this blog helpful, &lt;strong&gt;share it with your friends&lt;/strong&gt;, leave a comment below, or follow me here:&lt;br&gt;&lt;br&gt;
👉 &lt;a href="https://www.linkedin.com/in/singhaayush079/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;br&gt;&lt;br&gt;
👉 &lt;a href="https://x.com/saayush615" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Stay curious, keep learning, and explore the web with confidence! 🌐🚀&lt;/p&gt;

</description>
      <category>networking</category>
      <category>network</category>
      <category>computerscience</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How the Transport Layer Bridges the Gap Between Applications and Networks</title>
      <dc:creator>Aayush Singh</dc:creator>
      <pubDate>Sun, 30 Mar 2025 11:13:04 +0000</pubDate>
      <link>https://dev.to/singhaayush/how-the-transport-layer-bridges-the-gap-between-applications-and-networks-aan</link>
      <guid>https://dev.to/singhaayush/how-the-transport-layer-bridges-the-gap-between-applications-and-networks-aan</guid>
      <description>&lt;p&gt;&lt;strong&gt;Welcome back, tech explorers!&lt;/strong&gt; 🚀  &lt;/p&gt;

&lt;p&gt;I’m glad to have you here as we continue our exciting journey through the world of computer networking. If you haven’t checked out the previous blogs in this series—where we explored the Physical, Data Link, and Network layers—I highly recommend giving them a read. They’ll help you build a solid foundation before diving into today’s topic.  &lt;/p&gt;

&lt;p&gt;Now, let’s move one step higher in the networking hierarchy and uncover the magic of the &lt;strong&gt;Transport Layer&lt;/strong&gt;—the unsung hero ensuring smooth and reliable communication between devices. &lt;strong&gt;Let’s get started!&lt;/strong&gt; 🎯&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Imagine you’re sending a package to a friend in another city. You carefully pack it, choose between a reliable courier service (which guarantees delivery with tracking) or a faster, no-tracking option, and label it with the correct address. The transport layer in networking works in a similar way—it ensures that data sent from one device reaches the right application on another device, either reliably or quickly, depending on the need.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Functions of the Transport Layer
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Segmentation &amp;amp; Reassembly (Breaking down data into smaller packets and reassembling them).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Flow Control (Preventing data overload using mechanisms like sliding window).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Error Control (Ensuring data integrity through acknowledgments and retransmissions).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Multiplexing &amp;amp; Demultiplexing (Managing multiple communication sessions).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  How Does It Work?
&lt;/h3&gt;

&lt;p&gt;When an application sends data, the transport layer divides it into smaller units called &lt;u&gt;segments&lt;/u&gt; (in TCP) or &lt;u&gt;datagrams&lt;/u&gt; (in UDP). Each segment is labeled with a source port number and a destination port number, so the receiver knows which application should process the data.&lt;/p&gt;

&lt;h3&gt;
  
  
  Protocols of the Transport Layer
&lt;/h3&gt;

&lt;p&gt;The two main protocols in this layer are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;TCP (Transmission Control Protocol)&lt;/strong&gt; – A reliable, connection-oriented protocol that guarantees data delivery with error checking, acknowledgments, and retransmissions if needed. Think of it like a courier service with tracking.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;UDP (User Datagram Protocol)&lt;/strong&gt; – A fast, connectionless protocol that sends data without guarantees. It’s useful for time-sensitive applications like gaming and streaming. Think of it like sending a postcard—quick but no guarantee it’ll arrive safely.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Ports &amp;amp; Port Numbers
&lt;/h3&gt;

&lt;p&gt;Every computer has multiple applications running at the same time—so how does the transport layer know where to send the data? That’s where port numbers come in. A port is like a specific door in a building that directs incoming data to the right application. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Port 80 – Used for HTTP (web browsing)&lt;/li&gt;
&lt;li&gt;Port 443 – Used for HTTPS (secure web browsing)&lt;/li&gt;
&lt;li&gt;Port 25 – Used for email (SMTP)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We are done with introduction part, I think i described everything in concise format now let's discuss everything in detail.&lt;/p&gt;




&lt;h2&gt;
  
  
  Transport layer protocol
&lt;/h2&gt;

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

&lt;h3&gt;
  
  
  &lt;strong&gt;Transmission Control Protocol (TCP)&lt;/strong&gt; – Reliable &amp;amp; Connection-Oriented
&lt;/h3&gt;

&lt;p&gt;TCP is like a well-organized courier service that guarantees your package (data) will reach its destination correctly and in order. It establishes a connection between sender and receiver before transmitting data, making sure that the communication is reliable and accurate.&lt;/p&gt;

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

&lt;h3&gt;
  
  
  Key Features of TCP:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Connection-Oriented – A connection is established before sending data (via a process called the three-way handshake).&lt;/li&gt;
&lt;li&gt;Reliable Delivery – Ensures that all data reaches the destination correctly. If a packet is lost, TCP retransmits it.&lt;/li&gt;
&lt;li&gt;Error Checking – Uses checksums to detect errors in transmission.&lt;/li&gt;
&lt;li&gt;Ordered Data Transfer – TCP numbers each packet so they arrive in the correct order.&lt;/li&gt;
&lt;li&gt;Flow Control – Prevents overwhelming the receiver by adjusting the speed of data transmission.&lt;/li&gt;
&lt;li&gt;Congestion Control – Regulates data flow to avoid network congestion.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  How TCP Works?
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1 Connection Establishment (Three-Way Handshake)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The sender sends a SYN request to initiate communication.&lt;/p&gt;

&lt;p&gt;The receiver responds with SYN-ACK to acknowledge the request.&lt;/p&gt;

&lt;p&gt;The sender replies with ACK, and the connection is established.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;2 Data Transmission&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;TCP segments are sent in sequence, and each segment is acknowledged by the receiver.&lt;/p&gt;

&lt;p&gt;If a segment is lost, TCP retransmits it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3 Connection Termination&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When communication is done, the sender and receiver exchange FIN (Finish) and ACK packets to close the connection.&lt;/p&gt;

&lt;h3&gt;
  
  
  TCP Header
&lt;/h3&gt;

&lt;p&gt;When data is transmitted using TCP, it is broken into segments, and each segment contains a TCP header. This header provides important control information that ensures reliable and ordered delivery of data.&lt;/p&gt;

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

&lt;p&gt;The TCP header is typically 20 to 60 bytes long and contains the following fields:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Source Port &amp;amp; Destination Port&lt;/strong&gt; – These ensure the data is sent to the correct application. For example, a web server may use port 80 (HTTP), while an email server may use port 25 (SMTP).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Sequence Number&lt;/strong&gt; – TCP assigns &lt;u&gt;each byte of data&lt;/u&gt; a sequence number, ensuring that data is reassembled correctly at the receiver’s end.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Acknowledgment Number&lt;/strong&gt; – This field confirms receipt of data. If a sender sends data with sequence number 1000, the receiver will reply with acknowledgment 1001, meaning it expects the next byte to start from 1001.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Flags (Control Bits)&lt;/strong&gt; – Used to manage the connection:&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;SYN – Used in connection establishment (Three-Way Handshake).&lt;/p&gt;

&lt;p&gt;ACK – Acknowledges received data.&lt;/p&gt;

&lt;p&gt;FIN – Used to terminate a connection.&lt;/p&gt;

&lt;p&gt;RST – Resets the connection.&lt;/p&gt;

&lt;p&gt;URG – Indicates urgent data.&lt;/p&gt;

&lt;p&gt;PSH – Instructs to send data immediately.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Window Size&lt;/strong&gt; – Controls flow control by specifying how much data can be sent before requiring an acknowledgment.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Checksum&lt;/strong&gt; – Used for error detection to ensure data integrity.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Urgent Pointer&lt;/strong&gt; – If the URG flag is set, this field tells the receiver which part of the data is urgent.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Use Cases of TCP:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Web Browsing (HTTP/HTTPS) – Ensures webpages load completely and correctly.&lt;/li&gt;
&lt;li&gt;Email (SMTP, IMAP, POP3) – Guarantees reliable delivery of emails.&lt;/li&gt;
&lt;li&gt;File Transfer (FTP) – Ensures error-free transmission of files.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;User Datagram Protocol (UDP)&lt;/strong&gt; – Fast &amp;amp; Connectionless
&lt;/h3&gt;

&lt;p&gt;UDP is like sending a regular letter without tracking—it delivers data quickly but does not guarantee that all packets will arrive. It does not establish a connection before sending data, making it much faster than TCP.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Features of UDP:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Connectionless Communication – No need to establish a connection before sending data.&lt;/li&gt;
&lt;li&gt;Fast &amp;amp; Lightweight – Less overhead compared to TCP.&lt;/li&gt;
&lt;li&gt;No Error Checking or Retransmission – Lost packets are not resent.&lt;/li&gt;
&lt;li&gt;Unordered Data Transfer – Packets may arrive out of order.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  How UDP Works?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The sender transmits data packets (datagrams) to the receiver.&lt;/li&gt;
&lt;li&gt;The receiver gets them, but there are no guarantees of order or reliability.&lt;/li&gt;
&lt;li&gt;If a packet is lost, UDP does not request retransmission.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  UDP Header
&lt;/h3&gt;

&lt;p&gt;Unlike TCP, UDP (User Datagram Protocol) does not establish a connection before sending data, making it faster but less reliable. The UDP header is fixed at 8 bytes, making it much smaller than the TCP header.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Source Port &amp;amp; Destination Port&lt;/strong&gt; – Like TCP, these identify the sender and receiver’s applications. For example, a video streaming service might use port 1935 (RTMP), and DNS uses port 53.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Length&lt;/strong&gt; – Specifies the total length of the UDP packet (header + data). The minimum size is 8 bytes (header only), but it can be larger if data is included.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Checksum&lt;/strong&gt; – Provides error detection. Unlike TCP, UDP does not request retransmission if errors are found, meaning the data is simply discarded.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Use Cases of UDP:
&lt;/h3&gt;

&lt;p&gt;🔹 Online Gaming – Fast response time is more important than 100% accuracy.&lt;br&gt;
🔹 Live Streaming (YouTube, Netflix, Zoom) – Minor packet loss doesn’t ruin the experience.&lt;br&gt;
🔹 DNS (Domain Name System) – Quick lookups of website addresses need speed, not reliability.&lt;/p&gt;




&lt;h2&gt;
  
  
  Ports &amp;amp; Sockets
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is a Port?
&lt;/h3&gt;

&lt;p&gt;A port is a logical communication endpoint used by networking protocols to identify specific services running on a device. Just like a house has multiple rooms, a computer has multiple ports to handle different types of network traffic.&lt;/p&gt;

&lt;p&gt;Each port is assigned a port number, which is a 16-bit integer (ranging from 0 to 65535). The combination of an IP address and a port number allows a computer to distinguish between different network connections.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Types of Port Numbers&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
    &lt;thead&gt;
        &lt;tr&gt;
            &lt;th&gt;Port Range&lt;/th&gt;
            &lt;th&gt;Name&lt;/th&gt;
            &lt;th&gt;Description&lt;/th&gt;
        &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;0 – 1023&lt;/td&gt;
            &lt;td&gt;Well-Known Ports&lt;/td&gt;
            &lt;td&gt;Reserved for common services like HTTP (80), HTTPS (443), FTP (21), and SMTP (25).&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;1024 – 49151&lt;/td&gt;
            &lt;td&gt;Registered Ports&lt;/td&gt;
            &lt;td&gt;Used by specific applications like MySQL (3306) and Docker (2375).&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;49152 – 65535&lt;/td&gt;
            &lt;td&gt;Dynamic / Private Ports&lt;/td&gt;
            &lt;td&gt;Assigned dynamically to temporary connections (e.g., video calls, online gaming).&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Examples of Common Port Numbers:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Service&lt;/th&gt;
      &lt;th&gt;Port Number&lt;/th&gt;
      &lt;th&gt;Protocol&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;HTTP (Web Browsing)&lt;/td&gt;
      &lt;td&gt;80&lt;/td&gt;
      &lt;td&gt;TCP&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;HTTPS (Secure Web Browsing)&lt;/td&gt;
      &lt;td&gt;443&lt;/td&gt;
      &lt;td&gt;TCP&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;FTP (File Transfer Protocol)&lt;/td&gt;
      &lt;td&gt;21&lt;/td&gt;
      &lt;td&gt;TCP&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;SSH (Secure Shell)&lt;/td&gt;
      &lt;td&gt;22&lt;/td&gt;
      &lt;td&gt;TCP&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;DNS (Domain Name System)&lt;/td&gt;
      &lt;td&gt;53&lt;/td&gt;
      &lt;td&gt;UDP&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;SMTP (Email Sending)&lt;/td&gt;
      &lt;td&gt;25&lt;/td&gt;
      &lt;td&gt;TCP&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  What is a Socket?
&lt;/h3&gt;

&lt;p&gt;A socket is a combination of an IP address and a port number that uniquely identifies a network connection. It acts as an endpoint for sending and receiving data between two devices.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understanding Socket Address&lt;/strong&gt;&lt;br&gt;
A socket address is written in the format:&lt;br&gt;
 &lt;code&gt;IP Address:Port Number&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;192.168.1.10:8080&lt;/code&gt;
Here,&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;192.168.1.10&lt;/code&gt; → Represents the device’s IP address&lt;/p&gt;

&lt;p&gt;&lt;code&gt;8080&lt;/code&gt; → Represents the port number where a service (e.g., a web server) is running&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Cryptography: Securing Data in the Transport Layer&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In computer networks, &lt;strong&gt;cryptography&lt;/strong&gt; plays a crucial role in ensuring &lt;strong&gt;secure communication&lt;/strong&gt; over the internet. It protects sensitive data from unauthorized access, alteration, or interception.  &lt;/p&gt;

&lt;h3&gt;
  
  
  ** What is Cryptography?**
&lt;/h3&gt;

&lt;p&gt;Cryptography is the practice of securing information through &lt;strong&gt;encryption and decryption&lt;/strong&gt; techniques. It ensures &lt;strong&gt;confidentiality, integrity, and authenticity&lt;/strong&gt; in communication.  &lt;/p&gt;

&lt;h3&gt;
  
  
  ** Key Goals of Cryptography**
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Confidentiality&lt;/strong&gt; – Ensures that only the intended recipient can read the data.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Integrity&lt;/strong&gt; – Ensures that the data is not altered during transmission.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Authentication&lt;/strong&gt; – Verifies the identity of the sender and receiver.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Non-repudiation&lt;/strong&gt; – Prevents denial of sending or receiving data.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ** Cryptography in the Transport Layer**
&lt;/h3&gt;

&lt;p&gt;At the &lt;strong&gt;transport layer&lt;/strong&gt;, cryptography is implemented using &lt;strong&gt;SSL (Secure Sockets Layer) and TLS (Transport Layer Security)&lt;/strong&gt; to encrypt and secure data during transmission. These protocols prevent eavesdropping and ensure a &lt;strong&gt;secure end-to-end connection&lt;/strong&gt; between devices.  &lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In this blog, we explored the &lt;strong&gt;Transport Layer&lt;/strong&gt;, understanding its core concepts:&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Transport Layer Protocols&lt;/strong&gt; – TCP (reliable) vs. UDP (fast).&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;TCP &amp;amp; UDP Headers&lt;/strong&gt; – Structure and role of each field.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Ports &amp;amp; Sockets&lt;/strong&gt; – How applications communicate using port numbers.&lt;br&gt;&lt;br&gt;
✅ &lt;strong&gt;Cryptography&lt;/strong&gt; – How encryption secures data transmission.  &lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Transport Layer is the backbone of reliable data communication&lt;/strong&gt;, ensuring that messages are delivered correctly and securely.  &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;🙏 Thank You for Reading!&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Thank you for reading this blog! I hope it helped you understand the &lt;strong&gt;Transport Layer in depth&lt;/strong&gt;. My final blog on the &lt;strong&gt;Application Layer&lt;/strong&gt; is still pending, so stay tuned! 🚀  &lt;/p&gt;

&lt;p&gt;📢 &lt;strong&gt;Follow me on &lt;a href="https://www.linkedin.com/in/singhaayush079/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; and &lt;a href="https://x.com/saayush615" rel="noopener noreferrer"&gt;X (Twitter)&lt;/a&gt; for more updates!&lt;/strong&gt; 😊&lt;/p&gt;

</description>
      <category>network</category>
      <category>beginners</category>
      <category>computerscience</category>
      <category>networking</category>
    </item>
    <item>
      <title>From IP Addressing to Routing: Everything You Need to Know About the Network Layer</title>
      <dc:creator>Aayush Singh</dc:creator>
      <pubDate>Mon, 24 Mar 2025 08:00:50 +0000</pubDate>
      <link>https://dev.to/singhaayush/from-ip-addressing-to-routing-everything-you-need-to-know-about-the-network-layer-1ck8</link>
      <guid>https://dev.to/singhaayush/from-ip-addressing-to-routing-everything-you-need-to-know-about-the-network-layer-1ck8</guid>
      <description>&lt;p&gt;Welcome back, fellow tech explorers! 🚀 If you've been following my blog series on computer networking, you already know the drill. So far, I’ve covered:&lt;/p&gt;

&lt;p&gt;Computer Networking Basics – Where we cracked the networking code.&lt;/p&gt;

&lt;p&gt;Data Link Layer (Part 1 &amp;amp; Part 2) – Where we learned how devices whisper &lt;br&gt;
 secrets to each other using MAC addresses and frames.&lt;/p&gt;

&lt;p&gt;If you haven’t read them yet, go check them out! Trust me, they’ll make this journey much smoother.&lt;br&gt;
Now, let’s talk about the Network Layer – the part of networking that ensures your data finds its way through the chaotic digital highways. Think of it like Google Maps for the internet.&lt;/p&gt;




&lt;h2&gt;
  
  
  Introduction: The Network Layer
&lt;/h2&gt;

&lt;p&gt;"The Network Layer is the third layer in the OSI (Open Systems Interconnection) model and plays a crucial role in data transmission across networks. It is responsible for routing, forwarding, and addressing data packets to ensure they reach their intended destination." ok done with text book definition now, let's understand it with interesting example:&lt;br&gt;
Imagine ordering a pizza, but the delivery guy has no map. He takes random turns, gets lost, and your pizza never arrives. That's what happens to data packets without proper routing! Luckily, the Network Layer acts like Google Maps, ensuring your data (or pizza) reaches the right destination.&lt;/p&gt;

&lt;p&gt;In this blog, we’ll explore how IP addresses, routers, and routing algorithms work together to make internet magic happen. Let’s dive in! 🚦💻&lt;/p&gt;




&lt;h2&gt;
  
  
  Function of Network layer
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Logical Addressing (IP Addressing)&lt;/strong&gt; – Assigns unique IP addresses to &lt;br&gt;
devices to ensure data reaches the correct destination.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Routing&lt;/strong&gt;– Determines the best path for data packets to travel across &lt;br&gt;
networks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Packet Forwarding&lt;/strong&gt; – Moves packets from one network to another based &lt;br&gt;
on routing decisions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Fragmentation and Reassembly&lt;/strong&gt; – Splits large data packets into &lt;br&gt;
smaller ones for transmission and reassembles them at the destination.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Error Handling &amp;amp; Diagnostics&lt;/strong&gt; – Uses protocols like ICMP to detect &lt;br&gt;
issues like unreachable hosts or network congestion.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Traffic Control &amp;amp; Congestion Avoidance&lt;/strong&gt; – Manages network congestion &lt;br&gt;
by optimizing data flow and rerouting packets if necessary.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  IP Addressing and Subnetting
&lt;/h2&gt;

&lt;p&gt;Before your data finds its way through the network, it needs an address—just like a home address for postal mail. In the networking world, this is done using IP addresses. The Network Layer ensures that every device has a unique identity so that data reaches the correct destination.&lt;/p&gt;

&lt;h3&gt;
  
  
  IPv4 vs. IPv6: The Addressing Evolution
&lt;/h3&gt;

&lt;p&gt;There are two main types of IP addresses:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;IPv4 (Internet Protocol Version 4)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Uses a 32-bit address (4 bytes).&lt;/li&gt;
&lt;li&gt;Decimal notation (e.g., 192.168.1.1).&lt;/li&gt;
&lt;li&gt;Can support around 4.3 billion unique addresses.&lt;/li&gt;
&lt;li&gt;Due to the internet’s rapid growth, IPv4 addresses are running out.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;IPv6 (Internet Protocol Version 6)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Uses a 128-bit address (16 bytes).&lt;/li&gt;
&lt;li&gt;Hexadecimal Notation (e.g., 2001:0db8:85a3:0000:0000:8a2e:0370:7334)&lt;/li&gt;
&lt;li&gt;Can support an almost infinite number of addresses(340 undecillion).&lt;/li&gt;
&lt;li&gt;Includes improved security and efficiency features.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Think of IPv4 as old-school phone numbers with limited digits, while IPv6 is like modern international phone numbers with a much larger range.&lt;/p&gt;

&lt;h3&gt;
  
  
  Classful Addressing: The Traditional IP Addressing Method
&lt;/h3&gt;

&lt;p&gt;Classful addressing was the original method used for IP address allocation, where IP addresses were divided into fixed-size classes.&lt;/p&gt;

&lt;p&gt;Each IP address consists of two parts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Network Part – Identifies the network.(prefix)&lt;/li&gt;
&lt;li&gt;Host Part – Identifies individual devices (hosts) within that network.(suffix)
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fii0f8nfi5k2erx3cjlle.png" alt="Ip address" width="450" height="221"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, classful addressing led to inefficient IP usage, which is why Classless Inter-Domain Routing (CIDR) replaced it. But understanding classful addressing is still important!&lt;/p&gt;

&lt;h3&gt;
  
  
  IP Address Classes (A to E)
&lt;/h3&gt;

&lt;p&gt;In classfull addressing, IP addresses are divided into five classes (A to E) based on their first few bits and range of values.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn9zlc57vho2qratb9zu0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn9zlc57vho2qratb9zu0.png" alt="Classes" width="800" height="246"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;1.Class A (Large Networks like ISPs, Government, Large Corporations)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First Bit: Always starts with 0 (binary: 0xxxxxxx).&lt;/li&gt;
&lt;li&gt;Range: 1.0.0.0 to 126.255.255.255.&lt;/li&gt;
&lt;li&gt;Prefix Length: 8 bits (n = 8) → Net ID: 8 bits, Host ID: 24 bits.&lt;/li&gt;
&lt;li&gt;Supports: 16 million hosts per network (2²⁴ - 2 addresses per network).&lt;/li&gt;
&lt;li&gt;Example: Google (8.8.8.8), Apple (17.x.x.x) use Class A addresses.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;📌 Note: 127.x.x.x is reserved for loopback addresses (used for testing on a local machine).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.Class B (Medium-Sized Networks like Universities, Large Organizations)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First Two Bits: Always starts with 10 (binary: 10xxxxxx).&lt;/li&gt;
&lt;li&gt;Range: 128.0.0.0 to 191.255.255.255.&lt;/li&gt;
&lt;li&gt;Prefix Length: 16 bits (n = 16) → Net ID: 16 bits, Host ID: 16 bits.&lt;/li&gt;
&lt;li&gt;Supports: 65,536 hosts per network (2¹⁶ - 2 addresses per network).&lt;/li&gt;
&lt;li&gt;Example: Many universities and corporations use Class B addresses.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3.Class C (Small Businesses, Local Networks, Home Networks)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First Three Bits: Always starts with 110 (binary: 110xxxxx).&lt;/li&gt;
&lt;li&gt;Range: 192.0.0.0 to 223.255.255.255.&lt;/li&gt;
&lt;li&gt;Prefix Length: 24 bits (n = 24) → Net ID: 24 bits, Host ID: 8 bits.&lt;/li&gt;
&lt;li&gt;Supports: 254 hosts per network (2⁸ - 2 addresses per network).&lt;/li&gt;
&lt;li&gt;Example: Home Wi-Fi networks often use private Class C addresses (192.168.x.x).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;📌 Note: This class is widely used in private networking (e.g., routers assigning IPs like 192.168.1.1).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.Class D (Multicast Applications like Streaming, Live Feeds)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First Four Bits: Always starts with 1110 (binary: 1110xxxx).&lt;/li&gt;
&lt;li&gt;Range: 224.0.0.0 to 239.255.255.255.&lt;/li&gt;
&lt;li&gt;Purpose: Used for multicasting, where one sender transmits to multiple receivers (e.g., video conferencing, IPTV).&lt;/li&gt;
&lt;li&gt;No Net ID / Host ID: Instead of assigning hosts, Class D uses group IDs.&lt;/li&gt;
&lt;li&gt;Example: Video streaming services and real-time data sharing use multicast addressing.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;📌 Note: Class D does not support subnetting since it’s used for group communication.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5.Class E (Experimental &amp;amp; Future Use, Reserved by IETF)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First Four Bits: Always starts with 1111 (binary: 1111xxxx).&lt;/li&gt;
&lt;li&gt;Range: 240.0.0.0 to 255.255.255.255.&lt;/li&gt;
&lt;li&gt;Purpose: Reserved for future networking research and experiments.&lt;/li&gt;
&lt;li&gt;Not Used for Public Internet: No devices or organizations use Class E addresses.&lt;/li&gt;
&lt;li&gt;Example: Research institutions and networking experiments may utilize this class.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;📌 Note: You cannot assign Class E addresses to hosts or routers in practical networking.&lt;/p&gt;

&lt;h3&gt;
  
  
  Casting in Networking: How Data is Sent
&lt;/h3&gt;

&lt;p&gt;In networking, casting refers to how data is transmitted from one device to another. There are three main types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Unicast&lt;/strong&gt;: Transmitting data from one source host to one destination host.(one to one transmission) (e.g., sending an email to a specific person).&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Multicast&lt;/strong&gt;: Transmitting data from one source host to a particular group of hosts having an interest in receiving the data.(One-to-many communication) (e.g., streaming a live event to multiple users).&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Broadcast&lt;/strong&gt;: Transmitting data from one source host to all other hosts residing in a network either same or other network.(One-to-all communication) (e.g., a DHCP request sent to all devices in a network).&lt;/li&gt;
&lt;/ul&gt;

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

&lt;h3&gt;
  
  
  What is Subnetting? Why is it Needed?
&lt;/h3&gt;

&lt;p&gt;Subnetting is the process of dividing a large network into smaller, manageable sub-networks (subnets).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why is subnetting important?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Helps reduce network congestion by limiting broadcast traffic.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Improves security by isolating different network segments.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ensures efficient use of IP addresses, preventing wastage.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, instead of using a single Class A network with millions of devices, subnetting allows dividing it into smaller networks to improve efficiency.&lt;/p&gt;

&lt;h3&gt;
  
  
  Subnet Mask: The Key to Subnetting
&lt;/h3&gt;

&lt;p&gt;A Subnet Mask helps identify which part of an IP address belongs to the network and which part belongs to the host.&lt;/p&gt;

&lt;p&gt;For example, in 192.168.1.0/24 (Subnet Mask: 255.255.255.0):&lt;/p&gt;

&lt;p&gt;192.168.1.0 is the network portion.&lt;/p&gt;

&lt;p&gt;The last octet (0-255) represents host addresses.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Common Subnet Masks:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Class A: 255.0.0.0 (/8)&lt;/p&gt;

&lt;p&gt;Class B: 255.255.0.0 (/16)&lt;/p&gt;

&lt;p&gt;Class C: 255.255.255.0 (/24)&lt;/p&gt;

&lt;p&gt;By adjusting the subnet mask, networks can be further divided into smaller subnets, optimizing IP allocation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Classless Addressing
&lt;/h3&gt;

&lt;p&gt;Classless Addressing is a modern method of IP addressing that removes the limitations of fixed classes (A, B, C) and allows networks to use IP addresses more efficiently. It is implemented through CIDR (Classless Inter-Domain Routing).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Was Classless Addressing Adopted?&lt;/strong&gt;&lt;br&gt;
Classful addressing caused two major problems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;IP Address Wastage:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Class A networks had 16 million addresses, but even a large 
organization might use only a few thousand.&lt;/li&gt;
&lt;li&gt;This led to a shortage of available IPv4 addresses.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Rigid Network Sizes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Companies needed more flexible subnetting instead of being 
forced into Class A, B, or C.&lt;/li&gt;
&lt;li&gt;Classless addressing allows custom subnet sizes instead of 
being stuck with classful limits.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;How Classless Addressing Works?&lt;/strong&gt;&lt;br&gt;
Instead of dividing IPs into strict classes, CIDR allows any number of bits to be allocated for the network and host portions. This helps in efficient IP allocation.&lt;/p&gt;

&lt;h3&gt;
  
  
  CIDR Notation (Classless Inter-Domain Routing Notation)
&lt;/h3&gt;

&lt;p&gt;CIDR (Classless Inter-Domain Routing) notation is a shorthand representation of IP addresses and their subnet masks. It defines how many bits belong to the network portion of an address.CIDR Notation Format: &lt;code&gt;IP Address / Subnet Bits&lt;/code&gt;, The /x (suffix) tells us how many bits are used for the network portion.The remaining bits are used for the host portion.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 1&lt;/strong&gt;: 192.168.1.0/24&lt;br&gt;
/24 means the first 24 bits are for the network.&lt;/p&gt;

&lt;p&gt;The last 8 bits are for host addresses.&lt;/p&gt;

&lt;p&gt;Subnet Mask: 255.255.255.0&lt;/p&gt;

&lt;p&gt;Total Hosts: 2⁸ - 2 = 254 (excluding network and broadcast addresses).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 2&lt;/strong&gt;: 10.0.0.0/16&lt;br&gt;
/16 means the first 16 bits are for the network.&lt;/p&gt;

&lt;p&gt;The remaining 16 bits are for host addresses.&lt;/p&gt;

&lt;p&gt;Subnet Mask: 255.255.0.0&lt;/p&gt;

&lt;p&gt;Total Hosts: 2¹⁶ - 2 = 65,534&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How CIDR Improves IP Allocation?&lt;/strong&gt;&lt;br&gt;
Instead of using fixed Class A, B, or C, CIDR customizes network sizes based on actual needs.&lt;br&gt;
&lt;u&gt;Example&lt;/u&gt;: A company may require 5000 IP addresses. In classful addressing, they would need a Class B network (65,536 IPs). With CIDR, they can use a /19 subnet (8192 IPs), avoiding waste.&lt;/p&gt;

&lt;h3&gt;
  
  
  Supernetting (Merging Multiple Networks into One)
&lt;/h3&gt;

&lt;p&gt;Supernetting is the process of combining multiple smaller networks (subnets) into a larger network to improve routing efficiency. It is the opposite of subnetting.&lt;/p&gt;

&lt;p&gt;Used to reduce routing table size by advertising one large block instead of multiple small ones.&lt;/p&gt;

&lt;h3&gt;
  
  
  IPv4 Header
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq2vhlnhvesq66a6th3hk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq2vhlnhvesq66a6th3hk.png" alt="Payload" width="465" height="148"&gt;&lt;/a&gt;&lt;br&gt;
a payload refers to the actual data being transmitted inside a packet. It is the part of the packet that carries the useful information intended for the receiver, excluding headers, trailers, and metadata.&lt;/p&gt;

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

&lt;h3&gt;
  
  
  IPv4 Header Fields
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Version&lt;/strong&gt; – Specifies the IP version being used. For IPv4, this value is always 4.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Header Length (HLEN)&lt;/strong&gt; – Defines the size of the header. Since IPv4 headers can have optional fields, their size may vary.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Type of Service (ToS) / Services type&lt;/strong&gt; – Helps prioritize network traffic. For example, video calls may need higher priority than normal browsing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Total Length&lt;/strong&gt; – Represents the full size of the packet, including the header and the actual data (payload).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Identification&lt;/strong&gt; – A unique number assigned to each packet to help reassemble fragmented data. If a large file is broken into smaller packets, this field helps put them back in order.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Flags&lt;/strong&gt; – Controls fragmentation of packets. It tells whether a packet can be fragmented and if more fragments are coming.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Fragment Offset&lt;/strong&gt; – If a packet is split into smaller parts, this field helps routers and devices reassemble them in the correct order.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Time to Live (TTL)&lt;/strong&gt; – Limits how long a packet can travel in a network. Each router decreases its value, and if it reaches zero, the packet is discarded to prevent infinite loops.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Protocol&lt;/strong&gt; – Indicates which transport layer protocol (like TCP or UDP) is being used to handle the data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Header Checksum&lt;/strong&gt; – A mechanism for error detection in the header. If an error is found, the packet is discarded and retransmitted.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Source IP Address&lt;/strong&gt; – The IP address of the device that sent the packet.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Destination IP Address&lt;/strong&gt; – The IP address of the intended recipient of the packet.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Options (Optional Field)&lt;/strong&gt; – Provides extra functionalities like security, timestamp, and routing preferences. It is not commonly used.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Padding (Optional Field)&lt;/strong&gt; – Fills up extra space in the header to maintain proper alignment for processing efficiency.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Key Limitation of IPv4 Header&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Lacks security features.&lt;/li&gt;
&lt;li&gt;Limited address space (only ~4.3 billion addresses).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  IPv6 Header Fields
&lt;/h3&gt;

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

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Version&lt;/strong&gt; – Specifies the IP version being used. For IPv6, this value is always 6.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Traffic Class&lt;/strong&gt; – Similar to the Type of Service (ToS) field in IPv4, it helps prioritize certain types of network traffic.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Flow Label&lt;/strong&gt; – Helps maintain smooth and consistent data flow for real-time applications like VoIP and video streaming.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Payload Length&lt;/strong&gt; – Specifies the size of the actual data (payload) being carried by the packet.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Next Header&lt;/strong&gt; – Specifies the type of information following the IPv6 header. It helps in identifying whether the next part is TCP, UDP, or additional extension headers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Hop Limit&lt;/strong&gt; – Functions like TTL in IPv4, preventing packets from looping indefinitely by decreasing its value at every hop. If it reaches zero, the packet is discarded.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Source Address&lt;/strong&gt; – The IPv6 address of the sender.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Destination Address&lt;/strong&gt; – The IPv6 address of the intended recipient.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Key Protocols of the Network Layer: ARP, ICMP, and IGMP
&lt;/h2&gt;

&lt;p&gt;The Network Layer is responsible for moving packets from source to destination. However, just sending packets isn’t enough—devices in a network need to find each other, report errors, and manage group communication. That’s where three important protocols come into play:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;ARP (Address Resolution Protocol) – Helps devices find each other in a local network.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ICMP (Internet Control Message Protocol) – Reports errors and network issues.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;IGMP (Internet Group Management Protocol) – Manages communication between multiple devices in a group.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2z7g0mp992cdi6dsdph5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2z7g0mp992cdi6dsdph5.png" alt="Protocol" width="633" height="274"&gt;&lt;/a&gt;&lt;br&gt;
Let’s break them down one by one.&lt;/p&gt;

&lt;h3&gt;
  
  
  Address Resolution Protocol (ARP) – "The Detective of the Network"
&lt;/h3&gt;

&lt;p&gt;Imagine you’re sending a letter to your friend. You know their name, but you don’t know their house number. So, you ask a neighbor, and they tell you the address. That’s exactly what ARP does in a network!&lt;/p&gt;

&lt;p&gt;Computers communicate using IP addresses, but actual data travels using MAC addresses (the physical address of a device’s network card). ARP maps IP addresses to MAC addresses so devices can find each other.&lt;/p&gt;

&lt;p&gt;🛠 &lt;strong&gt;How ARP Works?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;If a device wants to send data but only knows the IP address of the receiver, it broadcasts an ARP request asking, "Who has this IP? Tell me your MAC address!"&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The device with the matching IP replies with an ARP response containing its MAC address.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The sender now has the MAC address and can send the data.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;🔥 &lt;strong&gt;Why is ARP Important?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Without ARP, devices in a LAN wouldn’t be able to communicate because they wouldn’t know each other’s MAC addresses.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ARP caches (stores) resolved addresses to speed up future communication.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ARP can be exploited in cyberattacks (ARP Spoofing), where attackers trick a device into sending data to the wrong MAC address.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Internet Control Message Protocol (ICMP) – "The Network's Troubleshooter"
&lt;/h3&gt;

&lt;p&gt;ICMP is like a network doctor—it diagnoses connection problems and reports errors. It doesn’t send actual data but helps troubleshoot packet loss, unreachable networks, and latency issues.&lt;/p&gt;

&lt;p&gt;🛠 &lt;strong&gt;How ICMP Works?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;If a packet fails to reach its destination (e.g., due to an unreachable network), ICMP sends an error message back to the sender.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Network administrators use ping (ICMP Echo Request) to check if a device is online and responding.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Traceroute (ICMP Time Exceeded) helps find the path packets take across the internet.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🔥 &lt;strong&gt;Why is ICMP Important?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Helps diagnose connectivity issues (e.g., if a website is down).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Used in ping tests to check if a server or router is active.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Prevents endless loops by setting a Time-to-Live (TTL), so packets don’t travel forever.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;code&gt;Ping Command (ping google.com)&lt;/code&gt; – Sends ICMP Echo Requests to check if Google’s server is online.&lt;br&gt;
&lt;code&gt;Traceroute (tracert google.com)&lt;/code&gt; – Shows the path a packet takes to reach Google’s servers.&lt;/p&gt;

&lt;p&gt;⚠️ &lt;strong&gt;Security Concern&lt;/strong&gt;:&lt;br&gt;
Attackers can use ICMP in DDoS attacks (e.g., Ping of Death, Smurf Attack) to flood a network with useless traffic.&lt;/p&gt;

&lt;h3&gt;
  
  
  Internet Group Management Protocol (IGMP) – "The Group Manager"
&lt;/h3&gt;

&lt;p&gt;IGMP helps devices communicate in multicast groups. Instead of sending multiple copies of the same data to different devices, IGMP allows efficient group communication by delivering data to multiple recipients at once.&lt;/p&gt;

&lt;p&gt;🛠 &lt;strong&gt;How IGMP Works?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A device joins a multicast group (e.g., an online live stream).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The router, using IGMP, registers the device and ensures it receives the multicast data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When the device leaves the group, IGMP updates the router to stop sending unnecessary traffic.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🔥 &lt;strong&gt;Why is IGMP Important?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Reduces network traffic by avoiding duplicate transmissions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Used in live video streaming, online gaming, and IPTV (Internet TV).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Helps in efficient routing for group-based communication.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example of IGMP in Action&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Watching a Live Sports Stream&lt;/code&gt;: Instead of sending the same video to each viewer individually, the server sends one multicast stream, and IGMP ensures only interested users receive it.&lt;/p&gt;




&lt;h2&gt;
  
  
  Routing in the Network Layer
&lt;/h2&gt;

&lt;p&gt;Routing is the process of finding the best path for data packets to travel from the sender to the receiver across multiple networks. It ensures that data reaches its correct destination efficiently.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;How Does Routing Work?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Every packet has a destination IP address.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Routers analyze the destination address and decide where to forward the packet.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Routers use routing tables and algorithms to determine the best path for packet delivery.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Types of Routing&lt;/strong&gt;&lt;br&gt;
&lt;u&gt;Static Routing&lt;/u&gt; – Routes are manually configured by the network administrator.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Dynamic Routing&lt;/u&gt; – Routes are automatically learned and updated using routing protocols.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Default Routing&lt;/u&gt; – Used when there is only one exit path for all unknown destinations (common in home networks).&lt;/p&gt;

&lt;h2&gt;
  
  
  Packet Forwarding and Routing Tables
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What is Packet Forwarding?&lt;/strong&gt;&lt;br&gt;
Once a router decides the best path for a packet, it needs to forward the packet to the next device on the path. This process is called packet forwarding.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is a Routing Table?&lt;/strong&gt;&lt;br&gt;
A routing table is a list of rules that helps routers decide where to send packets. It contains:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Destination IP Address – Where the packet needs to go.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next Hop – The next device/router in the path.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Metric – A value that helps determine the best route (e.g., shortest path, fastest link).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnez5d3hbgeu8blu0ch5r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnez5d3hbgeu8blu0ch5r.png" alt="Routing Table" width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
Routing Protocols Used for Packet Forwarding&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;RIP (Routing Information Protocol) – Uses hop count to find the best path.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;OSPF (Open Shortest Path First) – Uses link-state information to calculate the best route.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;BGP (Border Gateway Protocol) – Used for routing between different networks on the internet.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Network Address Translation (NAT) &amp;amp; Its Role
&lt;/h2&gt;

&lt;p&gt;Network Address Translation (NAT) is a technique that allows multiple devices in a private network to share a single public IP address to access the internet.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why is NAT Important?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Solves IPv4 Address Shortage – Since IPv4 addresses are limited, NAT allows multiple devices to use a single IP address.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Adds a Layer of Security – NAT hides internal IP addresses, making it harder for hackers to target devices.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reduces Costs – ISPs provide fewer public IPs, and companies can still connect multiple devices.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Types of NAT&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;u&gt;Static NAT&lt;/u&gt; – Maps one private IP to one public IP.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;u&gt;Dynamic NAT&lt;/u&gt; – Maps private IPs to a pool of public IPs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;u&gt;PAT (Port Address Translation)&lt;/u&gt; – Multiple private IPs share one public IP using different port numbers (most common type).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example of NAT in Action&lt;/strong&gt;&lt;br&gt;
&lt;u&gt;Home Network Example:&lt;/u&gt;&lt;br&gt;
Your home router has one public IP address, but multiple devices (laptops, phones, TVs) can browse the internet using that same public IP due to NAT.&lt;/p&gt;




&lt;h2&gt;
  
  
  Challenges and Security Concerns in the Network Layer
&lt;/h2&gt;

&lt;p&gt;While the network layer ensures smooth communication, it also faces several challenges and security risks:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Routing Attacks&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Man-in-the-Middle (MITM) Attack – Attackers intercept and manipulate network traffic.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Route Hijacking – Malicious entities advertise incorrect routes, disrupting traffic flow.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. IP Address Spoofing&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hackers fake an IP address to disguise their identity or impersonate a trusted device.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. DDoS (Distributed Denial of Service) Attacks&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Attackers overload a network with massive traffic, causing services to crash.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4. IPv4 Address Exhaustion&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;IPv4 addresses are running out, making IPv6 adoption necessary.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;5. NAT and Performance Issues&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;While NAT provides security, it can cause issues with applications that require direct peer-to-peer communication, such as VoIP and online gaming.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The Network Layer is a crucial part of the OSI model that ensures data is properly routed and delivered across different networks. It manages &lt;u&gt;IP addressing&lt;/u&gt;, &lt;u&gt;packet forwarding&lt;/u&gt;, and &lt;u&gt;routing&lt;/u&gt;, &lt;u&gt;making global communication possible&lt;/u&gt;. Technologies like &lt;u&gt;IPv4&lt;/u&gt;, &lt;u&gt;IPv6&lt;/u&gt;, &lt;u&gt;NAT&lt;/u&gt;, and &lt;u&gt;routing protocols&lt;/u&gt; help in efficient data transmission, while security measures protect networks from attacks.&lt;/p&gt;

&lt;p&gt;Thank you for reading! I hope this blog helped you understand the Network Layer better. If you found it useful, feel free to follow me on my social media for more tech content:&lt;br&gt;
🔗 &lt;a href="https://www.linkedin.com/in/singhaayush079/" rel="noopener noreferrer"&gt;Linkedin&lt;/a&gt;&lt;br&gt;
🔗 &lt;a href="https://x.com/saayush615" rel="noopener noreferrer"&gt;X (Twitter)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Stay connected and keep learning! 🚀&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>networking</category>
      <category>network</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Error-Free Communication: How the Data Link Layer Ensures Reliable Data Transfer</title>
      <dc:creator>Aayush Singh</dc:creator>
      <pubDate>Sun, 23 Feb 2025 17:08:51 +0000</pubDate>
      <link>https://dev.to/singhaayush/error-free-communication-how-the-data-link-layer-ensures-reliable-data-transfer-i4f</link>
      <guid>https://dev.to/singhaayush/error-free-communication-how-the-data-link-layer-ensures-reliable-data-transfer-i4f</guid>
      <description>&lt;p&gt;Till now we have studied about MAC addressing, Framing and Random access concepts in Data link layer. In this blog we will Explore more about how the DLL Handle errors in the transmission of data and flow control. so Let's start:&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;u&gt;Flow control&lt;/u&gt;
&lt;/h2&gt;

&lt;p&gt;Flow control is a technique to prevent the data overflow, the receiver has buffer memory where the incoming data are temporarily stored until processed, and the data processing speed often lags behind the transmission rate.&lt;/p&gt;

&lt;p&gt;Flow control can be basically divided in two types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;u&gt;Stop-and-Wait Flow Control&lt;/u&gt;&lt;/strong&gt;: In this the sender divides data in frames sends one frame(and keep its copy) and wait a particular time(starts a timer) to receive an acknowledgment to send other frame, if the acknowledgment is not received due to any reason in a particular time the sender will resend the frame and again starts the timer. If the acknowledgment is arrived it will discard the frame and sends the other frame. In this method, only one of frames can be in transmission at a time. It leads to inefficiency. see the below diagram to get better understanding.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Lets discuss the diagram:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;first frame 0 is send (timer is start), the receiver received it successfully and sends the acknowledgment for transmitting the frame-1. &lt;/li&gt;
&lt;li&gt;The sender received the ack 1 successfully and send frame-1 (starts a timer), due to some issue this frame1 is lost, sender will not get any ack after a particular time timer stops ,resend the frame1 and again restarts the timer. &lt;/li&gt;
&lt;li&gt;frame1 is successfully arrived and ack 0 is successfully received by sender. Sender sends Frame 0 it is received by receiver but this time the ack 1 get lost. so, the sender does not receive the ack 1 so it resends the frame 0. and this goes on.
I hope from the above explanation you got the concept of stop and wait. But before proceeding to another flow control time, let us discuss about some delays to get a better understanding about delays.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7kxz0sj0t64jfd09d5zh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7kxz0sj0t64jfd09d5zh.png" alt="Delay" width="800" height="170"&gt;&lt;/a&gt;&lt;br&gt;
You can classify delay in 4 types:&lt;br&gt;
1.Propagration Delay: This is time it takes for a bit to travel from point A to point B in transmission media.(denoted by Tp)&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Tp = (Distance) / (propagation speed)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;2.Transmission Delay: A sender needs to put the bits in a packet on the line one by one. If the first bit of the packet is put on the line at time t1 and the last bit is put on the line at time t2, transmission delay of the packet is (t2-t1). (denoted by TT)&lt;/p&gt;

&lt;p&gt;&lt;code&gt;TT = (packet length) / Transmission rate or Bandwidth&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;3.Queuing Delay - It is measured as time a packet waits in the input queue and output queue of a router.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;queue delay = The time a packet waits in input and output queues in a router&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;4.Processing Delay - It is a time require for a Destination host to receive a packet from its input port, remove the header,perform an error detection procedure, and deliver the packet to the output port or deliver the packet to the upper-layer protocol(in case of destination host).&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Delay = Time require to process a packet in a destination host.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;As you know the frames are send one by one in stop-and-wait. It is an inefficient method to transfer frame the more efficient method is Sliding Window flow control. In this multiple frames can be sent before waiting for acknowledgment.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;u&gt;Sliding Window Protocol&lt;/u&gt;&lt;/strong&gt;:  Sliding Window allows a sender to transmit several frames consecutively, reducing idle time and improving network efficiency. The "window" refers to the number of frames that can be sent before the sender must pause and wait for acknowledgment.
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F76b7kspk6p5wtodyk978.png" alt="sliding window" width="800" height="216"&gt;
In this example just think window length 15(0-14). If all the 15 frames are send at once. If the sender receives acknowledgment of just say 6, It means all the frames before 6 have definitely been received so it will discard 0-5 and move the window forward to send more.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This protocol operates in two main variants: Go-Back-N ARQ and Selective Repeat ARQ. &lt;/p&gt;

&lt;p&gt;1.&lt;strong&gt;Go-Back-N Automatic Repeat Request&lt;/strong&gt;&lt;br&gt;
Go-Back-N Automatic Repeat Request (ARQ) is a sliding window protocol used for reliable data transmission.In this method, the sender can transmit up to N frames (as defined by the window size) before needing an acknowledgment. However, if an error or packet loss occurs, the receiver rejects the erroneous frame and all subsequent frames, forcing the sender to go back and retransmit from the errored frame onward—even if some frames were received correctly.&lt;/p&gt;

&lt;p&gt;For example, if a sender transmits frames 1 to 5 and an error occurs in frame 3, the receiver discards frames 3, 4, and 5 and requests retransmission starting from frame 3. This makes Go-Back-N simple to implement but can be inefficient in high-latency networks, as it wastes bandwidth by resending correctly received frames. Despite its inefficiency, it remains widely used in protocols like TCP (with certain modifications) due to its simplicity and robustness.&lt;/p&gt;

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

&lt;blockquote&gt;
&lt;p&gt;The send window,an imaginary concept, covers the sequence numbers of frames that can be in transit, having maximum size of 2^m - 1.&lt;/p&gt;

&lt;p&gt;Sequence numbers are divided into four regions: the first represents acknowledged frames(no copies kept), the second represents frames sent but with unknown status(outstanding farmes), the third denotes frames ready to be sent pending data packets from the network layer, and the fourth signifies sequence numbers inaccessible until the window slides further.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;2.&lt;strong&gt;Selective Repeat ARQ&lt;/strong&gt; : Selective Repeat Automatic Repeat Request (ARQ) is a more efficient sliding window protocol designed to minimize unnecessary retransmissions. Unlike Go-Back-N ARQ, where all frames after an erroneous one are discarded and resent, Selective Repeat only retransmits the corrupted or lost frames, saving bandwidth and improving network efficiency.&lt;/p&gt;

&lt;p&gt;In this method, both the sender and receiver maintain separate sliding windows. The receiver stores correctly received frames in a buffer, even if they arrive out of order, and requests retransmission only for the missing or corrupted frames(Negetaive acknowledgment). Once all expected frames are received in order, the data is passed to the upper layer.&lt;/p&gt;

&lt;p&gt;For example, if the sender transmits frames 1 to 5, and only frame 3 is lost or corrupted, the receiver will acknowledge frames 1, 2, 4, and 5 and request only frame 3 to be resent. This prevents redundant retransmissions, making Selective Repeat ARQ more bandwidth-efficient than Go-Back-N, especially in networks with high error rates. However, it requires more complex buffering and processing at both sender and receiver, making its implementation more resource-intensive. It is commonly used in high-speed and wireless networks where minimizing retransmissions is crucial.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;u&gt;Error Detection and correction&lt;/u&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Understanding Errors in Data Transmission
&lt;/h3&gt;

&lt;p&gt;In any communication system, data transmission errors are inevitable due to various physical and environmental factors. Whether you're sending a text message, streaming a video, or making an online transaction, data must travel through wired or wireless networks, and during this journey, it can get corrupted. Ensuring data accuracy and reliability is crucial, which is why networking protocols implement error detection and correction mechanisms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What Are Errors in Networking?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An error occurs when the data received at the destination differs from the data sent by the source. These errors are usually caused by: Electromagnetic interference, Noise in transmission mediums, Signal attenuation, Synchronization issues.&lt;/p&gt;

&lt;p&gt;Even a single bit error can cause major problems. For example, if a bank transaction of ₹5000 gets altered to ₹9000 due to an error, the consequences can be severe. This is why detecting and correcting errors is a fundamental part of networking.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Types of Errors&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;Errors in data transmission are classified into two main types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Single-Bit Errors
A single bit is flipped (0 → 1 or 1 → 0) due to noise or interference.
Rare in wired networks but more common in wireless communication.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example:&lt;br&gt;
Sent: 1011001&lt;br&gt;
Received: 1011101 (4th bit flipped)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Burst Errors
Multiple bits are altered in a sequence.
More common in wireless and long-distance wired networks.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example:&lt;br&gt;
Sent: 1101010110&lt;br&gt;
Received: 1100000110 (4-bit burst error)&lt;/p&gt;

&lt;p&gt;Since errors cannot always be avoided, networks use error detection and correction techniques to identify and fix corrupted data before it causes failures.&lt;/p&gt;

&lt;p&gt;This sets the foundation for understanding how error detection and correction techniques work, ensuring data integrity and reliable communication across networks. &lt;/p&gt;

&lt;h3&gt;
  
  
  Error Detection and Correction Techniques
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Parity Check (Single and Two-Dimensional Parity)&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;u&gt;Single Parity Check (Even and Odd Parity)&lt;/u&gt;: Parity checking is one of the simplest error detection methods, where an extra bit, called the parity bit, is added to a data unit (byte, word, or frame). The purpose of the parity bit is to ensure that the total number of 1s is either even or odd, depending on the chosen scheme.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;blockquote&gt;
&lt;p&gt;Even Parity: The number of 1s in the data, including the parity bit, must be even.&lt;br&gt;
Odd Parity: The number of 1s in the data, including the parity bit, must be odd.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Example of Even Parity:&lt;br&gt;
If we want to send the 4-bit data "1010", we add a parity bit to ensure an even number of 1s.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
  &lt;tr&gt;
    &lt;th&gt;Data Bits&lt;/th&gt;
    &lt;th&gt;Parity Bit (Even)&lt;/th&gt;
    &lt;th&gt;Transmitted Bits&lt;/th&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;1010&lt;/td&gt;
    &lt;td&gt;0&lt;/td&gt;
    &lt;td&gt;10100&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;1101&lt;/td&gt;
    &lt;td&gt;1&lt;/td&gt;
    &lt;td&gt;11011&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;At the receiver end: If an error occurs and the number of 1s becomes odd, it signals that the data is corrupted.&lt;/p&gt;

&lt;p&gt;Limitations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cannot detect even-numbered bit errors (e.g., two bits flipped won’t change parity).&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Does not correct errors, only detects them.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;u&gt;Two-Dimensional Parity Check&lt;/u&gt; : To improve error detection, a two-dimensional parity check extends parity checking across multiple data units (rows and columns).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjg1rr0u9g5j2qop1icpn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjg1rr0u9g5j2qop1icpn.png" alt="Two-Dimensional Parity Check" width="800" height="410"&gt;&lt;/a&gt;&lt;br&gt;
How It Works:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A parity bit is added to each row of data (horizontal parity).&lt;/li&gt;
&lt;li&gt;Another parity bit is added for each column (vertical parity).&lt;/li&gt;
&lt;li&gt;The receiver checks both row and column parity to identify errors.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;2.&lt;strong&gt;Checksum&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The Checksum method is used in network protocols like TCP/IP to detect errors in transmitted data. Instead of checking individual bits, the checksum verifies an entire block of data by computing a sum of its values.&lt;/p&gt;

&lt;p&gt;How It Works:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The sender divides data into equal-sized segments (e.g., 16-bit words).&lt;/li&gt;
&lt;li&gt;It calculates the sum of all segments and sends the sum (checksum) along 
with the data.&lt;/li&gt;
&lt;li&gt;The receiver performs the same sum calculation and compares it with the 
transmitted checksum.&lt;/li&gt;
&lt;li&gt;If they match → Data is correct.&lt;/li&gt;
&lt;li&gt;If they don’t match → An error is detected.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example:&lt;br&gt;
Assume we are transmitting two 16-bit data words:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
  &lt;tr&gt;
    &lt;th&gt;Data 1&lt;/th&gt;
    &lt;th&gt;Data 2&lt;/th&gt;
    &lt;th&gt;Checksum (Sum of Data)&lt;/th&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;10011001 10101010&lt;/td&gt;
    &lt;td&gt;11001100 11110000&lt;/td&gt;
    &lt;td&gt;01100110 10100010&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;If any bit in the data gets corrupted, the receiver's sum will not match the transmitted checksum, signaling an error.&lt;/p&gt;

&lt;p&gt;Limitations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cannot detect some burst errors, especially if errors cancel each other 
out.&lt;/li&gt;
&lt;li&gt;Does not correct errors, only detects them.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;3.&lt;strong&gt;Cyclic Redundancy Check (CRC)&lt;/strong&gt;&lt;br&gt;
Cyclic Redundancy Check (CRC) is a powerful error detection technique used in network protocols like Ethernet and Wi-Fi. It is based on binary division and is more reliable than parity and checksum methods.&lt;/p&gt;

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

&lt;p&gt;How CRC Works:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The sender treats the data as a long binary number.&lt;/li&gt;
&lt;li&gt;It divides this number by a predetermined divisor (generator polynomial) using modulo-2 division (binary division without carry).&lt;/li&gt;
&lt;li&gt;The remainder of this division is the CRC code, which is appended to the data before transmission.
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz4xwptlpqav387o913bi.png" alt="Encoader" width="769" height="678"&gt;
&lt;/li&gt;
&lt;li&gt;The receiver performs the same division and checks the remainder:

&lt;ul&gt;
&lt;li&gt;If the remainder is zero → No error detected.&lt;/li&gt;
&lt;li&gt;If the remainder is non-zero → Error detected.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Example (Simplified CRC Calculation):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Suppose the data to be sent is 101100 and the divisor (generator) is 1101.&lt;/li&gt;
&lt;li&gt;The sender appends zeros (one less than the divisor length) → 101100000.&lt;/li&gt;
&lt;li&gt;The sender divides 101100000 ÷ 1101 (using XOR operations).&lt;/li&gt;
&lt;li&gt;The remainder (CRC code) is 011, which is appended to the original data.
&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;tr&gt;
&lt;th&gt;Data&lt;/th&gt;
&lt;th&gt;CRC code&lt;/th&gt;
&lt;th&gt;Transmitted Data&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;101100&lt;/td&gt;
&lt;td&gt;011&lt;/td&gt;
&lt;td&gt;101100011&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;The receiver divides 101100011 ÷ 1101:

&lt;ul&gt;
&lt;li&gt;If remainder = 0 → No error.&lt;/li&gt;
&lt;li&gt;If remainder ≠ 0 → Error detected.
Advantages of CRC:&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Can detect multiple-bit errors (unlike parity and checksum).&lt;/li&gt;

&lt;li&gt;Used in high-speed networks like Ethernet.&lt;/li&gt;

&lt;li&gt;Efficient for large data blocks.&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Limitations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cannot correct errors, only detects them.&lt;/li&gt;
&lt;li&gt;Complex compared to parity and checksum methods.&lt;/li&gt;
&lt;/ul&gt;




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

&lt;p&gt;In computer networks, ensuring reliable communication is a combination of error control and flow control. Error control mechanisms like Parity Check, Checksum, and CRC help detect corrupted data, while advanced techniques like ARQ (Automatic Repeat reQuest) ensure lost or erroneous packets are retransmitted. On the other hand, flow control mechanisms like Stop-and-Wait, Sliding Window, and Selective Repeat help regulate data transmission so that a fast sender does not overwhelm a slow receiver. Together, these techniques ensure data integrity and efficient transmission across networks.&lt;/p&gt;

&lt;p&gt;Thanks for reading till here! I hope this blog helped you understand error detection, correction, and flow control in the Data Link Layer. In the next blog, we will dive into the Network Layer, where we’ll explore IP addressing, routing, and more. Stay tuned! 🚀 Follow me on &lt;a href="https://x.com/saayush615" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; and &lt;a href="https://www.linkedin.com/in/singhaayush079/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; for more updates.&lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>networking</category>
      <category>network</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Bridging the Gap: How the Data Link Layer Keeps Your Network Connected</title>
      <dc:creator>Aayush Singh</dc:creator>
      <pubDate>Mon, 10 Feb 2025 18:24:47 +0000</pubDate>
      <link>https://dev.to/singhaayush/bridging-the-gap-how-the-data-link-layer-keeps-your-network-connected-62e</link>
      <guid>https://dev.to/singhaayush/bridging-the-gap-how-the-data-link-layer-keeps-your-network-connected-62e</guid>
      <description>&lt;p&gt;In this blog we are going to deep dive into DataLink layer(DLL). Let's start our discussion with the Textbook definition "The Data Link Layer is the second layer of the OSI model.It is responsible for receiving and getting data &lt;em&gt;bits&lt;/em&gt; usually from Physical Layer and then converting these bits into groups, known as data link &lt;em&gt;frames&lt;/em&gt; so that it can be transmitted further". In short, its main job is to ensure reliable data transfer between two directly connected nodes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Responsibilities:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Framing&lt;/strong&gt;: It takes raw bits from the physical layer and organizes them into &lt;em&gt;frames&lt;/em&gt; (like envelopes for sending messages).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Error Detection and correction&lt;/strong&gt;: It checks for errors in transmitted data using methods like parity checks, CRC (Cyclic Redundancy Check), and checksum. For correction, methods like Automatic Repeat Request (ARQ) are used.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Flow Control&lt;/strong&gt;: Prevents a fast sender from overwhelming a slow receiver, like a traffic signal controlling the flow of cars. It include method like stop-and-wait &amp;amp; Sliding window.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Media Access Control (MAC)&lt;/strong&gt;: MAC Address is a hardware address associated to a network interface card (NIC) or network device. Determines who can send data and when especially in shared networks like Wi-Fi or Ethernet.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Divisions of the Data Link Layer
&lt;/h3&gt;

&lt;p&gt;It has two sublayers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Logical Link Control (LLC): It handles error detection &amp;amp; flow control. Ensures communication between devices works smoothly.&lt;/li&gt;
&lt;li&gt;Media Access Control (MAC): Manages physical addressing (MAC addresses).Controls how devices access and share the network medium (wired or wireless).&lt;/li&gt;
&lt;/ul&gt;

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

&lt;h2&gt;
  
  
  Media Access Control
&lt;/h2&gt;

&lt;p&gt;when nodes or stations are connected and use a common link, we need a multiple-access protocol to coordinate access to the link. &lt;/p&gt;

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

&lt;p&gt;In multiple-access protocol we are only going to discuss about &lt;em&gt;Random access protocol&lt;/em&gt;, since rest of the protocol is Advance and not much related to CS/IT. Let's start.&lt;/p&gt;




&lt;h3&gt;
  
  
  Random Access
&lt;/h3&gt;

&lt;p&gt;Random Access Protocols are used in networks where multiple devices share a common communication channel. These protocols allow devices to transmit data whenever they have data to send, but they also have mechanisms to handle collisions (when two devices transmit at the same time).It is called a Random Access Protocol because there is no fixed order or schedule for devices to send data. Instead, devices transmit whenever they have data, leading to random chances of collisions.&lt;/p&gt;

&lt;p&gt;Think of it like a group of people talking in a room without a moderator—sometimes, two people talk at the same time, leading to confusion (collision), and they have to pause and retry.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Important Note:&lt;br&gt;
All the protocols in the Random access approach will answer the following questions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;When can the station access the medium?&lt;/li&gt;
&lt;li&gt;What can the station do if the medium is busy?&lt;/li&gt;
&lt;li&gt;How can the station determine the success or failure of transmission?&lt;/li&gt;
&lt;li&gt;What can the station do if there is an access conflict?&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  1.ALOHA
&lt;/h4&gt;

&lt;p&gt;ALOHA was one of the earliest random access protocols, developed in the 1970s for wireless communication.The main idea of ALOHA is how it handles collisions, which happen when two devices try to send data at the same time, causing interference. &lt;br&gt;
There are two version of ALOHA protocol:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;&lt;u&gt;Pure ALOHA&lt;/u&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Pure ALOHA refers to the original ALOHA protocol. It is a Random Access Protocol where devices send data whenever they want, without checking if the channel is free. If two devices transmit at the same time, a collision occurs, and they need to retransmit after a random time.&lt;/p&gt;

&lt;p&gt;Since multiple devices can transmit at the same time, collisions are common.If the receiver does not send the acknowledgment, the sender will assume that it has not been received and sender resends the message. &lt;/p&gt;

&lt;p&gt;Since collisions are frequent, much of the network capacity is wasted.maximum efficiency of Pure ALOHA is only 18.4%, meaning most transmissions fail.Pure ALOHA is mainly used in wireless communication (satellites, RFID systems) where devices cannot easily detect other transmissions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk66p3cfrizpqwba5f01y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk66p3cfrizpqwba5f01y.png" alt="collision" width="800" height="342"&gt;&lt;/a&gt;&lt;br&gt;
With this diagram you can clearly see that last bit of frame A is colliding with first bit of frame B. vulnerable time in which there is a possibility of collision, we can see that the time during which the collision may occur in pure ALOHA. &lt;code&gt;Vulnerable time = 2*Transmission delay&lt;/code&gt; (we will discuss Transmission delay later).&lt;/p&gt;

&lt;p&gt;2.&lt;strong&gt;&lt;u&gt;Slotted ALOHA&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
Slotted ALOHA is an improved version of Pure ALOHA that reduces collisions by dividing time into fixed slots. Devices can only send data at the beginning of a time slot, which synchronizes transmissions and improves efficiency with max efficiency of 36.8%.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The channel is divided into equal-sized time slots, and devices can only send data at the start of a slot.&lt;/li&gt;
&lt;li&gt;This ensures that collisions can only happen if two devices pick the same slot, unlike Pure ALOHA where collisions happen anytime.&lt;/li&gt;
&lt;li&gt;If a collision happens, devices wait for a random number of time slots before trying again.This helps reduce repeated collisions in the next slot.&lt;/li&gt;
&lt;li&gt;Slotted ALOHA is used in wireless systems where devices can be synchronized, like satellite uplinks and RFID (contactless card systems).&lt;/li&gt;
&lt;/ul&gt;

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

&lt;h4&gt;
  
  
  2.Carrier Sense Multiple Access (CSMA)
&lt;/h4&gt;

&lt;p&gt;CSMA reduces collisions by first listening to the channel before transmitting which means In this protocol, each device first sense the channel before sending the data. If the channel is busy, the device waits until it is free. This helps reduce collisions. There are two ways to check if the channel is busy or idle:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Persistent CSMA&lt;/strong&gt;: Keeps checking and sends immediately if the channel is free. (Higher chance of collision).&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Non-Persistent CSMA&lt;/strong&gt;: Waits a random time before checking again. (Reduces collision chances).&lt;/li&gt;
&lt;/ul&gt;

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

&lt;h4&gt;
  
  
  3.CSMA/CD (Carrier Sense Multiple Access with Collision Detection)
&lt;/h4&gt;

&lt;p&gt;CSMA/CD is used in wired networks (Ethernet) to detect and handle collisions when multiple devices transmit at the same time. If a collision occurs, devices stop transmission, send a jam signal, and retry after a random delay to avoid repeated collisions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How CSMA/CD Works?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Carrier Sense (Listen Before Sending): 

&lt;ul&gt;
&lt;li&gt;The device listens to the channel before sending data.&lt;/li&gt;
&lt;li&gt;If the channel is free, it sends the data.&lt;/li&gt;
&lt;li&gt;If the channel is busy, it waits for a random time before trying 
again.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Collision Detection (Detecting a Crash): 

&lt;ul&gt;
&lt;li&gt;If two devices send data at the same time, a collision happens, and 
data gets corrupted.&lt;/li&gt;
&lt;li&gt;Devices can detect this because they hear a jumbled signal (like 
overlapping voices in a room).&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Jam Signal (Alert Everyone): 

&lt;ul&gt;
&lt;li&gt;When a collision is detected, a "jam signal" is sent to notify all 
devices.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Random Backoff (Wait and Retry): 

&lt;ul&gt;
&lt;li&gt;The devices that collided wait for a random time before 
retransmitting&lt;/li&gt;
&lt;li&gt;This helps reduce repeated collisions.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Imagine a two-way road where cars can only pass if the road is clear&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A driver (device) checks if the road is empty (carrier sensing).&lt;/li&gt;
&lt;li&gt;If clear, the driver moves.&lt;/li&gt;
&lt;li&gt;If two cars move at the same time (collision), they both stop (detect 
collision).&lt;/li&gt;
&lt;li&gt;They wait for a random time before trying again to avoid another crash.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  4.CSMA/CA (Carrier Sense Multiple Access with Collision Avoidance)
&lt;/h4&gt;

&lt;p&gt;CSMA/CA is used in wireless networks (Wi-Fi) to prevent collisions before they happen. Devices first send an RTS (Request to Send) signal, wait for a CTS (Clear to Send) response, and then transmit data to ensure smooth communication.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why CSMA/CA is Needed for Wireless?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In Wi-Fi, devices cannot "hear" each other's transmissions properly 
(hidden node problem).&lt;/li&gt;
&lt;li&gt;Unlike Ethernet, wireless signals can’t detect collisions, so CSMA/CA 
prevents collisions instead of detecting them.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;How CSMA/CA Works?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Carrier Sense (Listen Before Sending):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The device checks if the channel is idle.&lt;/li&gt;
&lt;li&gt;If busy, it waits before trying again.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Request to Send (RTS) &amp;amp; Clear to Send (CTS):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Instead of just sending data, the device first sends an RTS (Request
to Send) signal to the access point (Wi-Fi router).&lt;/li&gt;
&lt;li&gt;If the channel is free, the router replies with a CTS (Clear to 
Send) signal.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Data Transmission (Safe to Send) :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;After receiving CTS, the device transmits data.&lt;/li&gt;
&lt;li&gt;Other devices stay silent to avoid interference.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Acknowledgment (ACK):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The receiver sends an ACK (Acknowledgment) message confirming 
successful reception.&lt;/li&gt;
&lt;li&gt;If no ACK is received, the sender assumes a collision happened and 
retries after a random time.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Imagine a classroom where students ask for permission to speak&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A student (device) raises their hand (RTS - Request to Speak).&lt;/li&gt;
&lt;li&gt;The teacher (Wi-Fi router) grants permission (CTS - Clear to Speak).&lt;/li&gt;
&lt;li&gt;The student speaks (data transmission).&lt;/li&gt;
&lt;li&gt;The teacher nods (ACK) to confirm the message was heard.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  MAC Address
&lt;/h3&gt;

&lt;p&gt;A MAC address is a 48-bit (6-byte) unique hardware address assigned to a network interface card (NIC) by the manufacturer. It is used to identify devices in a Local Area Network (LAN).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Format&lt;/u&gt;&lt;/strong&gt; : &lt;br&gt;
A MAC address is usually written in hexadecimal format, separated by colons or hyphens.&lt;br&gt;
    - Example: 00:A0:C9:14:C8:29 or 00-A0-C9-14-C8-29&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Structure (6 Bytes = 48 Bits)&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
  &lt;tr&gt;
    &lt;th&gt;First 3 Bytes (24 bits)&lt;/th&gt;
    &lt;th&gt;Last 3 Bytes (24 bits)&lt;/th&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt; **Organizationally Unique Identifier(OUI)** - Assigned to manufacturer&lt;/td&gt;
    &lt;td&gt; **Device Identifier(NIC Specific)** - Unique to each device&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Example: 00:A0:C9 → Manufacturer &lt;/td&gt;
    &lt;td&gt;Example: 14:C8:29 → Unique Device ID&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Here are some OUI of well-known manufacturers:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;CC:46:D6 - Cisco &lt;br&gt;
3C:5A:B4 - Google, Inc.&lt;br&gt;
3C:D9:2B - Hewlett Packard&lt;br&gt;
00:9A:CD - HUAWEI TECHNOLOGIES CO.,LTD&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Why is a MAC Address Needed?&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Uniquely identifies devices in a network (like a fingerprint for your computer).&lt;/li&gt;
&lt;li&gt;Used in the Data Link Layer for local communication within a LAN.&lt;/li&gt;
&lt;li&gt;Helps switches forward data to the correct device in a network.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Types of MAC Addresses&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
MAC addresses can be categorized based on their purpose:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
  &lt;tr&gt;
    &lt;th&gt;Type&lt;/th&gt;
    &lt;th&gt;Description&lt;/th&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Unicast MAC Address&lt;/td&gt;
    &lt;td&gt;Used to send data to a single specific device in a network.&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Multicast MAC Address&lt;/td&gt;
    &lt;td&gt;Used to send data to a group of devices (e.g., video streaming). 
    &lt;/td&gt;
  &lt;/tr&gt;
&lt;tr&gt;
    &lt;td&gt;Broadcast MAC Address&lt;/td&gt;
    &lt;td&gt;Used to send data to all devices in a network (FF:FF:FF:FF:FF:FF).&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If a switch wants to send data to one computer, it uses a unicast MAC 
address.&lt;/li&gt;
&lt;li&gt;If a router wants to send data to all devices in a network, it uses the 
broadcast MAC address (FF:FF:FF:FF:FF:FF).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;How MAC Addresses Work in a Network?&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
When a device wants to communicate, it follows these steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Step 1: The sender checks the MAC address of the destination using the ARP (Address Resolution Protocol).&lt;/li&gt;
&lt;li&gt;Step 2: The sender adds the MAC address to the data frame and sends it.&lt;/li&gt;
&lt;li&gt;Step 3: A network switch reads the MAC address and forwards the data to the correct device.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example:&lt;br&gt;
If your laptop sends a request to a printer in a LAN, the request contains the printer's MAC address, so the switch knows where to send the data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;MAC Address vs. IP Address – What's the Difference?&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
  &lt;tr&gt;
    &lt;th&gt;Feature&lt;/th&gt;
    &lt;th&gt;MAC Address&lt;/th&gt;
    &lt;th&gt;IP Address&lt;/th&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Definition&lt;/td&gt;
    &lt;td&gt;Unique hardware address of a device&lt;/td&gt;
    &lt;td&gt;Logical address assigned to a device&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Layer&lt;/td&gt;
    &lt;td&gt;Data Link Layer (Layer 2)&lt;/td&gt;
    &lt;td&gt;Network Layer (Layer 3)&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Type&lt;/td&gt;
    &lt;td&gt;Physical (cannot change)&lt;/td&gt;
    &lt;td&gt;Logical (can change)&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Used By&lt;/td&gt;
    &lt;td&gt;Switches&lt;/td&gt;
    &lt;td&gt;Routers&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Example&lt;/td&gt;
    &lt;td&gt;00:A0:C9:14:C8:29&lt;/td&gt;
    &lt;td&gt;192.168.1.1&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Analogy:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A MAC address is like a house address (permanent).&lt;/li&gt;
&lt;li&gt;An IP address is like a temporary hotel room number (can change).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To find your MAC address just open your command prompt type &lt;code&gt;ipconfig /all&lt;br&gt;
&lt;/code&gt; and press Enter. Look for "Physical Address" under your network adapter.&lt;/p&gt;




&lt;h3&gt;
  
  
  Framing in Data Link Layer
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;What is Framing?&lt;/strong&gt;&lt;br&gt;
Framing is the process of dividing a stream of data into small manageable units called frames for transmission over a network. Each frame contains both data and necessary control information (such as addresses and error detection codes) to ensure reliable communication.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why is Framing Needed?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The physical layer (Layer 1) only transmits raw bits (0s and 1s) without 
meaning.&lt;/li&gt;
&lt;li&gt;The data link layer (Layer 2) groups these bits into meaningful frames 
for error detection, synchronization, and addressing.&lt;/li&gt;
&lt;li&gt;It allows the receiver to correctly identify the start and end of each 
data unit.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example Analogy:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Imagine a long letter written without spaces or punctuation—it would be hard to read!&lt;/li&gt;
&lt;li&gt;Framing adds spaces, punctuation, and envelopes so that the receiver can properly understand each message.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Components of a Frame&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
Each frame consists of three main parts:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
  &lt;tr&gt;
    &lt;th&gt;Part&lt;/th&gt;
    &lt;th&gt;Purpose&lt;/th&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Header&lt;/td&gt;
    &lt;td&gt;Contains control information like source &amp;amp; destination MAC addresses&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Data&lt;/td&gt;
    &lt;td&gt;The actual payload (message) being transmitted&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Trailer&lt;/td&gt;
    &lt;td&gt;Contains error detection codes to ensure correct data transmission&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;

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

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Error Detection in Framing&lt;/u&gt;&lt;/strong&gt;&lt;br&gt;
The trailer of a frame includes an error detection code to ensure data integrity.&lt;/p&gt;

&lt;p&gt;Common Error Detection Techniques:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Parity Bit: Adds an extra bit to make the number of 1s either even or odd.&lt;/li&gt;
&lt;li&gt;Checksum: A sum of all data bits is added and verified at the receiver’s end.&lt;/li&gt;
&lt;li&gt;Cyclic Redundancy Check (CRC): A mathematical formula generates a check code, which is compared on both ends.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this blog, we explored the Data Link Layer, the backbone of network communication. We delved into key concepts like framing, MAC addressing, and random access protocols such as ALOHA, CSMA, CSMA/CA, and CSMA/CD. These mechanisms ensure efficient data transmission and collision avoidance, keeping networks connected and functional.&lt;/p&gt;

&lt;p&gt;In the next blog, we’ll dive into the Logical Link Control (LLC) sublayer, covering error detection, correction, and flow control. Let’s keep the conversation going! Connect with me on: &lt;a href="https://www.linkedin.com/in/singhaayush079/" rel="noopener noreferrer"&gt;Linkedin&lt;/a&gt; &amp;amp; &lt;a href="https://x.com/saayush615" rel="noopener noreferrer"&gt;X(formally twitter)&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>networking</category>
      <category>network</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Computer Networking 101: The Digital Superhighway Explained</title>
      <dc:creator>Aayush Singh</dc:creator>
      <pubDate>Sun, 02 Feb 2025 04:26:48 +0000</pubDate>
      <link>https://dev.to/singhaayush/computer-networking-101-the-digital-superhighway-explained-k1k</link>
      <guid>https://dev.to/singhaayush/computer-networking-101-the-digital-superhighway-explained-k1k</guid>
      <description>&lt;p&gt;Imagine the internet as a massive, interconnected highway system. Just like roads connect cities, towns, and homes, computer networks connect devices, allowing them to communicate and share information. This is the essence of computer networking—a digital superhighway that enables seamless communication across the globe. In this blog, we’ll break down the basics of computer networking, its goals, structure, and the technologies that make it all possible. Buckle up, and let’s hit the road!&lt;/p&gt;




&lt;h2&gt;
  
  
  What is Computer Network?
&lt;/h2&gt;

&lt;p&gt;Computer networking is a telecommunication network that allows autonomous digital devices(nodes), to exchange data between each other using either wired or wireless connections, to share resources interconnected by a single technology, e.g. the Internet. Think of it as a postal system: devices (like your laptop or smartphone) are like houses, and the network is the postal service that delivers messages (data) between them.&lt;/p&gt;




&lt;h2&gt;
  
  
  Goals and Applications of Computer Networking
&lt;/h2&gt;

&lt;p&gt;Why do we need computer networks? Here are the primary goals and applications:&lt;/p&gt;

&lt;p&gt;1.&lt;strong&gt;Resource Sharing&lt;/strong&gt;: Networks allow devices to share resources like printers, files, and internet connections.&lt;/p&gt;

&lt;p&gt;2.&lt;strong&gt;Communication&lt;/strong&gt;: Networks enable real-time communication through emails, video calls, and messaging apps.&lt;/p&gt;

&lt;p&gt;3.&lt;strong&gt;Data Storage and Access&lt;/strong&gt;: Networks provide access to centralized data storage systems like cloud services.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Example: Google Drive lets you store and access files from anywhere.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;4.&lt;strong&gt;Scalability and Flexibility&lt;/strong&gt;: Networks allow businesses to grow and adapt by adding new devices and users easily.&lt;/p&gt;




&lt;h2&gt;
  
  
  Data communication
&lt;/h2&gt;

&lt;p&gt;Data communication system has 5 components:&lt;br&gt;
1.&lt;strong&gt;Message&lt;/strong&gt; -&amp;gt; Information(data) to be communicated e.g. text,audio.&lt;br&gt;
2.&lt;strong&gt;Sender&lt;/strong&gt; -&amp;gt; device which sends message.&lt;br&gt;
3.&lt;strong&gt;Receiver&lt;/strong&gt; -&amp;gt; device which receives message.&lt;br&gt;
4.&lt;strong&gt;Transmission medium&lt;/strong&gt; -&amp;gt; is the physical path by which message travel from sender to receiver.&lt;br&gt;
5.&lt;strong&gt;Protocol&lt;/strong&gt; -&amp;gt;  set of rules and guidelines for communicating data between devices.&lt;/p&gt;

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




&lt;h2&gt;
  
  
  Transmission Mode
&lt;/h2&gt;

&lt;p&gt;When data travels across a network, it doesn’t just move in one fixed way. The transmission mode determines the direction and flow of data between devices. Think of it as the rules of the road for data traffic—whether it’s a one-way street, a two-way street, or a multi-lane highway. Let’s explore the three main types of transmission modes:&lt;br&gt;
1.&lt;strong&gt;Simplex Mode&lt;/strong&gt; : In simplex mode, data flows in only one direction—like a one-way street. One device sends data, and the other can only receive it. There’s no way for the receiver to send data back. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;for example:  A radio broadcast. The radio station sends out signals, and your radio can only receive them. You can’t send a message back to the station.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;2.&lt;strong&gt;Half-Duplex Mode&lt;/strong&gt; : In half-duplex mode, data can flow in both directions, but not at the same time. It’s like a narrow bridge where cars must take turns to cross.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;for example: Walkie-talkies. You can talk or listen, but you can’t do both at the same time. You say “Over” to signal the other person to respond.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;3.&lt;strong&gt;Full-Duplex Mode&lt;/strong&gt; : In full-duplex mode, data can flow in both directions simultaneously. It’s like a multi-lane highway where cars can travel in both directions at the same time without interfering with each other.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Example: Modern Ethernet networks, Wi-Fi, and cellular networks.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Network criteria
&lt;/h2&gt;

&lt;p&gt;A network must be able to meet a certain number of criteria. The most important of these are:&lt;br&gt;
1.&lt;strong&gt;Delivery &amp;amp; Accuracy&lt;/strong&gt; - Must deliver the data to correct destination without any error.&lt;/p&gt;

&lt;p&gt;2.&lt;strong&gt;Performance&lt;/strong&gt; - Can be measured in many ways including transit time,response time,number of users,types of transmission medium,capability of connecting hardware's and efficiency of software.&lt;/p&gt;

&lt;p&gt;3.&lt;strong&gt;Reliability&lt;/strong&gt; - Is a measure of frequency of failure and the time taken to resolve from the failure.&lt;/p&gt;

&lt;p&gt;4.&lt;strong&gt;Security&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Types of connection
&lt;/h2&gt;

&lt;p&gt;1.&lt;strong&gt;Point-to-point&lt;/strong&gt; - A point-to-point connection provides a dedicated link between two devices.&lt;br&gt;
2.&lt;strong&gt;Multipoint&lt;/strong&gt; - A multipoint connection is one in which more than two specific devices share a single link.&lt;/p&gt;




&lt;h2&gt;
  
  
  Network Topology
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Mesh Topology: Every device is connected to every other device in the network. It’s like a spider web, where each strand is a direct connection.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Example: Military networks or critical infrastructure systems where reliability is paramount.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Star Topology: All devices connect to a central hub.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Example: Home Wi-Fi networks.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Bus Topology: Devices are connected in a single line.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Example: Older Ethernet networks.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Ring Topology: Devices are connected in a circular loop.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Example: Token Ring networks.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Hybrid Topology: A hybrid topology combines two or more different topologies to create a customized network.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Example: A large office might use a star topology for individual departments and connect them using a bus topology.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ul&gt;

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




&lt;h2&gt;
  
  
  Network Structure and Architecture
&lt;/h2&gt;

&lt;p&gt;Networks are built using a combination of hardware (like routers and cables) and software (like protocols). The structure of a network can vary depending on its size and purpose:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Local Area Network (LAN): A small network covering a single building or home.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Example: Your home Wi-Fi network.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Wide Area Network (WAN): A large network that spans cities, countries, or even continents.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Example: The internet.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Metropolitan Area Network (MAN): A network that covers a city or campus.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Example: A university’s network connecting multiple buildings.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  The OSI Reference Model: The 7-Layer Highway
&lt;/h2&gt;

&lt;p&gt;The OSI (Open Systems Interconnection) model is a framework that explains how data travels across a network. It’s divided into seven layers, each with a specific role. Think of it as a multi-layered highway system:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Physical Layer (Layer 1): The actual road—cables, switches, and signals.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Example: Ethernet cables or Wi-Fi signals.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Data Link Layer (Layer 2): Ensures data is transferred reliably between devices on the same network.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Example: MAC addresses used in Ethernet.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Network Layer (Layer 3): Routes data between different networks.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Example: IP addresses and routers.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Transport Layer (Layer 4): Ensures data arrives error-free and in the correct order.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Example: TCP (Transmission Control Protocol).&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Session Layer (Layer 5): Manages connections between devices.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Example: Establishing a Zoom call.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Presentation Layer (Layer 6): Translates data into a readable format.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Example: Encryption or file compression.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Application Layer (Layer 7): The interface between users and the network.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Example: Web browsers (Chrome, Firefox) or email clients (Outlook, Gmail).&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ul&gt;

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




&lt;h2&gt;
  
  
  Physical Layer and Transmission Media
&lt;/h2&gt;

&lt;p&gt;The physical layer deals with the actual transmission of data. Common transmission media include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Wired Media: Ethernet cables(Coaxial Cables,Twisted Pair Cables,Fiber optic Cables).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Wireless Media: Wi-Fi, Bluetooth, cellular networks.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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




&lt;h2&gt;
  
  
  Switching Methods
&lt;/h2&gt;

&lt;p&gt;Switching determines how data is forwarded across the network:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Circuit Switching: Dedicated path for the entire communication.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Example: Traditional phone calls.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Packet Switching: Data is broken into packets and sent independently.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Example: Internet data transfer.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Computer networking is the backbone of our digital world, enabling communication, resource sharing, and access to information. By understanding the basics—like the OSI model, network topologies, and transmission media—you can appreciate the complexity and beauty of this digital superhighway. Whether you’re sending an email, streaming a movie, or browsing the web, you’re riding on this incredible network. So next time you connect to Wi-Fi, remember: you’re not just online—you’re on the digital superhighway!&lt;/p&gt;

&lt;p&gt;But this is just the beginning! In the next blog of this series, we’ll dive deeper into the Data Link Layer.Make sure to follow me on &lt;a href="https://www.linkedin.com/in/singhaayush079/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;and &lt;a href="https://x.com/saayush615" rel="noopener noreferrer"&gt;X (formerly Twitter)&lt;/a&gt; to stay updated with the latest posts, tips, and insights&lt;/p&gt;

</description>
      <category>network</category>
      <category>networking</category>
      <category>beginners</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>Leveling Up in Git and GitHub: A Guide to Remotes, Pull Requests, and Beyond</title>
      <dc:creator>Aayush Singh</dc:creator>
      <pubDate>Tue, 07 Jan 2025 17:26:37 +0000</pubDate>
      <link>https://dev.to/singhaayush/leveling-up-in-git-and-github-a-guide-to-remotes-pull-requests-and-beyond-2bio</link>
      <guid>https://dev.to/singhaayush/leveling-up-in-git-and-github-a-guide-to-remotes-pull-requests-and-beyond-2bio</guid>
      <description>&lt;p&gt;This blog continues from my previous one. It is helpful to have a basic understanding of Git before proceeding.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Working with Remote Repositories&lt;/strong&gt;(GITHUB)
&lt;/h2&gt;

&lt;p&gt;Remote repositories are hosted versions of your local Git repository that allow multiple developers to collaborate on a project. GitHub is a popular platform for hosting such repositories. Let’s break down this topic with detailed explanations and examples.&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting Up a Remote Repository
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1.Create a Repository on GitHub&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Log in to GitHub and click the "+" button in the top-right corner.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;Select "New Repository."&lt;/li&gt;
&lt;li&gt;Name your repository (e.g., my-project) and choose whether it’s public or private.&lt;/li&gt;
&lt;li&gt;Click Create Repository.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;&lt;strong&gt;Optional step:&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;git branch -M main&lt;/code&gt; : This command will rename your local branch from master to main, which is now more preferred..&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.Link Your Local Repository to the Remote Repository&lt;/strong&gt;&lt;br&gt;
Command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git remote add origin &amp;lt;repository-URL&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Replace &lt;code&gt;&amp;lt;repository-URL&amp;gt;&lt;/code&gt; with the HTTPS or SSH link from GitHub.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;3.Verify the Remote Link&lt;/strong&gt;&lt;br&gt;
Command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git remote &lt;span class="nt"&gt;-v&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;origin  https://github.com/username/my-project.git &lt;span class="o"&gt;(&lt;/span&gt;fetch&lt;span class="o"&gt;)&lt;/span&gt;
origin  https://github.com/username/my-project.git &lt;span class="o"&gt;(&lt;/span&gt;push&lt;span class="o"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Pushing Changes to the Remote Repository
&lt;/h3&gt;

&lt;p&gt;Pushing uploads your local commits to the remote repository.&lt;br&gt;
Command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git push origin &amp;lt;branch-name&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If it’s your first time pushing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git push &lt;span class="nt"&gt;-u&lt;/span&gt; origin &amp;lt;branch-name&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command sets the default remote branch for future pushes. By including this, the specified branch becomes the default, allowing you to push and pull from your remote repository simply using &lt;code&gt;git push&lt;/code&gt; and &lt;code&gt;git pull&lt;/code&gt;. Without this setting, you would need to specify the branch name every time you push or pull.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cloning a Remote Repository
&lt;/h3&gt;

&lt;p&gt;Cloning creates a copy of an existing repository on your local machine.&lt;br&gt;
Command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone &amp;lt;repository-URL&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;you can get &lt;code&gt;&amp;lt;repository-URL&amp;gt;&lt;/code&gt; by going on your repo and clicking Code button.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmxedj6luiq121ab6qs8t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmxedj6luiq121ab6qs8t.png" alt="repository-URL" width="660" height="243"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Fetching remote repo
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;git fetch&lt;/code&gt; downloads the latest commits, branches, and tags from a remote repository but does not merge them into your local branch. It’s like “checking what’s new” without changing your work.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git fetch

&lt;span class="c"&gt;# Fetching changes from origin main into your local main&lt;/span&gt;
git fetch origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Merge remote repo
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;git merge&lt;/code&gt; integrates changes from one branch into another. You use it after fetching to bring remote updates into your local branch.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#1. Merge remote main&lt;/span&gt;
git fetch origin main
git merge origin/main

&lt;span class="c"&gt;# 2. Merge local main branch into feature&lt;/span&gt;
git checkout feature
git merge main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Pulling remote repo
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;git pull&lt;/code&gt; is a shortcut for &lt;strong&gt;fetch + merge&lt;/strong&gt;. It fetches the latest changes from the remote and then automatically merges them into your current branch.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git pull

&lt;span class="c"&gt;# Pull changes from origin main directly into your local main&lt;/span&gt;
git pull origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;This ensures your local branch is up-to-date with the remote branch.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Resolving Merge Conflicts
&lt;/h3&gt;

&lt;p&gt;A merge conflict occurs when two branches (or local and remote repositories) modify the same part of a file.&lt;/p&gt;

&lt;p&gt;Steps to Resolve:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Git identifies the conflicting file(s).&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Open the file(s) and look for conflict markers like:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&lt;/span&gt;&amp;lt; HEAD
Your changes here
&lt;span class="o"&gt;=======&lt;/span&gt;
Changes from the remote branch
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; branch-name

&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Edit the file to keep the desired changes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Stage the resolved file: &lt;code&gt;git add &amp;lt;file&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Commit the changes: &lt;code&gt;git commit&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Collaboration in GitHub&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;GitHub is a powerful platform for team collaboration. Here's how it helps developers work together effectively:&lt;/p&gt;

&lt;h3&gt;
  
  
  1 Forking a Repository
&lt;/h3&gt;

&lt;p&gt;Forking creates a personal copy of someone else's repository on your GitHub account.&lt;/p&gt;

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

&lt;p&gt;STEPS:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Click the Fork button on the repository's GitHub page.&lt;/li&gt;
&lt;li&gt;Your forked copy will appear in your GitHub account.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  2 Pull Requests
&lt;/h3&gt;

&lt;p&gt;A pull request (PR) is a request to merge your changes (usually in a feature branch of your forked repository) into the original repository.Lets others review, discuss, and merge your changes into the main project.&lt;/p&gt;

&lt;p&gt;STEPS:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Push your changes to your forked repository.&lt;/li&gt;
&lt;li&gt;Click New Pull Request on the original repository's page.&lt;/li&gt;
&lt;li&gt;Compare your changes and describe them before submitting.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  3 Reviewing Code
&lt;/h3&gt;

&lt;p&gt;Reviewing code involves examining PRs for correctness, style, and quality before merging.Ensures that the codebase remains high quality and free of errors.&lt;br&gt;
Key Actions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add comments.&lt;/li&gt;
&lt;li&gt;Approve the PR.&lt;/li&gt;
&lt;li&gt;Request changes if needed.&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  &lt;strong&gt;Step-by-Step Workflow to contribute to an original project&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;0 Create a issue or find the issue to solve by going in Issue tab&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn5qfiwg18s9h9iqj33x5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn5qfiwg18s9h9iqj33x5.png" alt="issue" width="800" height="196"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1 Fork the Original Repository, by clicking fork button&lt;/strong&gt;&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;2 Clone Your Forked Repository&lt;/strong&gt;&lt;br&gt;
Clone your fork to your local machine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/your-username/forked-repo.git

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Navigate into the project directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;forked-repo

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3 Set the Original Repository as an Upstream&lt;/strong&gt;&lt;br&gt;
This ensures you can sync your fork with the original repository.&lt;br&gt;
Add the original repository as an upstream remote:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git remote add upstream https://github.com/original-owner/original-repo.git

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check the remotes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git remote &lt;span class="nt"&gt;-v&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;origin   https://github.com/your-username/forked-repo.git &lt;span class="o"&gt;(&lt;/span&gt;fetch&lt;span class="o"&gt;)&lt;/span&gt;
upstream https://github.com/original-owner/original-repo.git &lt;span class="o"&gt;(&lt;/span&gt;fetch&lt;span class="o"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4 Create a Feature Branch&lt;/strong&gt;&lt;br&gt;
Before making changes, create a new branch for every issue. Branches should be named like feat/abc, fix/abc . &lt;em&gt;Always remember&lt;/em&gt; create any branch from main branch only:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout &lt;span class="nt"&gt;-b&lt;/span&gt; feature-branch

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Make your changes, test them, and commit them:&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add &lt;span class="nb"&gt;.&lt;/span&gt;
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Add feature X"&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5 Sync with the Original Repository (if needed)&lt;/strong&gt;&lt;br&gt;
Before creating a pull request (PR), ensure your fork is up-to-date with the original repository.&lt;/p&gt;

&lt;p&gt;Pull changes from the original repository set as upstream:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;main
git pull upstream main

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;merge local up-to-date repo to update remote(origin) repo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git push origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now merge this local main branch with feature-branch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout feature-branch
git merge main

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Now your feature branch is up-to-date. if there any merge conflict resolve it and commit them.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;6 Push Changes to Your Forked Repository&lt;/strong&gt;&lt;br&gt;
Push the feature branch to your forked repository:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git push origin feature-branch

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;7 Create a Pull Request (PR)&lt;/strong&gt;&lt;br&gt;
On GitHub:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to your forked repository.&lt;/li&gt;
&lt;li&gt;Switch to the feature-branch.&lt;/li&gt;
&lt;li&gt;Click Compare &amp;amp; pull request.&lt;/li&gt;
&lt;li&gt;Write a descriptive title and summary for your changes.&lt;em&gt;Remeber to add fixes #issueid in your PR description&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Submit the PR to the original repository's main branch.&lt;/li&gt;
&lt;li&gt;Stay clam, and do all the necessary changes told to you by maintainers and push them too. &lt;/li&gt;
&lt;li&gt;After your branch is successfully merged, you can delete that feature-branch.&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  &lt;strong&gt;Managing Issues and Projects&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;GitHub provides tools for tracking bugs, features, and tasks.&lt;br&gt;
&lt;strong&gt;1 Issues&lt;/strong&gt;&lt;br&gt;
Issues are GitHub’s way of tracking bugs, feature requests, or tasks.Centralized discussion for solving problems.Think of issues as sticky notes on a whiteboard, each representing something that needs attention.&lt;br&gt;
Steps to Create an Issue:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to the Issues tab in the repository.&lt;/li&gt;
&lt;li&gt;Click New Issue.&lt;/li&gt;
&lt;li&gt;Describe the problem or request.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2 Labels&lt;/strong&gt;&lt;br&gt;
Labels categorize issues (e.g., "bug," "enhancement").Labels are like tags you put on your sticky notes to organize them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3 Milestones&lt;/strong&gt;&lt;br&gt;
Milestones group related issues to track progress toward a specific goal.Like grouping sticky notes for a project deadline.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4 GitHub Projects&lt;/strong&gt;&lt;br&gt;
A project board organizes issues and pull requests into a visual workflow.Like a Kanban board with columns for "To Do," "In Progress," and "Done."&lt;/p&gt;

&lt;p&gt;Doing this much is enough for beginner for now to get started. now I will discuss about some advance concept if you came till here, I will encourage you to read and try to understand basics of this advance concept&lt;/p&gt;


&lt;h2&gt;
  
  
  &lt;strong&gt;Advanced Git Concepts&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1 Rebasing&lt;/strong&gt;&lt;br&gt;
Rebasing rewrites commit history to create a linear sequence of commits.Imagine organizing your shuffled photo album into chronological order.&lt;br&gt;
command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git rebase &amp;lt;branch-name&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2 Cherry-Picking&lt;/strong&gt;&lt;br&gt;
Apply a specific commit from one branch to another.Like copying a single page from one book into another.&lt;br&gt;
command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git cherry-pick &amp;lt;commit-hash&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3 Stashing&lt;/strong&gt;&lt;br&gt;
Temporarily saves uncommitted changes to a stack.Like putting your work on hold and tucking it into a drawer.&lt;code&gt;git stash&lt;/code&gt; is like moving changes to backstage and calling it to the untracked area with &lt;code&gt;git stash pop&lt;/code&gt; or deleting backstage data with &lt;code&gt;git stash clear&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git stash
git stash apply

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;Working with CI/CD Pipelines&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What is CI/CD?&lt;/strong&gt;&lt;br&gt;
Continuous Integration (CI) ensures code changes are tested automatically, and Continuous Deployment (CD) automates code deployment. Like a factory assembly line that builds, tests, and ships products automatically.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GitHub Actions&lt;/strong&gt;&lt;br&gt;
GitHub’s built-in CI/CD tool for automating workflows.Like a robot that handles repetitive tasks for you.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;GitHub Features&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1 GitHub Pages&lt;/strong&gt; &lt;br&gt;
Host a static website directly from a GitHub repository. Use it for a portfolio or project demo.&lt;br&gt;
Steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to the repository settings.&lt;/li&gt;
&lt;li&gt;Enable GitHub Pages under the Pages section.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2 Insights and Analytics&lt;/strong&gt;&lt;br&gt;
View contributor stats, commit history, and activity graphs.Helps understand how a project evolves and who contributes the most.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3 GitHub Discussions&lt;/strong&gt;&lt;br&gt;
A forum-like feature for open-ended discussions.For brainstorming or getting help without creating issues.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4 Security Features&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dependabot Alerts: Scans for vulnerabilities in dependencies.&lt;/li&gt;
&lt;li&gt;Code Scanning: Detects security issues in your code.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Thank you for reading this blog till the end! I hope it gave you a clear understanding of Git and GitHub, from the basics to essential commands, collaboration, and exploring GitHub’s powerful features. With these skills, you’re now well-equipped to start contributing to projects, managing your own repositories, and collaborating effectively with others. 🚀&lt;/p&gt;

&lt;p&gt;What can you do now?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Begin experimenting with Git commands and workflows in your own 
projects.&lt;/li&gt;
&lt;li&gt;Contribute to an open-source project to solidify your learning.&lt;/li&gt;
&lt;li&gt;Explore GitHub’s advanced features like GitHub Actions or Pages to level 
up your skills.
If you found this blog helpful, let’s connect! You can follow me on &lt;a href="https://x.com/saayush615" rel="noopener noreferrer"&gt;X (formally twitter)&lt;/a&gt; and &lt;a href="https://www.linkedin.com/in/saayush615" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; to stay updated with my journey and future blogs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Stay tuned for my next blog, where I’ll dive deeper into diffrent topics. Until then, happy coding! 😊&lt;/p&gt;

</description>
      <category>git</category>
      <category>github</category>
      <category>beginners</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Getting Started with Git and GitHub: A Beginner's Guide</title>
      <dc:creator>Aayush Singh</dc:creator>
      <pubDate>Sat, 04 Jan 2025 10:48:52 +0000</pubDate>
      <link>https://dev.to/singhaayush/getting-started-with-git-and-github-a-beginners-guide-5emi</link>
      <guid>https://dev.to/singhaayush/getting-started-with-git-and-github-a-beginners-guide-5emi</guid>
      <description>&lt;h2&gt;
  
  
  Basics of Git
&lt;/h2&gt;

&lt;p&gt;Git is a tool that helps developers track changes in their code. It’s like a time machine for your project, allowing you to see what changed, when, and by whom.&lt;/p&gt;

&lt;h3&gt;
  
  
  what is Git and why it is used?
&lt;/h3&gt;

&lt;p&gt;Git is a version control system that helps you manage changes to files in your project over time. Imagine writing a book, Git is like a notebook where you record every change you make to your draft. If you mess up, you can look back at your notes and restore an earlier version of the book.&lt;br&gt;
It is used to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;save versions of your work&lt;/li&gt;
&lt;li&gt;collaborate with others&lt;/li&gt;
&lt;li&gt;keep track of changes without losing anything&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now after you have understood what Git is Now lets install Git.&lt;/p&gt;
&lt;h3&gt;
  
  
  Installing and configuring Git
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Install Git on your system by downloading it from: &lt;a href="https://git-scm.com/downloads" rel="noopener noreferrer"&gt;git-scm.com&lt;/a&gt;. follow the instructions provided on the official website to: &lt;a href="https://git-scm.com/book/en/v2/Getting-Started-Installing-Git" rel="noopener noreferrer"&gt;Install Git&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After Installing open Git Bash. as shown in below image&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;Then configure your name using the command:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; user.name &lt;span class="s2"&gt;"Your Name"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Finally configure your email with:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; user.email &lt;span class="s2"&gt;"your-email@example.com"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Now you have saved you name and email.lets verify everything using below command:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; &lt;span class="nt"&gt;--list&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Before starting with git commands. let's first understand some terminology related to git&lt;/p&gt;
&lt;h3&gt;
  
  
  Git Terminology
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Repository (Repo)&lt;/strong&gt; : A repository is where Git stores all your project files and their version history.Think of a repository as a folder where you keep your project. Git keeps a hidden "diary" in that folder, recording everything you do.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Working Directory&lt;/strong&gt; : The working directory is the folder where you’re actively working on your files.It’s like your desk where you spread out your papers to edit.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Staging Area&lt;/strong&gt; : The staging area is where you prepare files before saving them in Git’s history. Imagine a box(staging area) where you gather paper(files) to click a photo (commit).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;commit&lt;/strong&gt; : A commit is a snapshot of your project at a specific point in time.Imagine taking a photo of your desk. A commit freezes the current state of your work so you can always look back at it later.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Branch&lt;/strong&gt; : A branch is a separate line of development in your project.It’s like working on a copy of your book while keeping the original safe. Once you’re done, you can merge the changes back into the main book.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Merge&lt;/strong&gt; : Merging combines changes from one branch into another.If two people write different chapters of a book, merging is putting those chapters together into one final draft.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;HEAD&lt;/strong&gt; : HEAD is the pointer to your current commit or branch.HEAD is like a bookmark showing where you are in your project history.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now you are done with Git basics let's dive into Git commands.&lt;/p&gt;


&lt;h2&gt;
  
  
  Essential Git Commands
&lt;/h2&gt;

&lt;p&gt;These are the basic command that you will encounter daily. so Let's start:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;git init&lt;/strong&gt; : This initializes a new Git repository in your project folder, allowing Git to track changes.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;blockquote&gt;
&lt;p&gt;This creates a hidden .git folder in your project directory, setting up Git for version control.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;git add&lt;/strong&gt; : This command moves changes (modified or new files) from the working directory to the staging area.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add file1.txt &lt;span class="c"&gt;# Add file1.txt to staging area&lt;/span&gt;
git add &lt;span class="nb"&gt;.&lt;/span&gt;  &lt;span class="c"&gt;# Adds all changes in the current folder&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;blockquote&gt;
&lt;p&gt;This prepares files for committing.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;git commit&lt;/strong&gt; : This saves the changes in the staging area as a snapshot in Git's history. Each commit has a unique ID and message to describe the changes.It’s like taking a photograph of your project at a specific moment.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Added a new feature to the homepage"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;git status&lt;/strong&gt; : This command shows the current state of the working directory and staging area. It tells you what changes have been staged, what changes are not staged, and which files are untracked.
Example:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git status

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;On branch main
Untracked files:
  &lt;span class="o"&gt;(&lt;/span&gt;use &lt;span class="s2"&gt;"git add &amp;lt;file&amp;gt;..."&lt;/span&gt; to include &lt;span class="k"&gt;in &lt;/span&gt;what will be committed&lt;span class="o"&gt;)&lt;/span&gt;
        file1.txt
Changes to be committed:
  &lt;span class="o"&gt;(&lt;/span&gt;use &lt;span class="s2"&gt;"git restore --staged &amp;lt;file&amp;gt;..."&lt;/span&gt; to unstage&lt;span class="o"&gt;)&lt;/span&gt;
        new file:   file2.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;git log&lt;/strong&gt; : This command displays the history of commits in your repository, showing the commit hash, author, date, and message.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git log

&lt;span class="c"&gt;# or&lt;/span&gt;

git log &lt;span class="nt"&gt;--oneline&lt;/span&gt; &lt;span class="c"&gt;# for single line response&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Git Diff&lt;/strong&gt; : &lt;code&gt;git diff&lt;/code&gt; is used to see the differences in your code. It helps you compare changes between your working directory, staging area, commits, or even branches. This is especially useful before committing or merging code.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Show changes in working directory that are not staged&lt;/span&gt;
git diff

&lt;span class="c"&gt;# Show changes that have been staged (ready for commit)&lt;/span&gt;
git diff &lt;span class="nt"&gt;--staged&lt;/span&gt;

&lt;span class="c"&gt;# Compare two commits using their hash IDs&lt;/span&gt;
git diff &amp;lt;hashid1&amp;gt; &amp;lt;hashid2&amp;gt;
&lt;span class="c"&gt;# You can get commit hash IDs using: git log --oneline&lt;/span&gt;

&lt;span class="c"&gt;# Compare differences between two branches&lt;/span&gt;
git diff branchone..branchtwo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Use git diff to review changes and ensure you’re committing exactly what you want.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Working with Branches
&lt;/h2&gt;

&lt;p&gt;A branch in Git is like a separate line of development. It allows you to work on new features, fix bugs, or experiment without affecting the main code.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a Branch:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git branch feature-branch

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Creates a new branch called feature-branch.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Switch to a Branch:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout feature-branch

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Switches to the branch feature-branch.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;OR &lt;br&gt;
(modern way):&lt;/p&gt;


&lt;pre class="highlight shell"&gt;&lt;code&gt;git switch feature-branch

&lt;/code&gt;&lt;/pre&gt;

&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Create and Switch to a Branch (Shortcut):
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout &lt;span class="nt"&gt;-b&lt;/span&gt; feature-branch

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;List All Branches:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git branch

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Shows all branches in the repository. The current branch is marked with *.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Merge a Branch:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git merge feature-branch

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Combines changes from feature-branch into the current branch.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Delete a Branch:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git branch &lt;span class="nt"&gt;-d&lt;/span&gt; feature-branch

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Deletes feature-branch after it’s merged.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Imagine you’re writing a book. The main branch (main) is your final version. When you want to write a new chapter, you make a photocopy (a branch). You work on this copy separately. Once done, you add the new chapter to the main book (merge the branch).&lt;/p&gt;

&lt;p&gt;Remember: Depending on your PC environment, your local repository may have a default branch named either main or master. In this guide, we'll use main as the default branch name, aligning with GitHub's recent change from master to main.&lt;/p&gt;




&lt;h2&gt;
  
  
  Understanding Git Stashing
&lt;/h2&gt;

&lt;p&gt;When working with Git, there are times when you’re in the middle of changes but need to switch branches, pull new code, or experiment without committing incomplete work. This is where &lt;strong&gt;Git Stash&lt;/strong&gt; comes in handy.  &lt;/p&gt;

&lt;p&gt;Stashing lets you temporarily "shelve" (or stash) changes in your working directory so you can work on something else, and then come back later to reapply them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Common Git Stash Commands
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. &lt;code&gt;git stash&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
This command saves your uncommitted changes (both staged and unstaged) into a new stash entry and reverts your working directory to match the last commit.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git stash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Think of it as "hiding" your work temporarily.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;2. &lt;code&gt;git stash pop&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This command reapplies the most recently stashed changes and then removes them from the stash list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git stash pop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Use this when you want to get your changes back and don’t need to keep the stash for later.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;3. &lt;code&gt;git stash list&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Displays all stashes you have saved. Each stash will be shown with an index like &lt;code&gt;stash@{0}&lt;/code&gt;, &lt;code&gt;stash@{1}&lt;/code&gt;, etc.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git stash list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Helpful when you have multiple stashes saved.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;4. &lt;code&gt;git stash apply&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This reapplies the most recent stash (or a specific one if you provide an identifier) &lt;strong&gt;without deleting it&lt;/strong&gt; from the stash list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Apply the most recent stash&lt;/span&gt;
git stash apply

&lt;span class="c"&gt;# Apply a specific stash by index&lt;/span&gt;
git stash apply stash@&lt;span class="o"&gt;{&lt;/span&gt;2&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;# Apply a stash by commit hash ID&lt;/span&gt;
git stash apply &amp;lt;hashid&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Use this if you want to reapply changes but still keep a copy in the stash.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;5. &lt;code&gt;git stash show&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Shows a summary of the changes in the most recent stash. Use &lt;code&gt;-p&lt;/code&gt; (patch) to see the full diff.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git stash show
git stash show &lt;span class="nt"&gt;-p&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6. &lt;code&gt;git stash drop&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Deletes a specific stash entry (default is the latest one).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git stash drop stash@&lt;span class="o"&gt;{&lt;/span&gt;0&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Useful if you don’t need a particular stash anymore.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;7. &lt;code&gt;git stash clear&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Removes &lt;strong&gt;all&lt;/strong&gt; stashes from the list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git stash clear
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Be careful — once cleared, you cannot recover them.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Example Workflow&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You’re working on a feature but need to quickly fix a bug on another
branch:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  git stash
  git checkout main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;After fixing the bug, you come back and reapply your feature work:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  git checkout feature-branch
  git stash pop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Undoing Changes in Git
&lt;/h2&gt;

&lt;p&gt;Mistakes happen, and Git makes it easy to undo changes at different stages. Let’s explore common scenarios with examples and outputs.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Undo Changes in the Working Directory&lt;/strong&gt; (git checkout or git restore)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you’ve made changes to a file but haven’t staged it yet, you can discard those changes.&lt;br&gt;
command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git restore &amp;lt;file&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example:&lt;br&gt;
Suppose you edited &lt;em&gt;index.html&lt;/em&gt; but don’t want the changes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git restore index.html

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
The file index.html is restored to the last committed version. Changes are discarded.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Unstage Changes&lt;/strong&gt; (git restore --staged)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you’ve staged a file using git add but want to remove it from the staging area without deleting changes:&lt;/p&gt;

&lt;p&gt;command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git restore &lt;span class="nt"&gt;--staged&lt;/span&gt; &amp;lt;file&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example:&lt;br&gt;
You staged style.css but realize it’s not ready to commit.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git restore &lt;span class="nt"&gt;--staged&lt;/span&gt; style.css
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;The file is moved back to the working directory, and git status will now show it as modified but not staged.&lt;/p&gt;

&lt;p&gt;Note: If this command does not work in your device use &lt;code&gt;git rm --cached &amp;lt;file&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Undo a Commit&lt;/strong&gt; (git reset)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;a. Undo the Last Commit (Keep Changes in Working Directory):&lt;/p&gt;

&lt;p&gt;Command:&lt;/p&gt;

&lt;p&gt;You committed too early and want to redo it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git reset &lt;span class="nt"&gt;--soft&lt;/span&gt; HEAD~1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;The last commit is undone, but &lt;em&gt;changes remain in the staging area&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;b. Undo the Last Commit (Unstage and Keep Changes):&lt;/p&gt;

&lt;p&gt;Command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git reset &lt;span class="nt"&gt;--mixed&lt;/span&gt; HEAD~1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
The last commit is undone, changes are unstaged, and files are moved to the working directory.&lt;/p&gt;

&lt;p&gt;c. Undo the Last Commit (Delete Changes):&lt;/p&gt;

&lt;p&gt;Command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git reset &lt;span class="nt"&gt;--hard&lt;/span&gt; HEAD~1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example:&lt;br&gt;
You committed unwanted changes and want to completely discard them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git reset &lt;span class="nt"&gt;--hard&lt;/span&gt; HEAD~1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
The last commit is undone, and changes are permanently deleted.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; &lt;strong&gt;Undo Changes in a Specific Commit&lt;/strong&gt; (git revert)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Instead of deleting a commit, this creates a new commit that undoes the changes.&lt;br&gt;
Command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git revert &amp;lt;commit-hash&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example:&lt;br&gt;
To undo changes in commit abc123:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git revert abc123
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Discard Untracked Files&lt;/strong&gt; (git clean)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Untracked file are the files you haven’t added to the staging area using git add. . &lt;br&gt;
If you’ve added new files but don’t want to keep them:&lt;br&gt;
command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clean &lt;span class="nt"&gt;-f&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example:&lt;br&gt;
You created a file temp.txt but don’t need it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clean &lt;span class="nt"&gt;-f&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
The untracked file temp.txt is deleted.&lt;br&gt;
Note:  git clean -f command will delete all untracked files in your working directory. Here,  -f flag is required to confirm you want to delete the files(Force Deletion).&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Important Tip:&lt;br&gt;
Dry Run Before Cleaning: To see which files will be deleted without actually deleting them, use git clean -n.&lt;/p&gt;


&lt;pre class="highlight shell"&gt;&lt;code&gt;git clean &lt;span class="nt"&gt;-n&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Summary Table:
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
  &lt;tr&gt;
    &lt;th&gt;Action&lt;/th&gt;
    &lt;th&gt;Command&lt;/th&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Undo changes in a file&lt;/td&gt;
    &lt;td&gt;git restore &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Unstage changes&lt;/td&gt;
    &lt;td&gt;git restore --staged &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Undo last commit (soft)&lt;/td&gt;
    &lt;td&gt;git reset --soft HEAD~1&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Undo last commit (hard)&lt;/td&gt;
    &lt;td&gt;git reset --hard HEAD~1&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Undo a specific commit&lt;/td&gt;
    &lt;td&gt;git revert &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Discard untracked files&lt;/td&gt;
    &lt;td&gt;git clean -f&lt;/td&gt;
  &lt;/tr&gt;

&lt;/table&gt;&lt;/div&gt;




&lt;p&gt;Git is an essential tool for managing code efficiently, and in this blog, we’ve covered the foundational concepts and commands you need to get started. From initializing repositories to branching and undoing changes, these skills form the backbone of version control and will help you work confidently in your projects.&lt;/p&gt;

&lt;p&gt;Understanding these basics ensures you can track your progress, experiment without fear, and fix mistakes when things don’t go as planned. The remaining topics, such as working with remote repositories (GitHub), collaboration workflows, and advanced features, will be covered in my next blog. Stay tuned for more!&lt;/p&gt;

&lt;p&gt;If you found this blog helpful or have any suggestions, feel free to reach out to me. Let’s connect &lt;a href="https://x.com/saayush615" rel="noopener noreferrer"&gt;TWITTER&lt;/a&gt; &amp;amp; &lt;a href="https://www.linkedin.com/in/saayush615/" rel="noopener noreferrer"&gt;Linkedin&lt;/a&gt;. Your feedback and support mean a lot to me as I continue sharing my journey in the tech world. 😊&lt;/p&gt;

</description>
      <category>git</category>
      <category>github</category>
      <category>beginners</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Mastering Classes and Objects: Step-by-Step for Beginners</title>
      <dc:creator>Aayush Singh</dc:creator>
      <pubDate>Sun, 29 Dec 2024 02:52:58 +0000</pubDate>
      <link>https://dev.to/singhaayush/mastering-classes-and-objects-step-by-step-for-beginners-28i4</link>
      <guid>https://dev.to/singhaayush/mastering-classes-and-objects-step-by-step-for-beginners-28i4</guid>
      <description>&lt;h2&gt;
  
  
  Introduction to Classes and Objects
&lt;/h2&gt;

&lt;p&gt;In programming, a class is like a blueprint, and an object is like a house built from that blueprint. Think of a class as a plan that defines the structure and behavior of an object. An object, on the other hand, is a specific instance of that class that exists in memory. By using classes and objects, we can organize and reuse code effectively.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Car {
    String color;
    String model;
    void start() {
        System.out.println("Car is starting");
    }
}

public class Main {
    public static void main(String[] args) {
        Car myCar = new Car(); // Object created
        myCar.color = "Red";
        myCar.start();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the &lt;em&gt;Car _class is a blueprint, and _myCar&lt;/em&gt; is an object created from that blueprint.&lt;/p&gt;




&lt;h2&gt;
  
  
  Components of a Class
&lt;/h2&gt;

&lt;p&gt;A class is made up of several components. Let’s break them down:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Class Name&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The class name is used to identify the class. It should follow naming &lt;br&gt;
  conventions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start with an uppercase letter.&lt;/li&gt;
&lt;li&gt;Use camel case (e.g., Car, StudentDetails).&lt;/li&gt;
&lt;li&gt;Avoid Acronyms and Abbriviation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Attributes&lt;/strong&gt; (Fields)&lt;/p&gt;

&lt;p&gt;Attributes are variables inside the class that represent the properties of an object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Car {
    String color; // Attribute
    String model; // Attribute
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Methods&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Methods are functions inside a class that define the behavior of an object. For example, a method can make a car start:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void start() {
    System.out.println("Car is starting");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Return Types&lt;/strong&gt;&lt;br&gt;
Methods can return values(int,long,string etc). The &lt;em&gt;void keyword&lt;/em&gt; is used when a method doesn’t return anything:&lt;/p&gt;


&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void displayInfo() {
    System.out.println("This is a car.");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Access Modifiers&lt;/strong&gt;&lt;br&gt;
Access modifiers control the visibility of class members. For detailed information, &lt;a href="https://dev.toURL"&gt;read my blog on Access Modifiers here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Constructors&lt;/strong&gt;&lt;br&gt;
A constructor is a special method used to initialize objects. To know more about it &lt;a href="https://dev.to/singhaayush/oop-simplified-breaking-down-the-4-core-principles-4f23"&gt;read this&lt;/a&gt;.&lt;/p&gt;


&lt;h2&gt;
  
  
  Components of an Object
&lt;/h2&gt;

&lt;p&gt;An object has three main components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;State&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The state of an object is defined by its attributes. For example, a car’s color and model define its state.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Behavior&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The behavior of an object is defined by its methods. For example, starting and stopping a car are behaviors.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Identity&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each object has a unique identity, which is its reference or memory address in the system.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Car {
    String color;
    void displayInfo() {
        System.out.println("Car color: " + color);
    }
}

public class Main {
    public static void main(String[] args) {
        Car myCar = new Car();
        myCar.color = "Blue"; // State
        myCar.displayInfo(); // Behavior
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Special Components of a Class
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Static Fields and Methods&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Static fields and methods belong to the class, not any specific object. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MathUtils {
    static int square(int x) {
        return x * x;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;usage:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int result = MathUtils.square(5); // No object needed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In simple word it means, you do not have to initialize a object to use the static method in a class.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Final Classes and Variables&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The final keyword is used to make variables constant, prevent method overriding, or restrict inheritance. This keyword can be used in three context:&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;final variable =&amp;gt; To create constant contact variable.&lt;/li&gt;
&lt;li&gt;final method =&amp;gt; To prevent method overloading.&lt;/li&gt;
&lt;li&gt;final class =&amp;gt; prevent inheritance.
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;final class Constants {
    static final double PI = 3.14159;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Advanced Class Concepts
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Object Class&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Object class in Java is present in java.lang package. Every class in Java is directly or indirectly derived from the Object class. If a class does not extend any other class then it is a direct child class of the Java Object class and if it extends another class then it is indirectly derived. It provides useful methods like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;toString(): Converts an object to a string.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;equals(): Checks if two objects are equal.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Builder Classes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Builder classes help create objects step by step, especially when objects have many attributes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Student {
    String name;
    int age;

    Student setName(String name) {
        this.name = name;
        return this;
    }

    Student setAge(int age) {
        this.age = age;
        return this;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;usage:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Student student = new Student().setName("Alice").setAge(20);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Singleton Class&lt;/strong&gt;&lt;br&gt;
A Singleton class ensures that only one instance of the class is created throughout the program's execution. It is commonly used when you need a single, shared resource, such as a configuration manager or a database connection.&lt;/p&gt;

&lt;p&gt;The key steps to create a Singleton class are:&lt;/p&gt;

&lt;p&gt;Make the constructor private so no other class can instantiate it.&lt;br&gt;
Create a static method to provide access to the instance.&lt;br&gt;
Use a static field to hold the single instance of the class.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Singleton {
    // Step 1: Create a private static instance of the class
    private static Singleton instance;

    // Step 2: Make the constructor private
    private Singleton() {
        System.out.println("Singleton Instance Created");
    }

    // Step 3: Provide a public static method to get the instance
    public static Singleton getInstance() {
        if (instance == null) { // Check if instance is not already created
            instance = new Singleton();
        }
        return instance;
    }
}

public class Main {
    public static void main(String[] args) {
        Singleton obj1 = Singleton.getInstance(); // Creates the instance
        Singleton obj2 = Singleton.getInstance(); // Returns the same instance

        System.out.println(obj1 == obj2); // Output: true (both refer to the same instance)
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Explanation&lt;/em&gt;:&lt;br&gt;
The constructor is private, so you cannot create an object of Singleton class using new.&lt;br&gt;
The getInstance() method checks if the instance is null. If it is, a new instance is created. Otherwise, the existing instance is returned.&lt;br&gt;
This ensures that only one object is created, no matter how many times getInstance() is called.&lt;/p&gt;


&lt;h2&gt;
  
  
  In-Built Packages
&lt;/h2&gt;

&lt;p&gt;Packages group related classes. Some common in-built packages in Java include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;java.util: Contains utility classes like ArrayList, HashMap.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;java.io: Provides classes for input and output operations.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;java.lang: Includes core classes like String, Math.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import java.util.ArrayList;

public class Main {
    public static void main(String[] args) {
        ArrayList&amp;lt;String&amp;gt; list = new ArrayList&amp;lt;&amp;gt;();
        list.add("Hello");
        System.out.println(list);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Real-Life Applications of Classes and Objects
&lt;/h2&gt;

&lt;p&gt;Student Management: A Student class with &lt;em&gt;attributes like name, age&lt;/em&gt; and &lt;em&gt;methods like enroll()&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Bank System: A BankAccount class with &lt;em&gt;attributes like balance&lt;/em&gt; and &lt;em&gt;methods like deposit(), withdraw()&lt;/em&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Classes and objects are fundamental building blocks of object-oriented programming. They help organize code, make it reusable, and represent real-world entities in software. By understanding their components and practicing with small projects, you can lay a strong foundation for mastering object-oriented programming. Happy coding!&lt;/p&gt;

</description>
      <category>java</category>
      <category>beginners</category>
      <category>codenewbie</category>
      <category>coding</category>
    </item>
    <item>
      <title>Encapsulation and Abstraction in Object-Oriented Programming (OOP)</title>
      <dc:creator>Aayush Singh</dc:creator>
      <pubDate>Thu, 26 Dec 2024 12:53:07 +0000</pubDate>
      <link>https://dev.to/singhaayush/encapsulation-and-abstraction-in-object-oriented-programming-oop-4mo3</link>
      <guid>https://dev.to/singhaayush/encapsulation-and-abstraction-in-object-oriented-programming-oop-4mo3</guid>
      <description>&lt;p&gt;Understanding encapsulation and abstraction is essential when learning Object-Oriented Programming (OOP). These concepts make programs easier to design, read, and maintain. In this article, we will explore these two pillars of OOP step by step in simple terms, using Java examples to clarify the concepts.&lt;/p&gt;




&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What Are Encapsulation and Abstraction?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Encapsulation: The process of bundling data (variables) and methods (functions) that operate on the data into a single unit (class) while hiding the implementation details.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Abstraction: The process of exposing only essential features of an object while hiding unnecessary details.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Together, these concepts help developers create more secure, modular, and reusable code.&lt;/p&gt;




&lt;h2&gt;
  
  
  Encapsulation
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Definition and Concept&lt;/strong&gt;&lt;br&gt;
Encapsulation ensures that the internal details of a class are hidden from the outside world. It protects the data by restricting direct access to class fields and controlling it through methods.&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;Imagine a bank account. You can deposit or withdraw money through specific operations, but you cannot directly change the balance without using these operations. This protection is encapsulation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How Encapsulation Works&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Encapsulation is achieved using access modifiers (public, private, protected) to restrict access to class fields and methods.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Access Modifiers&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Private: The field or method can only be accessed within the class.&lt;/li&gt;
&lt;li&gt;Public: The field or method can be accessed from anywhere.&lt;/li&gt;
&lt;li&gt;Protected: The field or method can be accessed within the class and its subclasses.
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4ii9i14wd00aptlan4qd.png" alt="Access Modifiers" width="797" height="237"&gt;
Here is how encapsulation is implemented:&lt;/li&gt;
&lt;/ul&gt;


&lt;pre class="highlight plaintext"&gt;&lt;code&gt; class BankAccount {
     private double balance; // Private field
     // Public method to get the balance
     public double getBalance() {
         return balance;
     }
     // Public method to set the balance
     public void deposit(double amount) {
         if (amount &amp;gt; 0) {
             balance += amount;
         }
     }
     public void withdraw(double amount) {
         if (amount &amp;gt; 0 &amp;amp;&amp;amp; amount &amp;lt;= balance) {
             balance -= amount;
         }
     }
 }
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;&lt;strong&gt;Getters and Setters&lt;/strong&gt;&lt;br&gt;
Getters and setters are methods that allow controlled access to private fields. They help protect the data by validating or restricting input and output values.&lt;br&gt;
Example:&lt;/p&gt;


&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Person {
    private String name; // Private field
    // Getter method
    public String getName() {
        return name;
    }
    // Setter method
    public void setName(String name) {
        if (name != null &amp;amp;&amp;amp; !name.isEmpty()) {
            this.name = name;
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Benefits of Encapsulation&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Data Hiding: Prevents unauthorized access to the data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Improved Modularity: Each class handles its responsibilities.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Easy Maintenance: Changes in the internal implementation do not affect external code.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  Abstraction
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Definition and Concept&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Abstraction focuses on exposing only the essential details of an object while hiding its complexities. For example, when driving a car, you only need to know how to steer and use the accelerator—you don’t need to understand how the engine works internally.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How Abstraction Works&lt;/strong&gt;&lt;br&gt;
In Java, abstraction is achieved using:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Abstract Classes&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Interfaces&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Abstract Classes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An abstract class cannot be instantiated. It can have both abstract methods (methods without implementation) and concrete methods (methods with implementation).&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;abstract class Animal {
    // Abstract method
    abstract void makeSound();

    // Concrete method
    void sleep() {
        System.out.println("Sleeping...");
    }
}

class Dog extends Animal {
    @Override
    void makeSound() {
        System.out.println("Bark");
    }
}

class Main {
    public static void main(String[] args) {
        Animal dog = new Dog();
        dog.makeSound(); // Outputs: Bark
        dog.sleep();     // Outputs: Sleeping...
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Interfaces&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An interface is a blueprint of a class. It contains only abstract methods (until Java 8, where default and static methods are allowed).&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface Vehicle {
    void start(); // Abstract method
}

class Car implements Vehicle {
    @Override
    public void start() {
        System.out.println("Car is starting...");
    }
}

class Main {
    public static void main(String[] args) {
        Vehicle car = new Car();
        car.start(); // Outputs: Car is starting...
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Benefits of Abstraction&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Simplifies Code: Focuses only on essential details.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Improves Code Reusability: Abstract methods and interfaces provide reusable templates.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enhances Flexibility: Allows different implementations for the same behavior&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Encapsulation vs. Abstraction
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Key Differences&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
  &lt;tr&gt;
    &lt;th&gt;Encapsulation&lt;/th&gt;
    &lt;th&gt;Abstraction&lt;/th&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Hides implementation details.&lt;/td&gt;
    &lt;td&gt;Hides unnecessary details.&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Achieved using private fields.&lt;/td&gt;
    &lt;td&gt;Achieved using abstract classes or interfaces.&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
    &lt;td&gt;Focuses on how data is accessed.&lt;/td&gt;
    &lt;td&gt;Focuses on what an object does.&lt;/td&gt;
  &lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  How They Work Together
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Encapsulation hides the implementation details of a class.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Abstraction focuses on exposing only essential features.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example 1&lt;/strong&gt;: In a banking system:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Encapsulation:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Protect customer details (e.g., account number) using private fields.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Abstraction:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Define operations like deposit() and withdraw() in an interface.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 2&lt;/strong&gt;: Designing a Car Class&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Encapsulation:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hide the details of the engine (e.g., private fields).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Abstraction:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Expose essential methods like start() and stop().&lt;/p&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Encapsulation and abstraction are powerful tools in OOP. Encapsulation protects the internal details of a class, while abstraction simplifies complex systems by focusing on essential features. Together, they make code more secure, modular, and maintainable.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;As your next step&lt;/em&gt;, explore how these concepts are applied in design patterns and frameworks to deepen your understanding of OOP.&lt;/p&gt;

</description>
      <category>java</category>
      <category>oop</category>
      <category>beginners</category>
      <category>coding</category>
    </item>
  </channel>
</rss>
