Practice
Data Structures and Algorithms
Machine Coding Round (LLD)
System Design & Architecture (HLD)
Frontend UI Machine Coding
Resources
Career Advice and Roadmaps
Data Structures and Algorithms
Machine Coding Round (LLD)
System Design & Architecture (HLD)
Backend Development
Frontend Development
Project Ideas for Software Developers
Core Computer Science
Companies
SDE Jobs & Internships
Interview Questions
Compare Companies
IDE
Online IDE
Collaborative IDE

Introduction to Computer Networks (CN) | Core Computer Science

Gaurav Chandak
Gaurav Chandak

A computer network is a set of computers/devices sharing resources connected over a network with each device being represented as a network node. The computers communicate using standard protocols to send/receive data.

Computer networks can also include other devices that help in communication (network devices). Examples of network devices are routers, switches, hubs, and bridges.

Network Topology

Network topology is the layout of the computer network. It denotes how the devices in a network are connected.

Common network topologies are:

  • Bus network: all nodes are connected to a common medium along this medium.
  • Star network: all nodes are connected to a special central node.
  • Ring network: nodes are connected in the form of a ring.
  • Mesh network: each node is connected to an arbitrary number of neighbors in such a way that there is at least one traversal from any node to any other.
  • Fully connected network: each node is connected to every other node in the network.
  • Tree network: nodes are arranged hierarchically.

Types of Networks

There are different types of networks categorized based on the area of distribution.

  • PAN (Personal Area Network): Used for interconnecting devices within a person's workspace. Example: Bluetooth, USB
  • LAN (Local Area Network): Used for a small geographical location like home, office, school, etc.
  • MAN (Metropolitan Area Network): Used to connect a geographical region of the size of a metropolitan area.
  • WAN (Wide Area Network): Used to connect a wide geographical region usually a country or continent.
  • GAN (Global Area Network): Also known as the Internet. Uses satellites to connect devices across the globe.

VPN (Virtual Private Network)

VPN is software used to create a private secured tunnel over the internet. The device connects to the connection created by the VPN and the device accesses resources from the private network. It is used by organizations to allow access to resources available in the organization's private network. It is also used to access resources not accessible from the public network.

IP Address

An IP Address (Internet Protocol address) is a numerical label used to identify a device on a computer network that uses the Internet Protocol for communication.

IP addresses are written and displayed in human-readable notations.

Examples:

  • 138.34.124.2
  • 2351:ad7:2341:0:a1:679:12:2

IP Address Versions

IPv4

An IPv4 address is a version of IP Addressing that has a size of 32 bits. The total number of possible IPv4 addresses is ~4.29 billion addresses (2^32). Of this number, some addresses are reserved for special purposes such as private networks and multicast addressing.

Representation:

  • IPv4 addresses are generally represented in dot-decimal notation.
  • It consists of four decimal numbers, each ranging from 0 to 255, separated by dots (Ex: 138.34.124.2).
  • Each part represents a group of 8 bits (an octet) of the address.
IPv6

An IPv6 address is a version of IP Addressing that has a size of 128 bits. The total number of possible IPv4 addresses is ~3.4*10^38 addresses (2^128). The huge range of possible IP addresses is sufficient for the foreseeable future.

Representation:

  • IPv6 addresses are generally represented as eight groups of four hexadecimal digits with each group representing 16 bits.
  • The groups are separated by colons (:) (Ex: 2351:0ad7:2341:0000:00a1:0679:0012:0002).

Types of IP Addresses

Public IP Address

A public IP Address is the IP Address used to denote the device on the internet. It is provided by the ISP.

Private IP Address

A private IP Address is the IP Address used to uniquely identify the devices in the same network. There are specific IP Addresses reserved for private IP Addresses.

The private IP Address ranges are:

  • 10.0.0.0 to 10.255.255.255
  • 172.16.0.0 to 172.16.255.255
  • 192.168.0.0 to 192.168.255.255
Loopback Addresses

Loopback addresses are IP addresses reserved for use in accessing the network services on the same computer. The loopback address range is 127.0.0.0 to 127.255.255.255.

127.0.0.1 also known as localhost is a loopback address.

There are other reserved IP Addresses as well for different purposes.

MAC Address (Media Access Control Address)

MAC address is the physical address of a device. It is a 48-bit or 64-bit unique identifier embedded with the Network Interface Card/Controller (NIC). A MAC address is assigned to the NIC at the time of manufacturing. NIC is a hardware component that connects a computer to a computer network.

Port

A port is a logical construct that identifies a specific process or a type of network service. A port is identified for each transport protocol and address combination by a 16-bit unsigned number, known as the port number.

A port number is always associated with an IP address of a host and the type of transport protocol used for communication.

Common Default Port Numbers:

  • HTTP: 80
  • HTTPS: 443
  • SSH: 22
  • SMTP: 25
  • MySQL: 3306
  • MongoDB: 27017

TCP and UDP

TCP (Transmission Control Protocol)

TCP or TCP/IP stands for Transmission Control Protocol/Internet Protocol. TCP is one of the main protocols of the IP suite.

TCP/IP is a connection-oriented protocol that helps transmit data in a reliable, ordered, and error-checked manner over an IP network. A TCP connection is established using a three-way handshake. The connection is transferred once the data transfer is completed.

UDP (User Datagram Protocol)

UDP stands for User Datagram Protocol and is a protocol of the IP suite.

UDP is a connectionless protocol and sends messages based on Datagrams. UDP does not have any hand-shaking making it less reliable.

TCP vs UDP

  • Connection: TCP is connection-oriented whereas UDP is connectionless.
  • Speed: TCP is comparatively slower than UDP.
  • Ordered: TCP packets are ordered whereas UDP packets are unordered.
  • Reliability: TCP is more reliable compared to UDP.
  • Handshake: TCP uses a three-way handshake whereas there are no handshakes in UDP.
  • Error-checking: TCP provides better error-checking mechanisms compared to UDP.

HTTP (Hypertext Transfer Protocol)

HTTP is an application layer protocol used for communication on the internet.

In simple terms, HTTP is kind of a language that the clients and servers use to talk to each other. HTTP connections are made to an application/web service uniquely identified by a combination of an IP Address and a port.

HTTP messages are transferred between a client and a server using a Request-Response method. The client makes an HTTP Request to the server and the server responds with an HTTP Response.

HTTPS (Hypertext Transfer Protocol Secure)

To make the communication between a client and server secure, HTTPS protocol is used. HTTPS is an extension of HTTP.

The client sends the requests encrypted using a protocol known as TLS (Transport Layer Security). The server then decrypts the request before processing it. Any bad actor trying to eavesdrop would not be able to access the data as it would be encrypted.

SMTP, IMAP, and POP3

SMTP (Simple Mail Transfer Protocol) is a communication protocol used for email transmission. Mail servers use SMTP to send and receive emails. Email clients generally use SMTP to send emails and IMAP or POP3 to retrieve emails.

IMAP (Internet Message Access Protocol) and POP3 (Post Office Protocol) are protocols used by email clients to retrieve email messages from a mail server.

The difference between IMAP and POP3 is that IMAP downloads a local copy of the mail from the mailbox server whereas POP3 moves the mail from the mailbox server to the local computer.

FTP (File Transfer Protocol)

FTP is a communication protocol used to transfer files from a server to a client on a computer network. Recent versions of browsers have stopped support for FTP.

DNS (Domain Name System)

DNS is like an address book having the IP addresses for the domains. It is a hierarchical and decentralized naming system for computers, services, or other resources connected to the Internet or a private network.

OSI Model (Open Systems Interconnection Model)

The OSI model is a network architecture model that standardizes the communication protocols by partitioning the flow of data into seven abstraction layers.

The layers of the OSI Model are:

  1. Application Layer
  2. Presentation Layer
  3. Session Layer
  4. Transport Layer
  5. Network Layer
  6. Data Link Layer
  7. Physical Layer

Here, the Application Layer is the topmost layer and the Physical Layer is the lowest.

Let's look at the functions of all the OSI Model Layers.

  • Application: High-level APIs, including resource sharing, remote file access
  • Presentation: Translation of data between a networking service and an application; including character encoding, data compression, and encryption/decryption
  • Session: Managing communication sessions, i.e., a continuous exchange of information in the form of multiple back-and-forth transmissions between two nodes
  • Transport: Reliable transmission of data segments between points on a network, including segmentation, acknowledgment, and multiplexing
  • Network: Structuring and managing a multi-node network, including addressing, routing, and traffic control
  • Datalink: Reliable transmission of data frames between two nodes connected by a physical layer
  • Physical: Transmission and reception of raw bitstreams over a physical medium.
1
Gaurav Chandak
Gaurav Chandak
Gaurav is the co-founder of workat.tech and has previously worked at Flipkart and Microsoft. He intends to actively contribute to the future of education through workat.tech.
SDE Bootcamp - Become a software engineer at a product-based company
Practice Data Structures & Algorithms
Learning Resources
Interview Prep Resources
Blog
  • Career Advice and Roadmaps
  • Data Structures & Algorithms
  • Machine Coding Round (LLD)
  • System Design & Architecture
  • Backend Development
  • Frontend Development
  • Awesome Project Ideas
  • Core Computer Science
Practice Questions
  • Machine Coding (LLD) Questions
  • System Design (HLD) Questions
  • Topic-wise DSA Questions
  • Company-wise DSA Questions
  • DSA Sheets (Curated Lists)
  • JavaScript Interview Questions
  • Frontend UI Machine Coding Questions
Online Compilers (IDE)
  • Online Java Compiler
  • Online C++ Compiler
  • Online C Compiler
  • Online Python Compiler
  • Online JavaScript Compiler
Topic-wise Problems
  • Dynamic Programming Interview Questions
  • Linked List Interview Questions
  • Graph Interview Questions
  • Backtracking Interview Questions
  • Arrays Interview Questions
  • Trees Interview Questions
Company-wise Problems
  • Amazon Interview Questions
  • Microsoft Interview Questions
  • Google Interview Questions
  • Flipkart Interview Questions
  • Adobe Interview Questions
  • Facebook Interview Questions
DSA Sheets (Curated Lists)
  • Top Interview Questions
  • FAANG Interview Questions
  • Most Asked Interview Questions
  • 6 month DSA Practice Sheet
  • 3 month DSA Practice Sheet
  • Last minute DSA Practice Sheet