Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Aptitude
  • Engineering Mathematics
  • Discrete Mathematics
  • Operating System
  • DBMS
  • Computer Networks
  • Digital Logic and Design
  • C Programming
  • Data Structures
  • Algorithms
  • Theory of Computation
  • Compiler Design
  • Computer Org and Architecture
Open In App
Next Article:
Working Of Different layers in Computer Network
Next article icon

Working Of Different layers in Computer Network

Last Updated : 29 Jun, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

Ever wondered how different layers of network work together to send a message. Lets understand some basic terms before getting into details. 
 

  • A Default Gateway serves as an access point or IP router that a networked computer uses to send information to a computer in another network or the internet. 
     
  • Address Resolution Protocol (ARP) request is a protocol which converts IP address into MAC address. 
     
  • A Routing tables is a set of rules, often viewed in table format, that is used to determine where data packets traveling over an Internet Protocol (IP) network will be directed. 
     



Generally a host or a computer has all layers (from application layer to physical layer ) and a router has network, data link layer and a physical layer. 

Now lets understand the working of different layers with the help of an example. 

 




Suppose you want to send a message to an application on host2 (assume it is present in different network). 
Let the IP and MAC address of host1 be I1 , M1 and IP and MAC address of host2 be I2 , M2. Suppose the default gateway of host1 be router1(IP address be IR1, Mac address be MR1) and the default gateway of host2 be router2 (IP address be IR2, Mac address be MR2). 


At Host1: 
Suppose the application layer wants to send a message M to host2. The application layer of host1 gives it to transport layer of host1. Transport layer will add header to the message M which contains the port number of host1, host2(x,y). Therefore now the message will be (M,x,y) and this will be given to network layer of host1. Network layer also adds an header to the message which contains the Ip address of host1 and host2. 

Now the message will be (M,x,y,I1,I2) and it will be given to DataLink layer. Data link layer also adds an header for the message before giving it to the physical layer. Since the host2 is not present in the same network it will put the mac address of host1 and mac address of default gateway (it will know the mac address by sending an ARP request). Now the message will be (M,x,y,I1,I2,M1,MR1) and this will be given to physical layer. Physical layer converts the given message to bits and sends it the router1. 

 




At Router1: 
The physical layer will convert the bits into message and will inform the datalink layer that this packet should be processed after seeing the Mac address of router1. After seeing the packet the datalink layer of router1 will send an acknowledgement to datalink layer host1 and will remove the header information added at DLL of host1 before giving it to Network layer of router1. The message that network layer gets is (M,x,y,I1,I2). 

Network layer sees the destination Ip address and since the destination is not present in its network it will decide it forward it router2. Network layer of router1 decides it after seeing the routing tables at router1 and will decide it.Now the DLL of router adds header to the message. This time the source mac address will be MR1 and destination MAC address will be MR2 (using Arp it finds out). In this way the receiver only knows the Ip address of source and it will never know the mac address of the source. Now the message will be (M,x,y,I1,I2,MR1,MR2) and it will be given to physical layer. The physical layer converts it to bits and sends it router2. 

 




At Router2: 
The physical layer will convert the bits into message and will inform the DLL of router2.Now the DLL of router2 will send an acknowledgement to DLL of router1 after seeing the message. DLL of router2 will remove the MAC address and give it to network layer. 

Now the network layer finds out that the host2 is in the network to which the router2 is connected so it will send the message to host2. Network layer finds out that host2 is in the same network after seeing the routing tables present at the router2.N ow the DLL will add the header information with mac address of router2 (sender) and M2(destination) (it finds out using ARP request). Now the message will be (M,x,y,I1,I2,MR2,M2) and will be given to physical layer which converts it to bits and sends it host2. 

 




At Host2: 
The physical layer will convert it into bits and will give the message to DLL. DLL sends an acknowledgment to DLL of router2 and removes the MAC address on the message, which will be given to NL. Now the network layer will remove the IP address and gives it Transport layer. 

Now the transport layer will send an acknowledgment to Transport Layer of host1 (in case of TCP since it has the IP address of host1. The message will be (M,y,x,I2,I1)) and removes the port number and gives the message to the process(or application) present at y. 

 




Note: 
 

  1. Since Transport layer is responsible for end to end connectivity , transport layer of host2 sends an acknowledgment to transport layer of host1. 
     
  2. DataLink layer is responsible for hop to hop connectivity , each time a router/host receives a packet acknowledgment is sent to respective data link layers. 
     
  3. Network layer takes care of bit level error and transport layer takes care of packet errors. 
     
  4. Routers MAC address is temporary because ISP generally changes the NIC (Network Interface Card) which contains the MAC address. So default gateway IP address is shared to hosts and other routers and not MAC address. 
     



This is how the message from one host is delivered to another host on different network.
 


Next Article
Working Of Different layers in Computer Network

B

Bvs_Revanth
Improve
Article Tags :
  • Computer Networks

Similar Reads

    Dimensions of Computer Network
    Dimensions of computer networks mean under what characteristics or factors can the computer networks be categorized. Computer networks can be divided into different groups under the pattern which recognizes the transmission of information or messages by the sender to the receiver and the area it cov
    3 min read
    List of "Difference Between" Computer Networks Topics
    Computer Network is a set of devices or systems that shares resources through links and it can be defined as a collection of nodes. A node can be any device capable of transferring or receiving data. The communicating nodes need to be connected by communication links. A computer network refers to in
    4 min read
    Functionality of Computer Network
    Prerequisite - Basics of Computer Networking, Network goals, Layers of OSI Model, Transport Layer responsibilities When a client is present on one machine and server is present on another machine, then making a connection between them, is called computer network.Computer networks share common device
    4 min read
    MAN Full Form in Computer Networking
    A Metropolitan Area Network (MAN) is a type of computer network that spans over a metropolitan area, typically a city. It provides high-speed data communication services such as video, audio, and data transfer between multiple LANs (Local Area Networks) and WANs (Wide Area Networks). The main purpos
    9 min read
    Protocol Hierarchies in Computer Network
    A Protocol Hierarchy is a fixed set of rules and conventions that govern the communication between two or more computers. The hierarchical structure allows for modular design, interoperability, and ease of implementation in computer networks. What is Protocol?A protocol is simply defined as a set of
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences