Let’s Talk Tech: How the Internet Works Part 3: Subnet Routing
Welcome to the third episode of our new Let’s Talk Tech series: How the Internet Works! Building off last month’s episode, once a packet is broken down into fragments, subnet routing is used to get the packet to its destination. Dr. Deep Core (John Brewer), explains it all below.
Full transcript is below the video. Enjoy!
Introduction to Subnet Routing
Hello, and welcome to Let’s Talk Tech with Deep Core Data. I’m John Brewer, the owner and Founder here at Deep Core, where we’re using education to help companies make the right tech choices. In this series we’re going to be covering, at a technical level, how the Internet works.
We’ve been discussing the different aspects of IPv4, including the IPV4 packet and fragmentation. Basically, what it takes to address and package data. But what happens when we actually hand that packet to a router? Does it just magically appear on the other side of the world? Obviously not. Just like in the non-digital world, it needs a delivery service. Today we’re going to be talking about IPv4 Subnet Routing.
We’ve talked before about how IP packets are essentially letters getting mailed around the Internet from address to address. Or as large data shipments, being broken down and reassembled at their destination. But who carries those letters? Who delivers them? And how do we make sure they get to a particular address?
Every router on the Internet essentially has two things: a gateway to the “public” internet, and one or more “subnets”. Think of the Internet as the world, a network as a city, and a subnet as the postal codes in that city. On most modern equipment, the public network is called the WAN, or Wide-Area Network, and the subnets are called LANs, or Local Area Networks.
When a router receives a packet, it checks to see if it is going to any of the subnets it knows about. So like when a city distribution center receives a letter, it then decides which of the local post offices can deliver it, if any. If it’s one of the local zip codes, the router sends the packet to that subnet to be delivered.
If no subnet contains the destination address, it sends it back through the gateway to the public network, where a higher-level router will repeat the process. For example, as a city is broken up into different zip codes, so our virtual letter is moved around until the right zip code in that city is found. Eventually, the packet will reach a router that can send it into the subnet that contains the correct destination machine.
To start with, I’m going talk about how routing works for computers connected directly to the Internet. In other words, computers that have a public IP address that can be routed to from anywhere in the world. Think of these as your Internet Service Providers; your Verizons or AT&T, the big guys.
Most home and business computers don’t have a public IP address; they use what’s called Network Address Translation to get onto the Internet, since IPv4 is running out of addresses. Your internet provider essentially sublets you an address, so if your provider is an apartment building, your local network is the apartment itself; an address within a bigger address.
Network Address Translation, or NAT, is a very important topic and we’ll be covering it in a future video, but for now, just understand that if your IP address starts with 192.168 or 172, or 10, you have an extra layer in your network.
Let’s say I’m sending a packet from my computer at 188.8.131.52 to a computer down the hall at 184.108.40.206. My computer is a host, which means it has three things: an IP Address to identify what it is, a subnet mask (which is an operation that identifies which computers it can send to directly), and a gateway to send any packets it can’t send to directly.
Using our mail analogy, the letter goes from the distribution center, to the local post office, is handed off to the carrier, and then delivered to the apartment complex and finally, the corresponding apartment.
So let’s go into detail. Now, we’ve talked before about how an IP address is just 4 bytes, or 32 bits. If we write out the IP address in binary, we get 32 1’s and zero’s. So because my machine’s IP address is 220.127.116.11, in binary, it looks like this: (display on screen) 01100010 01100100 01100100 00000100. The subnet mask is also another 32 bit binary number, but its use is different.
Think of the subnet as being the apartment number on our virtual apartment building. The subnet mask helps figure out the right number.
When we send out a packet, we do what’s called a bitwise operation. Now, a bitwise operations is essentially a function that we perform on two binary numbers or bit patterns. In this case, we’re doing an AND operation, which is when we take two equal-length binary string and multiply them by each other.
So let’s suppose I had a subnet mask of 255.255.255.0, which is quite common. This essentially says that if the first three numbers of my IP address are the same as the first three numbers of my destination IP address, then no routing is required at all. In our example, if I was sending a packet from 18.104.22.168, I would apply my subnet mask to get 22.214.171.124.
Then I would apply my subnet mask to the destination IP address, 126.96.36.199, and I would also get 188.8.131.52. That tells me that my destination is on my subnet, and no routing is required. I can just send the packet directly to the destination.
What if I want to send a packet to 184.108.40.206, which is in another office, but still on the local network? When I run that through the subnet mask, I get 220.127.116.11, which is not the same, so I need to send the packet to my gateway. In this case, my gateway is a router. Let’s say my router has the IP address of 18.104.22.168 (it has to be on my subnet, otherwise I can’t send to it). Actually, my router has a bunch of different IP addresses, because it’s attached to a bunch of different subnets, but 22.214.171.124 is the address my computer knows it by.
My router knows about my subnet, where it is known as 126.96.36.199, and it knows about the other subnet, where it is known as 188.8.131.52. On both subnets, it has a subnet mask of 255.255.255.0. It checks to see if it can route to 184.108.40.206, and compares the subnet masks of its IP and the destination IP. Its subnetted IP is 220.127.116.11 on that network, while the destination IP is 18.104.22.168, so it knows that’s not the right subnet. It moves on to the next subnet, where its subnetted IP address is 22.214.171.124, and the destination’s subnetted IP address is 126.96.36.199. It has a match! It sends the packet down to the switch in that office, which delivers the packet to the destination machine.
We’ve talked about subnets on our local network, but what if an IP address is not found? The router does a bitwise AND between the destination IP address and the subnet mask, and a bitwise AND between our IP address and the subnet mask. If the result of both bitwise ANDs is the same, then the destination is on the local network. If they don’t match, then the destination machine is not on our subnet, and we send the packet to our local gateway to be routed to the broader internet.
So, let’s examine the case where I send a packet to the outside internet, like say… Facebook at 188.8.131.52. My local machine applies its subnet mask, and determines that 184.108.40.206 does not equal 220.127.116.11, and sends the packet to my router. My router determines that 18.104.22.168 does not equal 22.214.171.124, or 126.96.36.199, so it can’t route the packet and sends it up to its gateway at my ISP. My ISP has no idea, so it sends it on to Verizon, who sends it on to Facebook.
That, in a nutshell, is what routing is; a router receives a packet, and either sends it to one of the subnets that it knows about, or it sends it up to its gateway.
The observant (or possibly experienced) viewer might asking a couple different questions at this point. “How do the packets get ‘sent directly’ from one machine to another?” “How do switches and hubs know where to send these packets?” and “How do MAC addresses fit into all this?” For those viewers, we have two other videos: one on ethernet, and one on Address Resolution Protocol.
But that wraps up our high-level review of how IPv4 subnet routing. I hope you enjoyed this episode of How The Internet Works. If you liked what you saw, please subscribe. If you have questions or suggestions future episodes, please leave a comment below.
I’m John Brewer for Deep Core Data. Thanks for watching!