The Presentation Layer, Explained

UPI Study › Courses › Introduction to Operating Systems › Free lessons › Lesson 7.5 Free with a free account

The Presentation Layer

Introduction to Operating Systems · Chapter 7: Computer Networks: Architecture, Layers, and ProtocolsSection 7.5 · lesson 60 of 838 min · free with a free account

← The Network Layer and IPNext lesson: The Transport Layer →

A free account plays all of Chapter 1 and 3 more lessons of Introduction to Operating Systems. Create a free account →

Earn 3 college credits for Introduction to Operating SystemsRecommended for credit by NCCRS · Computer Science 354 · self-paced · one payment, lifetime access

In this lesson

How data is encoded, compressed and encrypted before it travels.

  • Explain the presentation layer's three jobs: encoding, compression and encryption
  • Count the UTF-8 bytes in text with accented letters and explain garbled characters
  • Apply run-length encoding and explain why random data does not compress
  • Compare symmetric and public-key encryption and explain why toy ciphers are weak

Free study notes

Get this lesson's notes by email

The key points and 4 practice questions with answers, in your inbox. One email, free.

One email. Unsubscribe in one click.

Transcript

Everything said in the video, section by section (1,095 words). Read along, or search it.

Opening Puzzle

A Garbled Crème Brûlée Order

A customer abroad orders a crème brûlée cupcake from Sam, who runs a small online bakery. But on Sam's screen, the order reads like this. Nothing was lost on the wire. Both computers read the same bytes, but with two different tables. The presentation layer exists to prevent mix-ups like this. It also shrinks data, and keeps it private, on its way.

Three Jobs

Encode, Compress and Encrypt

Layer 6, the presentation layer, takes what the application wants to say, and makes it fit to travel. Think of mailing a gift. You write the note in a language the reader knows: that's encoding. You vacuum-pack the gift so it takes less room: compression. And you lock it in a box: encryption. The receiver undoes the three jobs in reverse: decrypt, decompress, then decode. In the real world, the TCP/IP model has no separate presentation layer. Apps and libraries do these jobs, like a browser decoding text.

Character Encoding

ASCII, Unicode and UTF-8

Start with encoding. A network carries only bits, so every letter must become a number. A character encoding is the agreed table. The old table, ASCII, has 128 characters: English letters, digits, punctuation and some control codes. It has no room for accents, other alphabets, or emoji. Unicode gives every character in the world's writing systems its own number. And UTF-8, the most common way to write those numbers as bytes, uses one byte for each ASCII character, and two, three or four for the rest.

Worked Example

Five Bytes for Four Letters

Here's a short Python program that encodes the word café, accent and all. It turns the word into UTF-8 bytes, prints each letter with its number and its bytes, then reads the bytes back with two different tables. Run it. Four letters. The plain letters c, a and f take one byte each: 99, 97 and 102. But é is number 233, and UTF-8 writes it as two bytes: 195, then 169. So four letters need five bytes. Read back as UTF-8, the word is fine. But read the same bytes with the Latin-1 table, and é turns into two odd symbols. That's Sam's bug, in miniature. And the last line says café isn't pure ASCII: 233 is past ASCII's last code, 127. Now change one thing. Make the word crème, and run it again. Five letters, six bytes. And the Latin-1 reading turns è into the same kind of garble, the one Sam saw on screen.

Quick Check

Counting Bytes in Jalapeño

Quick check. Sam adds jalapeño cornbread to the menu. This program counts the letters, and the UTF-8 bytes, of the word jalapeño. How many bytes: eight, nine, or sixteen? Pause and predict. Nine. Seven plain letters take one byte each, and ñ takes two. Eight is the trap: it counts letters, not bytes. When a limit is in bytes, like a text field or a packet, accented letters and emoji take more than one.

Compression

Lossless Versus Lossy

Next job: compression. Data on a network costs time, so smaller is better. Compression removes repetition, so the same information takes fewer bytes. It's lossless when the original comes back exactly, as with ZIP files and text. It's lossy when some detail is thrown away for good, as with many photo, music and video formats.

