Networking Interview Prep
OSI Model

Presentation & Application Layers (Layers 6–7)

Presentation & Application Layers (Layers 6–7)

LinkedIn Hook

Most developers think TLS/SSL lives at Layer 7 — the Application Layer. It does not.

TLS lives at Layer 6 — the Presentation Layer.

Layer 6 is responsible for encryption, decryption, compression, and data format translation. When your browser makes an HTTPS request, TLS handshakes and encrypts the payload before it ever reaches the application protocol (HTTP).

This is one of the most common wrong answers in networking interviews — even from engineers with years of experience.

Here is exactly what each layer does, how OSI maps to TCP/IP (which is what actually runs the internet), and two code examples showing these layers in Node.js.


Presentation & Application Layers (Layers 6–7) thumbnail


What You'll Learn

  • What Layer 6 (Presentation) does — data translation, encoding, serialization, encryption, and compression
  • What Layer 7 (Application) does — the key protocols (HTTP, FTP, SMTP, DNS, SSH) with ports
  • How the OSI 7-layer model maps to the TCP/IP 4-layer model and when to use each in conversation
  • How these layers appear in real Node.js code through serialization, compression, and HTTP requests

Layer 6 — Presentation

Think of Layer 6 as a translator or interpreter. Two systems may speak different languages internally — different character encodings, different data formats, different compression schemes. Layer 6's job is to make sure that what one system sends, the other system can read correctly.

It sits between the Application Layer above it and the Session Layer below it. It takes raw application data and converts it into a format suitable for transmission — or on the receiving end, converts incoming data back into a format the application understands.

What Layer 6 handles

Character Encoding

When your application works with text, it uses a character encoding to represent characters as bytes. Layer 6 is responsible for encoding on the way out and decoding on the way in.

  • ASCII — 7-bit encoding, 128 characters, English only
  • UTF-8 — Variable-width encoding, backward compatible with ASCII, handles all Unicode characters. The web standard.
  • UTF-16 — Used internally by JavaScript and Java strings
  • Unicode — The character set; UTF-8 and UTF-16 are encodings of Unicode

If two systems use different encodings and no translation happens, you get mojibake — garbled characters where accented letters, emoji, or non-Latin scripts break.

Serialization Formats

Data structures in memory (objects, arrays, maps) cannot be sent over a network as-is. They must be serialized — converted into a byte sequence. Layer 6 handles this transformation.

FormatTypeUse Case
JSONTextREST APIs, web, human-readable
XMLTextSOAP, legacy enterprise, config
Protocol Buffers (protobuf)BinarygRPC, high-performance internal APIs
MessagePack (msgpack)BinaryCompact JSON alternative
CBORBinaryIoT, constrained environments

JSON is the dominant format on the web today. Protobuf is the dominant format for internal microservice communication where performance and schema validation matter.

Encryption and Decryption

This is where TLS conceptually lives in the OSI model.

TLS (Transport Layer Security) — and its predecessor SSL — encrypts data before it leaves the application and decrypts it on arrival. In OSI terms, this is a Presentation Layer function: transforming data from plaintext to ciphertext and back.

Key point for interviews: TLS is not Layer 7. It wraps the application-layer protocol. When you use HTTPS, the HTTP data is passed to TLS (Layer 6), encrypted, then passed down to TCP (Layer 4) for transport.

In practice, modern TCP/IP implementations do not have a distinct Presentation Layer process — TLS is implemented in libraries (OpenSSL, BoringSSL, NSS) that are called by the application. But conceptually in OSI terms, TLS is Layer 6.

Compression

Layer 6 also handles compressing data before transmission and decompressing it on receipt.

  • gzip — The standard for HTTP content encoding (Content-Encoding: gzip)
  • deflate — The underlying DEFLATE algorithm (also used in zlib)
  • Brotli — Google's algorithm, better compression ratios than gzip, supported by modern browsers
  • zstd — Facebook's algorithm, very fast, increasingly used in databases and internal systems

When your browser sends Accept-Encoding: gzip, deflate, br in an HTTP request, it is telling the server which Layer 6 compression schemes it supports.

MIME Types

MIME (Multipurpose Internet Mail Extensions) types tell the receiving system what kind of data it is receiving — the data format at a semantic level. Examples: application/json, text/html; charset=utf-8, image/png, application/octet-stream.

MIME types are a Layer 6 concern because they describe how to interpret and decode the payload.


Layer 7 — Application

Think of Layer 7 as the actual conversation — the language that applications speak to each other. If Layer 6 is the interpreter, Layer 7 is the specific language being interpreted.

A critical distinction: the Application Layer is not the application itself. It is the protocol the application uses to communicate. Chrome is not at Layer 7. HTTP is at Layer 7. Outlook is not at Layer 7. SMTP is at Layer 7.

The application layer defines the rules for how two programs communicate — what messages look like, what sequences are valid, what errors mean.

Key Application Layer Protocols

HTTP — Hypertext Transfer Protocol

  • Port: 80
  • Request-response protocol for web content
  • Stateless: each request is independent
  • Methods: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS
  • The protocol that powers the World Wide Web and REST APIs

HTTPS — HTTP Secure

  • Port: 443
  • HTTP with TLS encryption (the TLS part is Layer 6, the HTTP part is Layer 7)
  • Default for all modern web traffic

FTP — File Transfer Protocol

  • Ports: 21 (control), 20 (data)
  • Transfers files between client and server
  • Supports authentication, directory listing, active and passive modes
  • Plain text (insecure); replaced largely by SFTP (which runs over SSH) or FTPS (FTP + TLS)

SMTP — Simple Mail Transfer Protocol

  • Ports: 25 (server-to-server), 587 (client submission with STARTTLS), 465 (SMTPS, deprecated but still used)
  • Sends email from client to server and between mail servers
  • Works with IMAP (port 143/993) or POP3 (port 110/995) for email retrieval

DNS — Domain Name System

  • Port: 53 (UDP for queries, TCP for zone transfers and large responses)
  • Translates human-readable domain names (example.com) to IP addresses (93.184.216.34)
  • Hierarchical: root servers → TLD servers → authoritative servers → resolver cache
  • Every network connection begins with a DNS lookup (unless cached)

DHCP — Dynamic Host Configuration Protocol

  • Ports: 67 (server), 68 (client)
  • Automatically assigns IP addresses, subnet masks, default gateways, and DNS servers to devices on a network
  • Uses UDP broadcast; the client has no IP yet when it sends its first request (DHCPDISCOVER)

SSH — Secure Shell

  • Port: 22
  • Encrypted protocol for remote terminal access, file transfer (SCP/SFTP), and tunneling
  • Uses public-key cryptography for authentication
  • Replaced Telnet (port 23), which was unencrypted

API Calls as Application Layer Communication

When your frontend calls fetch('https://api.example.com/users'), every part of that is Layer 7. The HTTP method, headers, URL path, query parameters, request body, and response codes are all application-layer data. The fact that it travels over TLS (Layer 6) and TCP (Layer 4) is transparent to the application code.


OSI vs TCP/IP Model

The OSI model has 7 layers. The TCP/IP model has 4 layers. Both describe how network communication is organized, but they are not the same thing and they serve different purposes.

The TCP/IP model is what actually runs the internet. It was designed pragmatically, based on the protocols that were already working (TCP and IP). The OSI model was designed theoretically by ISO as a universal reference model. OSI won as the teaching tool. TCP/IP won in production.

TCP/IP 4 Layers

LayerTCP/IP NameWhat It Does
4ApplicationHTTP, FTP, DNS, SMTP, SSH — all user-facing protocols
3TransportTCP, UDP — end-to-end delivery, ports
2InternetIP, ICMP — routing packets across networks
1Network Access (Link)Ethernet, Wi-Fi — physical transmission on a single link

OSI to TCP/IP Mapping

OSI LayerOSI NameTCP/IP LayerTCP/IP Name
7Application4Application
6Presentation4Application
5Session4Application
4Transport3Transport
3Network2Internet
2Data Link1Network Access
1Physical1Network Access

OSI Layers 5, 6, and 7 all collapse into the single TCP/IP Application Layer. This is why TLS (OSI Layer 6) and HTTP (OSI Layer 7) are both implemented in the same process space in practice — there is no separate "Presentation Layer" runtime in TCP/IP.

When to use which model in conversation

Use OSI when:

  • Discussing concepts in interviews or teaching contexts ("TLS operates at Layer 6")
  • Troubleshooting — the OSI model gives you a structured checklist (physical, data link, network, transport...)
  • Vendor documentation often references OSI layer numbers (Layer 2 switch, Layer 3 routing, Layer 7 load balancer)

Use TCP/IP when:

  • Describing what actually happens on the internet
  • Writing documentation about protocol stacks
  • Discussing network architecture with engineers building systems

"Layer 7" in production contexts (like "Layer 7 load balancer") usually means OSI Layer 7 — application-level routing based on HTTP headers, URLs, or cookies. It is industry shorthand even in TCP/IP contexts.


