Introduction to TCP/IP (Part 2) - Five Layer Model and Applications

Last modified by Microchip on 2023/11/10 11:23

TCP/IP Five-Layer Software Model

Basic Needs for TCP/IP Communication

Some of the applications we use require us to move data across a network from point A to point B. The Transmission Control Protocol/Internet Protocol (TCP/IP) network provides a framework for transmitting this data, and it requires some basic information from us to move this data.

TCP/IP basic needs

We need to specify if we want the most reliable or fastest transmissions and we need to specify where we want the data delivered. Sometimes our data is routed based on its IP addresses and sometimes it's routed based on its MAC address. The data we send needs both addressing capabilities. This information needs to be sent along with all transmitted data. We also need to physically transmit the data from one location to another.

Back to top

TCP/IP Five-Layer Software Model Overview

We need to provide this basic information needed by TCP/IP in a standard format the network can understand. This format is provided by its five-layer software model.

Each layer provides TCP/IP with the basic information it needs to move our data across the network. These layers group functions according to the task that needs to be performed. Every function in this model is targeted to help a specific layer perform its job.

Each layer only communicates with adjacent layers. Software running in a higher layer does not have to know about or perform tasks delegated to lower-layer functions and vice versa. For example, the software you write for your application only needs to know how to request a connection with a remote host using the Transport layer. It doesn’t need to know how bits are encoded before transmission. That’s the Physical layer’s job.

TCP/IP five layers

​You are probably familiar with the seven-layer OSI model. TCP/IP simplifies this model to five layers. OSI stands for Open Systems Interconnect, which is a standard communication systems model. The top four layers of the seven-layer OSI model have been condensed into the top two TCP/IP layers.

Back to top

TCP/IP Five-Layer Model

Application Layer (Layer 5)

As you might have guessed, the Application layer is where applications requiring network communications live. Examples of these applications include email clients (SMTP) and web browsers (HTTP). These applications use the Transport Layer to send requests to connect to remote hosts.

Common TCP/IP applications >

application layer

Back to top

Transport Layer (Layer 4)

Layer 4 is the Transport layer. The transport layer creates virtual Transfer Control Protocol (TCP) or User Datagram Protocol (UDP) connections between network hosts.

This layer sends and receives data (packets) to and from the applications running on its host. The Transport layer assigns port numbers to the processes running in applications on the host and adds a TCP or UDP header to the messages received from the applications detailing the source and destination port numbers.

Note that some of the applications, specifically Telnet, SMTP, and HTTP require TCP as the transport protocol while others use UDP.

transport layer

Some applications require reliable ordered delivery of packets. The TCP protocol provides this capability. It uses error detection, retransmissions and acknowledgments. This protocol cares about your data.

Other applications don’t care if every packet is received. These applications can take advantage of UDP’s lower overhead to enable faster transmissions.

Typical TCP applications include email and web browsing and typical UDP applications include VoIP and music streaming.

TCP is strictly used for point-to-point or unicast transmissions while UDP can also be used for multicast and broadcast transmissions.


For more information on TCP, visit the "Transmission Control Protocol" page.
For more information on UDP, visit the "User Datagram Protocol" page

Back to top

TCP and UDP Headers

The header added to messages by the Transport layer includes more than just the source and destination port numbers. Here we are showing all the information included in TCP and UDP headers.

Note how the TCP protocol requires more information and overhead to guarantee data delivery.

TCP and UDP headers

Back to top

Network Layer (Layer 3)

Layer 3 is the Network or Internet layer.

When transmitting data (packets), this layer adds a header containing the source and destination IP addresses to the data received from the Transport layer. The packet it creates will then be forwarded to the MAC or Data Link layer.

When receiving data, this layer is used to determine if the packet received by the host contains the host’s IP address. If it does, the data is forwarded up to the Transport layer.

Network layer

Routers are referred to as “layer 3” devices because they route packets based on their IP addresses.

Back to top

TCP/IP IPv4 Packet Header

The Network layer header includes more than just the source and destination IP addresses.
IPv4 header

Back to top

Data Link Layer (Layer 2)

Layer 2 is the Data Link layer. This layer uses a Media Access Controller (MAC) to generate the frames that will be transmitted. As the name suggests, the MAC controls the physical transmission media. The wireless transmission media used for Wi-Fi® or 802.11 has different requirements from the wired transmission media used for Ethernet or 802.3, and therefore needs a different MAC and PHY. Note the upper layer software is not aware of or affected by the physical interface.

When transmitting data, this layer adds a header containing the source and destination MAC addresses to the packet received from the Network layer (layer 3). The frame it creates will then be forwarded to the Physical layer.

When receiving data, this layer is used to determine if the frame received by the host contains the host’s MAC address. If it does, the data is forwarded up to the Network layer.

Every host on the network has at least one MAC address. Laptops typically have two, one for the wired LAN and one for the wireless LAN. Home routers also typically have two MACs: one for the local network and one for the Internet.

Data Link layer

​Most switches are referred to as “layer 2” devices because they route frames based on their MAC addresses.

Back to top

Ethernet and Wi-Fi® Frame Format