Run-Length Encoding

Counting Runs of the Same Value

The simplest lossless method is run-length encoding: store each run of the same value as a count, then the value. This function walks along the text. For each run, it finds where the same letter stops, then writes down the count and the letter. The row is one line of a black and white picture: ten white, four black, then ten white. Run it. Twenty-four characters become just eight.

Quick Check

Do Not Forget the Last Run

Quick check. Here's a new row, for the same function. What will it print for this row? Pause and predict. 3B8W1B: three B, eight W, one B. The count comes first, then the value. 3B8W forgets the last run. That single B at the end is a run too, a run of one.

Real Compressors

DEFLATE Shrinks Repeats, Not Randomness

Real compressors are cleverer. Python's zlib uses DEFLATE, the method inside ZIP files, which replaces repeats with short references to earlier text. Sam's menu repeats the same three words sixty times: thirteen hundred eighty bytes. Run it. The menu shrinks to just forty-four bytes, and unzips to exactly the original. But random bytes have no pattern to remove. A thousand of them don't shrink at all. They even grow a little, to one thousand eleven. That's why data is compressed before it's encrypted. Encrypted data looks random, so there's nothing left to squeeze.

Encryption

Symmetric and Public-Key Encryption

The third job is encryption: scrambling data with a key, so only someone with the right key can read it. The readable original is the plain text. The scrambled result is the cipher text, and that's all a listener on the wire can see. In symmetric encryption, both sides share one key. In public-key encryption, two linked keys work as a pair: one locks, and the other unlocks. So strangers can send locked messages without swapping a secret first. Web addresses that start with https use both kinds together. Lesson 8.7 says more.

Toy Cipher

A Shift Cipher With Only 26 Keys

Here's a toy, just to show the idea of a key. It shifts each letter along the alphabet by the key. Never use it for anything real. It seals Sam's order with key 3, then tries the right key, and a wrong one. Run it. The cipher text is gibberish. The right key brings the order back, and the wrong key gives more gibberish. But this toy is weak. A shift cipher has only 26 keys, so an eavesdropper can simply try them all, in seconds.

Real Ciphers

AES and Trusted Libraries

Real ciphers, like AES, use keys of 128, 192 or 256 bits: far too many to try. Their designs are public, and checked by experts. So use a trusted library, and never invent your own.

Real Example

Switching the Shop to HTTPS and UTF-8

Back to Sam. Customers sometimes send phone numbers with their orders. So Sam asked Ivy, who looks after the computers at a school: can anybody read those on the wire? On plain http, yes, Ivy said. On https, the data is encrypted before it leaves, so a listener sees only noise. Sam switched the shop to https that afternoon. And the crème brûlée? The fix is agreement. The shop's pages now declare UTF-8, so both sides read the bytes with the same table.

Key Takeaways

Same Table, Smaller Data, Locked Data

To recap. The presentation layer has three jobs: encode, compress and encrypt, undone in reverse at the other end. UTF-8 writes plain letters in one byte, and others in two to four. Both sides must use the same table. Lossless compression removes repetition, but random data won't shrink. And encryption locks data with a key. Use real, tested ciphers, never toys.

About Introduction to Operating Systems at UPI Study

Introduction to Operating Systems (Computer Science 354) is a self-paced online course of 83 video lessons in 10 chapters, from what an operating system does and process scheduling to concurrency, memory, devices, file systems, networks, the internet, security and virtual machines. It carries a NCCRS credit recommendation for 3 semester credits.

Every lesson transcript is free on pages like this one, and the videos are free with a free UPI Study account. Enrolling adds a practice quiz after each lesson, the graded work and final exam that earn the credit, lifetime access, and an official transcript on completion. UPI Study has helped over 130,000 students with college credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Compare: Linux vs Operating Systems

Why take it here

Why students take Introduction to Operating Systems with UPI Study

