DEV Community

Ben Halpern
Ben Halpern Subscriber

Posted on

Explain TCP like I'm five

I understand Transmission Control Protocol (TCP) on some levels, but I feel like I never learned the concepts all that concretely. Can someone give me a really good overview?

Top comments (38)

Collapse
 
georgeoffley profile image
George Offley

You and a friend need to share a toy:

  1. You ask a friend if he can play with the toy.

  2. Your friend asks you if you actually asked him for the toy.

  3. You tell your friend that you asked for that toy.

  4. He gives you the toy.

UDP:

  1. Your friend throws a toy at you and walks away.
Collapse
 
antoinette0x53 profile image
Antoinette Maria

The UDP example has me DYING. That's hilarious

Collapse
 
georgeoffley profile image
George Offley

UDP is inherently funny.

Collapse
 
theodesp profile image
Theofanis Despoudis

Maybe a more accurate description will be:
Your friend throws a toy at your direction thinking that it will hit you eventually and walks away.

Collapse
 
georgeoffley profile image
George Offley

You're explaining it to a five year old. The less nuance the better.

Collapse
 
ino76 profile image
JsonKody • Edited

it's exactly the same information but with more words ;)
(adding info about what he is thinking which is not inherently important)

Collapse
 
hawarioware profile image
Wajdi Al-Hawari • Edited

I have a five year old. There is nothing beyond this that should be added. You're fantastic. Do you have a five year old? Because this is spot on.

Collapse
 
georgeoffley profile image
George Offley

I don't, mostly for the reason above. :)

Thread Thread
 
hawarioware profile image
Wajdi Al-Hawari

lol. Fair. :)

Collapse
 
kelfink profile image
Kevin Fries

Well, maybe it's your friend. And it's probably s ball.

Collapse
 
brovic profile image
Victor Ordu

ROTFL!!!

Collapse
 
dennisfen profile image
Denis Borisevich • Edited

Not an overview but for the sake of completeness this old joke must be on this thread:)

Hello, would you like to hear a TCP joke?
Yes, I'd like to hear a TCP joke.
OK, I'll tell you a TCP joke.
OK, I'll hear a TCP joke.
Are you ready to hear a TCP joke?
Yes, I am ready to hear a TCP joke.
OK, I'm about to send the TCP joke. It will last 10 seconds, it has two characters, it does not have a setting, it ends with a punchline.
OK, I'm ready to hear the TCP joke that will last 10 seconds, has two characters, does not have a setting and will end with a punchline.
I'm sorry, your connection has timed out...
...Hello, would you like to hear a TCP joke?

Collapse
 
bgadrian profile image
Adrian B.G.

A group of kids are trying to talk into the school yard.
They need a technology so simple that would allow communication even if one kid left the circle. They were already talking into tin cans, so they invented the strings (TCP).

On a serious note, a good history lesson on why and how HTTP and TCP/IP was created Jeremy Keith

Collapse
 
owenandrews_ profile image
Owen Andrews

I could tell you a joke about UDP but you might not get it.

Collapse
 
anthonylavado profile image
Anthony Lavado

Telling this joke in an interview is what got me my current job.

Collapse
 
ben profile image
Ben Halpern • Edited

Collapse
 
daveblythe profile image
Dave Blythe (he/him)

Really, Ben? THIS is the one that bothered you, lol?

Collapse
 
jacoby profile image
Dave Jacoby • Edited

I took networking in college, and then a bunch of us went to a coffee shop with free refills, so I always demonstrate network packets with sugar packets.

Let us contrast it with UDP. Imagine you're behind me and ask for a sugar packet. I grab one and throw it over my shoulder. It's not my responsibility to throw it to you, and I don't care if you get it. If you're where I think you are, you can ask for more and more, getting enough sugar to sweeten everyone's coffee, which is why UDP is often used for video, but dropped sugar stays dropped.

TCP has the "three-way handshake", which is more like:

I would like a sugar packet

I heard you ask for a sugar packet

I did ask for a sugar packet

Here's the sugar

This way, the sugar packets don't end up all over the floor.

Collapse
 
galdin profile image
Galdin Raphael

If sugar is the data, shouldn't it be handed over after the three way handshake?

Collapse
 
ben profile image
Ben Halpern

So how much sugar do I get to ask for in the first trip to the counter and each subsequent trip, and why is this so?

Collapse
 
tbd profile image
TBD

you ask for sugar and the server starts a session where he sends a numbered sugar sachets (TCP frames) and you confirm the delivery of each sachet (based on checksums) and as @gldraphael said the sugar arrives after the handshake

Thread Thread
 
ben profile image
Ben Halpern

And if I understand correctly, the barista will give give me one packet on the first trip, then two, then four, etc. and in data terms, each packet is about 14k in size.

Collapse
 
jabranr profile image
Jabran Rafique

Is TCP British? It sounds like one from the conversation flow.

Collapse
 
0x424c41434b profile image
0x424c41434b

I think additionally I could try and expand on this.

TCP is built on

Network Layer connection = how are we physically transporting this sugar
Internet Layer = Who is exchanging this sugar
Transport Layer = Which cup is this sugar going to

Network layer = responsible for physically transporting this data which is (e.g)
someone walking over or even throwing over the sugar to the person that is requesting it.
This can come in many forms such as ethernet or wifi(simplified). Are you throwing the sugar or are you physically walking there.

Internet Layer = You need to know where these packages are going, These layers usually have frames that contain destination IP and source IPs.
The source IP would be where the packet or sugar is coming from(which person) and where the packet should go destination IP(where the sugar is going)
This would be from a host to host level, we do not know which of the cups the sugar is going into

