what the f*ck is the internet? - vol. 1
TRANSCRIPT
What The F*ck Is The Internet?Vol 1: Bits, Encoding, Packets, and Protocols
Alex C. Viana (@AlexVianaPro)
Motivation: To Understand* How Networks WorkPhysics background → understand* how electronics work
Dev experience → understand* how software works
… everything in the middle is kinda ¯\_(ツ)_/¯
So this is me trying to fill in the gaps.
Everything I Previously Knew About NetworksData is digital (0’s and 1’s)
IP addresses are a thing
The internet exists
Sometimes computers are called “nodes”, this is usually about where I get lost
Sometimes people say the word “sockets” when explaining things to me
The PlanThere’s a lot of hand waving here, but I suspect this is the case for a lot of people.
So, with apologies to the devops who live and breath this stuff…
Let’s just start from the bottom and work our way up!
Bits, Bytes, and EncodingStarting from the bottom
Binary: 0’s and 1’sThe atomic unit of digital data is a “bit” which can either a 0 or a 1.
Everything digital, from Snapchat, to webpages, to Matchlight, is composed of bits.
The only reason bits can convey any information is because we have conventions
about what sequences of bits mean.
Binary: Numbers Other Than 0 or 1All integers can be represented in binary as some combination of the powers of 2:
1, 2, 4, 8, 16, ...
For example, here are all the numbers you can make with 2 bits:
00 (binary)= ((2 x 0) + (1 x 0)) = 0 + 0 = 0 (decimal)01 (binary)= ((2 x 0) + (1 x 1)) = 0 + 1 = 1 (decimal)10 (binary)= ((2 x 1) + (1 x 0)) = 2 + 0 = 2 (decimal)11 (binary)= ((2 x 1) + (1 x 1)) = 2 + 1 = 3 (decimal)
This is just a convention, there is no magic here.
Binary: Bits into Bytes8 bits together are called a byte:
10000001 (binary) = 129 (decimal)
This is where we get the terms we use for the size of data:
Kilobytes = 1,000 bytesMegabytes = 1,000,000 bytesGigabytes = 1,000,000,000 bytes
Ok so we can make numbers, but what else?
Binary: From Numbers to LettersSimilarly, by convention, numbers (in binary), can be mapped to letters, according to a
convention, called an encoding:
Binary Code | ASCII Code | Letter 01000001 | 065 | A 01000010 | 066 | B 01000011 | 067 | C
The convention above is called ASCII but there are others, such as UTF-8.
Computers have to agree/understand (in binary) what encoding is being used.
Binary: What’s Next? So you’re a computer. You’re sitting on a network. You get sent this:
11100011 10101101 01001110 00110100 00010000 01001011 01000000 01010001 10111001 00100100 01001101 10100101 11100010 10001011 01011101 00011111 00100000 01001100 11101111 11000011 11010000 01110100 10111001 00101100
Is this a series of letters? Is this a huge number? Something else? What now?
Protocols and PacketsMaking sense of bytes
Protocols: How Computers CommunicateIn the same way encodings allows us to turn bits into letters, another type of
convention, a protocol, allows us to make sense of the bits over a network.
There are lots of protocols, you can even write your own.
Packets: The Atomic Unit of a NetworkData is sent over a network in sequences of bits called packets
Packets typically have a header, which is metadata, and a payload, which contains the
data.
Let’s look at a header from a common type of protocol called IP (Internet Protocol)
Packets: Internet Protocol Header
IP Headers: VersionThe 1st 4 bits of an IP packet header are used to identify the IP protocol version.
This can be either IPv4 or IPv6, encoded by convention as a 4 or 6 in binary.
IPv4 : 0100 : 0 + 4 + 0 + 0 = 4IPv6 : 0110 : 0 + 4 + 2 + 0 = 6
Note that there is “room” in a 4-bit sequence for numbers up to 15.
The next header field implicitly begins at the 5th bit. There is no comma or period or
space.
IP Headers: AddressesThe source and destination address are 32-bit words that encode the IP address of the
sender and the receiver.
01001010011111010010101101100011 = 1249717091
While the above is technically correct, a 32-bit IP address is understood be composed
of 4 bytes (8-bit words). Adding dots for clarity:
01001010.01111101.00101011.01100011 = 74.125.43.99
This is just to emphasize that it’s the context of the protocol that gives the bits their
meaning.
IP Headers: IP AddressesAn IP address uniquely identifies a machine on a network.
In an IP header the Source and Destination Address fields tell every computer that
interacts with a packet where it is coming from and where it is going.
What happens next depends on the role of the machine in the network. This could be
as easy a printing from the printer right next to you or as complex as fetching a
webpage from Australia.
IP Headers: ProtocolThe protocol header is an 8-bit word that specifies the protocol used in the data
portion of the packet.
Using the same pattern as with letters, binary values map to decimal values which map
to a table of values, this time a table of possible protocols.
But isn’t the protocol already the IP protocol?
The Internet Protocol SuiteIt’s turtles all the way down!
The IP Suite: LayersThere are lots of protocols!
Protocols that serve roughly the same
purpose in a network are organized
into layers.
Layers work together to relay
information across a network.
This is also called the OSI model
The IP Suite: EncapsulationProtocols work together by completely
encapsulating packets as they move
between layers.
A packet (header + data) will be
encapsulated as a data in a new packet
with a new header appropriate for that
layer.
So an IP header, the protocol field
encodes the type of packet
encapsulated in the IP data.
SummaryAll digital data is just 0’s and 1’s
Conventions allow us to encode more complicated information as bits
Packets are digital data sent over the network
The contents of the bits in a packet are governed by protocols
Packet headers tell computers what the packets contain and what to do with them
This is the foundation of network communication
Future WorkI’m probably going to make more networking presentations as a way to teach myself.
Right now I’m really interested in what I see as the next step in this process: routing
and sockets.
That is what machines do with IP packets and how.
Also, interested how IP layers interact.
Thanks!