As you probably guessed, the Data Link layer adds more than just the source and destination MAC addresses to the packet. Note that the MAC for Ethernet and Wi-Fi are different and generate different frames.

Ethernet and WiFi frames

​For more information on Ethernet frames, visit the "Ethernet frame" page.
For more information on Wi-Fi frames, visit the "How 802.11 Wireless Works" page.

Back to top

Physical Layer (Layer 1)

Layer 1 is the Physical layer. It sends and receives signals on the physical wire or antenna to transmit the bits found in frames.

There is a PHY found at the end of every network interface (e.g., end of wire or antenna).

Physical Layer

Back to top

Transmit Data Using Network Layers

Now that we know the primary job of each layer, let’s see how they work together to send and receive data across a TCP/IP network.

This is a simplified view of how the network layers work together to generate frames. Higher layers pass information to lower layers. Each layer adds information called a header to the data being passed to it. This header contains information the layer needs to perform its job. We will start at the Application layer.

TCP/IP five layer overview

Back to top

Data Flow (Transmitting Data)

To send and receive data across a TCP/IP network, data is passed to each lower layer, which will add to the data until the full packet is formed. This is a simplified view of how the network layers work together to generate frames. Higher layers pass information to lower layers. Each layer adds information called a header to the data being passed to it. This header contains information the layer needs to perform its job.

transmit data

  • Application Layer
    • The Application layer generates a message. In this case, the specific application is a web browser requesting a webpage download. This message is then sent to the Transport layer.
  • Transport Layer
    • The Transport layer adds the TCP or UDP header which includes the source and destination port addresses. Additional information like the packet sequence number used for TCP will also be added to the header. The data generated by the transport layer is referred to as a Segment if TCP is used, and is referred to as a Datagram if UDP is used. This segment is then sent to the Network layer.
  • Network Layer
    • The Network layer adds a header including the source and destination IP address to generate a packet. This packet is then sent to the Data Link layer.
  • Data Link Layer
    • The Data Link layer adds a header containing the MAC address information to create a frame. The frame is then sent it to the Physical layer to transmit the bits.

Back to top

Data Flow (Receiving Data)

When receiving data, the network layers act as filters.

When the frame is received in the Data Link layer, the destination MAC address is compared with its own. If the data received is not intended for that host, it is immediately discarded. If it matches, the header is stripped and the payload, which in this case is a packet, is forwarded up to the next layer. Here, the Network layer checks if the destination IP address matches its own. If it matches, the header is stripped and the payload is forwarded up to the next layer. Here, the Transport layer checks to determine if there is a process running on the host with a destination port number of 80, which is the case. So, the header is stripped and the message is sent to process number 80 in the Application layer. Process number 80 is a function running in the HTTP server. This completes the message transmission process from one application to another.

receive data

Back to top

Terminology Reference

5 layer model terminology

Back to top

Common TCP/IP Applications

Dynamic Host Configuration Protocol (DHCP)

The dynamic host configuration protocol (DHCP) is the application responsible for requesting and offering IP addresses. A DHCP client automatically requests an IP address from a DHCP server when a network is detected. A DHCP server typically runs in a router and offers IP addresses to DHCP clients.


Back to top

DNS (Domain Name System)

A Domain Name System (DNS) enables us to browse a website by providing the website or domain name instead of the website’s IP address.

It maps domain names to IP addresses. A network host needs the IP address (not the domain or hostname) of the webserver to generate a packet.


Back to top

Hypertext Transfer Protocol (HTTP)

The Hypertext Transfer Protocol (HTTP) is the most commonly used TCP/IP application as it transfers web pages from a web server to a web browser.

Web pages are written using HTML, which stands for Hypertext Markup Language. In other words, the HTTP is used to transfer HTML files.


Back to top

NetBIOS Name Service (NBNS)

NBNS stands for NetBIOS Name Service. It is used to translate host names on a local network to local IP addresses. This is similar to what DNS does on the Internet.

In this example, the name “Board_A” has been assigned to a network host. NBNS allows us to access this host by typing its host name into a browser instead of typing its IP address. It maps host names to IP addresses.


Back to top

Simple Mail Transfer Protocol (SMTP)

Your embedded device can be configured to send emails. SMTP would be used for this.


Back to top

Simple Network Management Protocol (SNMP)

SNMP stands for Simple Network Management Protocol which manages network devices. It is primarily used to monitor network devices for conditions that may need a user's attention.


Simple Network Time Protocol (SNTP)

SNTP stands for Simple Network Time Protocol, which is a service that provides the time of day to network devices. Typical accuracy is in the range of hundreds of milliseconds.


Back to top

Telnet (Bi-directional Serial Text Communication)

Telnet is an application that enables bi-directional text communication via a terminal application like HyperTerm or Tera Term.


Back to top

Trivial File Transfer Protocol (TFTP)

TFTP is used to transfer files on a local network. It can be used to update firmware on an embedded device with a boot loader.

TFTP is a stripped-down version of FTP. TFTP has no provisions for security, so it is only used on local networks. Files are transferred in blocks of 512 bytes with a maximum file transfer size of 4 GB.


Learn More

Back to top