What happens under every app you runIntroduction to Operating Systems explains the software that runs a computer: processes and scheduling, threads and synchronization, deadlock, memory and paging, devices and storage, file systems, networking, security and virtualization. It suits computer science and information technology degrees.
Credit at a fraction of the priceThe same 3 credits can cost $750 or more at a US college. Here it is one payment, self-paced, with lifetime access.
Finish your degree soonerTransfer credits reduce the courses you still owe, so you can graduate earlier or lighten a heavy semester.
Strengthen an applicationA completed college-level course on an official transcript shows admissions and scholarship committees you can do the work.
Study on your own scheduleNo start dates, no deadlines. Watch the lessons, practice, and take the final when you are ready.
130,000+students helped with college creditsACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Where the credit goes

Universities that work with NCCRS

Introduction to Operating Systems carries a NCCRS credit recommendation. These universities work with NCCRS; some are UPI Study's signed partners. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Find my college → Not listed? Ask Athena in the corner of this page, or book a 15-minute call.

FAQ

Questions students ask us

About The Presentation Layer

What is the difference between ASCII and UTF-8?
ASCII is an old table of 128 characters covering English letters, digits, punctuation and control codes, while UTF-8 is a way to write any Unicode character as bytes. UTF-8 keeps each ASCII character as the same single byte and uses two, three or four bytes for other characters, such as accented letters, other alphabets and emoji.
Why do accented letters show up as strange symbols?
Garbled accents usually mean the text was written in one character encoding and read with another. For example, é in UTF-8 is the two bytes 195 and 169, and a program reading them with the Latin-1 table shows two odd symbols instead of one letter. Declaring UTF-8 on both sides, such as in a web page's settings, makes the bytes read back correctly.
What is the difference between lossless and lossy compression?
Lossless compression brings back the original data exactly, while lossy compression throws some detail away for good to save more space. ZIP files and compressed text are lossless, which matters for documents and programs. Many photo, music and video formats are lossy, because small losses there are hard to notice. Data with no pattern, such as random bytes, does not shrink with lossless methods.
Why is data compressed before it is encrypted?
Data is compressed first because encrypted data looks random, and random data has no repetition left to remove. Compression works by replacing repeats with shorter references, so it needs the patterns that encryption hides. In one test, 1,000 random bytes grew slightly to 1,011 bytes after compression with Python's zlib, while a repetitive 1,380-byte menu shrank to 44 bytes.

About the Introduction to Operating Systems course

How many college credits is Introduction to Operating Systems?
Introduction to Operating Systems (Computer Science 354) carries a NCCRS credit recommendation for 3 semester credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
How much does Introduction to Operating Systems cost and what is included?
$250, paid once, with lifetime access: all 83 video lessons, a practice quiz after each, the graded work and final exam, and an official transcript when you finish. Students who want several courses choose UPI Study PRO instead.
Which universities accept UPI Study credits?
UPI Study has signed partner agreements with universities such as Thomas Edison State University, University of the People and Charter Oak State College, and works with universities such as Penn State, SNHU and SUNY. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities. Use "Find my college" on this page to check yours.
How long does Introduction to Operating Systems take?
It is self-paced with no deadlines. The 83 lessons total about 10 hours of video; most students add reading and practice time and finish in a few weeks to a few months, on their own schedule.
How are the exams done?
Quizzes and assignments are online in the course. The final exam is taken online with proctoring; a person on the UPI Study team checks assignments, usually within two days.
How do my credits reach my college?
When the course shows 100% complete, request the official transcript from your dashboard. It is sent to the college you name, and you can send it to more than one. Check your college first with "Find my college" on this page, or ask Athena.

Ready for the full course? Earn 3 credits in Introduction to Operating Systems.

83 video lessons, a quiz after each one, and the graded work that earns the credit. Recommended for credit by NCCRS.

Updated

Introduction to Operating Systems
3 credits · NCCRS
Enroll →