Transport Layer = Imagine the person asking for the sugar has got three cups. We need to know which cup the sugar is going into. for this purpose we describe the cups as having their port addresses.
Putting the sugar into the designated cup would be transporting from an process to process level transportation.

Transport layer will have different methods of transporting the sugar as it was mentioned. Which would be where I would reference the first comment posted of UDP vs TCP

Collapse
 
ben profile image
Ben Halpern

What's the technical purpose for differentiating the Internet Layer and the Transport Layer? Why can't one "layer" handle IP and ports?

Collapse
 
0x424c41434b profile image
0x424c41434b

I am not sure of any accepted answer but one reasoning for this separation would be for applications that only implement up to one layer.

If there is a router that only implements up to the internet layer(because it doesn't need port control up to that point) it would easily be able to implement this functionality up the internet layer only.

This also proves the same for software that would only implement up to the network layer such as old switches

Thread Thread
 
antoinette0x53 profile image
Antoinette Maria

I agree with this. I'd also expand on this and say that different devices "unwrap" different layers of a packet. So yeah, it wouldn't necessarily make sense for an edge router to care what port is needed. It just needs to know where to send the packet (IP) and the target machine handles the rest.

Collapse
 
tgiddings profile image
Trevor Giddings

separating out being able to figure out where a packet goes (internet layer) from anything about it's contents and purpose (transport layer) allows the infrastructure of the internet to be much simpler. It also means that only the machines communicating with each other need to be concerned with what's being sent and why, and developers can create new transport protocols tailored to their use (though this is usually not a good idea since people end up creating a nock-off tcp).

as an analogy: if the transport layer is the methodology for deciding when and how to chuck packets at each other, the internet layer is the muscles in your arms. They only need to be specialized enough to move the arms. They don't need to be concerned with the manner of packet chucking, nor should they be in case you want to chuck packets differently.

Collapse
 
jacoby profile image
Dave Jacoby

Layers of misdirection, and I might have to redo this before I can get to the five-year-old level.

My group is in the coffee shop, and there's enough people to require a few tables, and my table runs out. The people at my table know me, and know Dave = "seat nearest the bathroom". This part is MAC address to to IP address, which is done by Address Resolution Protocol, or ARP, and you can use computers your whole life without caring about this.

But next table over doesn't know me or where I sit, so when you ask them (serving as gateway) to pass some sugar, it is the job of the IP layer to handle the sugar-to-table part and the transport to know who to pass it to here.

Plus, on some tables, people just pass left, or right, but some might throw it right to me over the air. Actually, "how it goes" is more the job of transport layer, although which-one's-Dave is part of that.

Collapse
 
galdin profile image
Galdin Raphael

I'd suggest you watch this and the next video on the playlist: youtube.com/watch?v=4IMc3CaMhyY&li...

A 5 year old might not understand that, but it'll give you a better overview of how TCP works. For better context read on TCP's features (flow-control, stream and connection oriented, etc.) first.

Collapse
 
ben profile image
Ben Halpern

Thanks, looks great.

Collapse
 
themikenicholson profile image
Mike Nicholson • Edited

Imagine you ask a friend to read you a long number over the phone. If you wanted to get this done really quickly your friend could just read all the numbers off as fast as possible. This might work, but maybe an ambulance drives by and you don't hear a few numbers, or maybe you can't write all the numbers down fast enough.

Naturally, you're going to ask your friend to read you a few numbers at a time and you'll let them know when they can proceed with the next ones. This sort of an informal implementation of TCP.

To extend the metaphor image the conversation goes like this:

You: Call your friend at his well known phone number
Friend: Answers phone, says hello
This is like the initiation of a TCP connection, instead of phone numbers TCP uses IP addresses and port numbers. Much like our normal phone etiquette, TCP/IP specifies a protocol, a very clear set of rules on how you connect and start the TCP conversation

You: "Ok, what is the first group of numbers?"
Friend: "1234"
You: "Ok, keep going"

This is like a TCP ACK which acknowledges successful receipt of the first bit of information. You just acknowledged you heard your friend and they could now continue transmitting the next chunk of information

Friend: "5678"
You: "Sorry, I missed that, we have a flaky connection. Can you please repeat the second group"
Friend: "5678"
You: Ok, got it, keep going
This was like a TCP retransmission. Something happened and you detected that you missed a bit of information, you ask your friend to repeat it

In this example, your friend is sending a few chunks of information at a time and you're ensuring you clearly receive everything and in the right order. While this might take a little longer than your friend rambling off the number as fast as possible, you're much more likely to correctly receive the number.

Obviously TCP is much more complex and well specified than an informal phone conversation. Computers need much clearer instructions than humans to complete any task. The underlying principles are the same though.

edit: typo's

Collapse
 
tmr232 profile image
Tamir Bahar

TCP is all fun and games until you start doing SACK (Selective ACK).

I am going to start handing you boxes. The boxes are numbered.
Your role is to drop the boxes into a hole in ground in order, based in the numbering.
When I give you a box, you read the number back to me.
If you are missing a number (I didn't give you that box, but I gave you a later one), tell me which is the one I gave you, and which is missing.
Keep doing that for arbitrarily many boxes.
If the boxes get too heavy, or if you feel it is a good idea, you can throw away the out-of-order boxes, and tell me which ones you kept.
I will try and only hand you boxes that you need, but I might send you duplicates now and then if you did not reply fast enough.

Collapse
 
asknbid profile image
¥§¥Stephan Froede¥§¥

TCP:

You need to ask mom and dad to get a toy. And only if you pay for the toy, and mom and dad do agree, you will get the toy.

UDP
Somebody is gifting you a toy.

Conclusion:
5 year olds love UDP