Code Example 1 — Layer 6 Concepts in Node.js

This example shows the three core Presentation Layer transformations: serialization, compression, and encoding. These are the transformations data goes through before it is handed to the transport layer.

const zlib = require('zlib');
const { promisify } = require('util');

const gzip = promisify(zlib.gzip);
const gunzip = promisify(zlib.gunzip);

// --- Serialization (Layer 6) ---
// Transform an in-memory JavaScript object into a byte sequence
const data = {
  userId: 42,
  name: 'Rakibul',
  roles: ['admin', 'editor'],
  active: true,
};

const jsonString = JSON.stringify(data);
console.log('Serialized (JSON):');
console.log(jsonString);
// Output: {"userId":42,"name":"Rakibul","roles":["admin","editor"],"active":true}

// --- Character Encoding (Layer 6) ---
// Convert the JSON string to a Buffer using UTF-8 encoding
const utf8Buffer = Buffer.from(jsonString, 'utf-8');
console.log('\nUTF-8 encoded buffer:');
console.log(utf8Buffer);
// Output: <Buffer 7b 22 75 73 65 72 49 64 22 3a 34 32 ...>
console.log('Byte length:', utf8Buffer.byteLength);

// Convert back — this is what the receiving system does (decoding)
const decoded = utf8Buffer.toString('utf-8');
const deserialized = JSON.parse(decoded);
console.log('\nDeserialized:', deserialized);

// --- Compression (Layer 6) ---
// gzip compresses the payload before it is sent
async function demonstrateCompression() {
  const original = Buffer.from(jsonString, 'utf-8');
  const compressed = await gzip(original);

  console.log('\nCompression (Layer 6):');
  console.log('Original size:', original.byteLength, 'bytes');
  console.log('Compressed size:', compressed.byteLength, 'bytes');
  console.log(
    'Reduction:',
    (((original.byteLength - compressed.byteLength) / original.byteLength) * 100).toFixed(1) + '%'
  );

  // Decompress on the receiving end
  const decompressed = await gunzip(compressed);
  const result = JSON.parse(decompressed.toString('utf-8'));
  console.log('After decompression:', result);
}

demonstrateCompression();

// --- What this maps to in HTTP ---
// When a server sends a response with Content-Encoding: gzip,
// the browser (or your fetch client) decompresses automatically.
// That decompression is Layer 6 behavior.
//
// Content-Type: application/json; charset=utf-8  <- encoding (Layer 6)
// Content-Encoding: gzip                          <- compression (Layer 6)
// The JSON payload itself                         <- serialization (Layer 6)
// HTTP method, headers, status code               <- Layer 7

Key takeaway: Every time you call JSON.stringify(), Buffer.from(), or zlib.gzip(), you are performing Presentation Layer operations. These transformations happen before the data touches the network.


Code Example 2 — HTTP Request Anatomy at Layer 7

This example dissects an HTTP request to show what is application-layer data versus what is handled by lower layers.

const https = require('https');

// Everything in this function operates at Layer 7 (Application)
function makeApplicationLayerRequest() {
  // These are all Layer 7 constructs:
  // - The protocol scheme (https -> HTTP over TLS)
  // - The hostname (resolved via DNS, also Layer 7)
  // - The path, method, headers, and body

  const options = {
    hostname: 'jsonplaceholder.typicode.com', // DNS resolution -> Layer 7
    port: 443,                                 // HTTPS port
    path: '/posts/1',                          // Layer 7: URL path
    method: 'GET',                             // Layer 7: HTTP method
    headers: {
      // Layer 7: Application-layer metadata
      'Accept': 'application/json',            // tells server what format we want
      'Accept-Encoding': 'gzip, deflate, br',  // tells server which Layer 6 compression we support
      'User-Agent': 'NodeJS-Demo/1.0',
      'Connection': 'keep-alive',
    },
  };

  // Anatomy of an HTTP/1.1 request (what Layer 7 produces):
  //
  // GET /posts/1 HTTP/1.1          <- Request line: method + path + version
  // Host: jsonplaceholder.typicode.com  <- Required Layer 7 header
  // Accept: application/json       <- Layer 7 header
  // Accept-Encoding: gzip, deflate, br  <- References Layer 6 capabilities
  // User-Agent: NodeJS-Demo/1.0    <- Layer 7 header
  // Connection: keep-alive         <- Layer 7 session hint
  //                                <- Blank line separates headers from body
  // [empty body for GET]

  const req = https.request(options, (res) => {
    console.log('Layer 7 response data:');
    console.log('  Status:', res.statusCode, res.statusMessage); // HTTP status -> Layer 7
    console.log('  Headers:', res.headers);                       // HTTP headers -> Layer 7

    // Content-Type tells us the Layer 6 encoding and format
    const contentType = res.headers['content-type'];
    const contentEncoding = res.headers['content-encoding'];
    console.log('\n  Content-Type (Layer 6 format hint):', contentType);
    console.log('  Content-Encoding (Layer 6 compression):', contentEncoding);

    const chunks = [];
    res.on('data', (chunk) => chunks.push(chunk));
    res.on('end', () => {
      // The body arrives as bytes. If compressed, Node's https module
      // may auto-decompress (Layer 6 operation).
      const body = Buffer.concat(chunks).toString('utf-8'); // Layer 6: decode
      const parsed = JSON.parse(body);                      // Layer 6: deserialize
      console.log('\n  Parsed body (now in application memory):', parsed);
    });
  });

  req.on('error', (err) => {
    console.error('Request failed:', err.message);
  });

  req.end();
}

makeApplicationLayerRequest();

// Layer responsibilities in this request:
//
// Layer 7 (Application): HTTP method, URL, headers, status codes, body format rules
// Layer 6 (Presentation): JSON serialization, UTF-8 encoding, gzip decompression, TLS encryption
// Layer 4 (Transport):    TCP connection to port 443, segment ordering, retransmission
// Layer 3 (Network):      IP routing from your machine to jsonplaceholder's server
// Layer 2 (Data Link):    Ethernet/Wi-Fi frames on your local network
// Layer 1 (Physical):     Actual bits on the wire / radio signals

Presentation & Application Layers (Layers 6–7) visual 1


Common Mistakes

Mistake 1: Assuming TLS/SSL lives at Layer 7

TLS is a Presentation Layer (Layer 6) function in OSI terms. It encrypts and decrypts data — a data transformation task. HTTP (Layer 7) rides on top of TLS. HTTPS = HTTP (Layer 7) + TLS (Layer 6) + TCP (Layer 4). If an interviewer asks "what layer does TLS operate at in OSI?", the answer is Layer 6. Many engineers answer Layer 7 because they associate HTTPS with the application, but that conflates the protocol with the encryption wrapper.

Mistake 2: Confusing the application with the Application Layer

The Application Layer is the protocol, not the software. Firefox is not at Layer 7 — HTTP is. Postman is not at Layer 7 — the HTTP requests it sends are. This matters in interviews when you are asked "where does Chrome operate?" The answer is that Chrome uses Layer 7 protocols (HTTP, DNS) but the browser itself is not a network layer — it is software that generates Layer 7 traffic.

Mistake 3: Not knowing when OSI vs TCP/IP applies

OSI and TCP/IP are both correct models used in different contexts. Saying "Layer 7 load balancer" is correct industry shorthand. But if asked how the internet actually works, TCP/IP is the answer — there is no distinct Presentation or Session layer process in real network stacks. Not knowing this distinction will trip you up on questions like "how many layers does the TCP/IP model have?" (4, not 7) or "where do OSI layers 5 and 6 go in TCP/IP?" (collapsed into the Application layer).


Interview Questions

Q: Where does TLS fit in the OSI model, and why do people often get this wrong?

TLS fits at Layer 6 — the Presentation Layer — because its function is data transformation: encrypting outbound data and decrypting inbound data. People get it wrong because HTTPS (which uses TLS) is associated with web browsing, which feels like an application concern. The confusion comes from collapsing OSI layers 5, 6, and 7 into a single mental bucket. In TCP/IP terms, TLS is implemented in the Application layer because TCP/IP has no separate Presentation layer — but in OSI terms it is specifically Layer 6.

Q: What is the difference between the OSI model and the TCP/IP model? Which one does the internet use?

The OSI model has 7 layers and was designed by ISO as a theoretical reference framework. The TCP/IP model has 4 layers (Network Access, Internet, Transport, Application) and was designed based on protocols already working in ARPANET. The internet runs on TCP/IP. OSI is used for teaching, documentation, and troubleshooting frameworks. OSI layers 5 (Session), 6 (Presentation), and 7 (Application) all collapse into TCP/IP's Application layer. OSI layers 1 (Physical) and 2 (Data Link) collapse into TCP/IP's Network Access layer.

Q: What is the difference between HTTP and HTTPS at a protocol level?

HTTP (port 80) is a plaintext application-layer protocol. HTTPS (port 443) is HTTP running over a TLS session. The HTTP request and response format is identical in both cases — the difference is that in HTTPS, before any HTTP data is exchanged, a TLS handshake occurs (authentication via certificates, key exchange, cipher negotiation). After the handshake, HTTP data is encrypted at the Presentation layer before being passed to TCP. To a network observer, HTTPS traffic shows only encrypted bytes — the URL path, headers, and body are hidden (though the hostname is visible in the TLS SNI extension and DNS queries).

Q: What does the Presentation Layer actually do? Give concrete examples.

The Presentation Layer (Layer 6) handles three categories of data transformation:

  1. Encoding/decoding — converting between character sets (ASCII to UTF-8, UTF-8 to UTF-16)
  2. Serialization/deserialization — converting data structures to transmittable formats (JSON.stringify, protobuf encoding, XML marshaling)
  3. Encryption/decryption and compression/decompression — TLS for encryption, gzip/Brotli for compression

In Node.js: JSON.stringify() is serialization (Layer 6), Buffer.from(str, 'utf-8') is encoding (Layer 6), zlib.gzip() is compression (Layer 6). The HTTP verb, headers, and path are Layer 7.

Q: A "Layer 7 load balancer" vs a "Layer 4 load balancer" — what is the difference?

A Layer 4 load balancer operates at the Transport layer. It sees IP addresses and TCP/UDP ports, and routes traffic based on that information. It cannot read HTTP headers or URLs. It is fast because it does minimal processing.

A Layer 7 load balancer operates at the Application layer. It terminates the HTTP (or HTTPS) connection, reads the headers, URL, and sometimes the body, and makes routing decisions based on application-level data — for example, routing /api/* to one server group and /static/* to another, or routing based on a cookie or Host header. It can also do SSL termination (which is actually a Layer 6 operation). Layer 7 load balancers are more flexible but have higher processing overhead than Layer 4 ones.


Quick Reference — Cheat Sheet

Table 1: Layer 6 vs Layer 7 Comparison

AttributeLayer 6 — PresentationLayer 7 — Application
RoleData translation and transformationProtocol rules for application communication
AnalogyInterpreter converting languagesThe language itself being spoken
EncodingUTF-8, ASCII, Base64Not responsible for encoding
SerializationJSON, XML, protobuf, msgpackNot responsible for format
EncryptionTLS/SSL (conceptually)Not responsible for encryption
Compressiongzip, Brotli, deflate, zstdNot responsible for compression
MIME typesDefines how to interpret the payloadUses MIME type hints in headers
ProtocolsTLS, SSL, JPEG, MPEG, ASCIIHTTP, HTTPS, FTP, SMTP, DNS, DHCP, SSH
Key protocols (ports)TLS (no port — wraps others)HTTP:80, HTTPS:443, FTP:21, SMTP:25/587, DNS:53, DHCP:67/68, SSH:22
In TCP/IPCollapsed into Application layerApplication layer
Node.js examplesJSON.stringify, zlib.gzip, Buffer.fromhttp.request, fetch, nodemailer

Table 2: OSI to TCP/IP Layer Mapping

OSI LayerOSI NameOSI FunctionTCP/IP LayerTCP/IP NameExample Protocols
7ApplicationUser-facing protocols4ApplicationHTTP, FTP, SMTP, DNS, SSH, DHCP
6PresentationEncoding, encryption, compression4ApplicationTLS, gzip, JSON, protobuf
5SessionSession management, dialog control4ApplicationNetBIOS, RPC, NFS
4TransportEnd-to-end delivery, ports3TransportTCP, UDP
3NetworkRouting between networks2InternetIP, ICMP, IGMP
2Data LinkNode-to-node on same network1Network AccessEthernet, Wi-Fi (802.11), ARP
1PhysicalBits on the wire1Network AccessCables, fiber, radio signals

OSI vs TCP/IP at a glance:

  • OSI: 7 layers — theory, teaching, troubleshooting reference
  • TCP/IP: 4 layers — what the internet actually runs
  • OSI layers 5+6+7 → TCP/IP Application
  • OSI layer 4 → TCP/IP Transport
  • OSI layer 3 → TCP/IP Internet
  • OSI layers 1+2 → TCP/IP Network Access

Previous: Lesson 2.3 — Transport & Session Layers Next: Lesson 3.1 — IPv4 Addressing


This is Lesson 2.4 of the Networking Interview Prep Course — 8 chapters, 32 lessons.

On this page