If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Main content

Internet routing protocol

The Internet Protocol (IP) is the protocol that describes how to route messages from one computer to another computer on the network. Each message is split up into packets, and the packets hop from router to router on the way to their destination.
Diagram of laptop computer sending packet to server computer. A network of 9 routers is shown between the laptop and the server, with various lines connecting them. There's a path from the laptop, through the routers, to the server, highlighted with green arrows.
Let's step through the process of routing a packet from a source to a destination.

Step 1: Send packet to router

Computers send the first packet to the nearest router. A router is a type of computing device used in computer networks that helps move the packets along.
Diagram with laptop on left and router on right. Arrow goes from laptop to router, with message "TO: 91.198.174.192" and "FROM: 216.3.192.1".
You likely have a router in your home or classroom right now, and that's the first stop for your current computer's packets.

Step 2: Router receives packet

When the router receives a packet, it looks at its IP header. The most important field is the destination IP address, which tells the router where the packet wants to end up.
IP header
FieldContent
Source IP Address216.3.192.1
Destination IP Address91.198.174.192
Version4
Time to Live64
... plus 10 more fields!

Step 3: Router forwards packet

The router has multiple paths it could send a packet along, and its goal is to send the packet to a router that's closer to its final destination.
Diagram with router on left and 3 routers on right. The left router has a line going to each of the right routers, and the lines are labeled 1, 2, and 3. A question mark is shown above each line.
How does it decide? The router has a forwarding table that helps it pick the next path based on the destination IP address. That table does not have a row for every possible IP address; there are 232 possible IP addresses, and that's far too much to store. Instead, the table has rows for IP address prefixes.
IP address prefixpath
91.112#1
91.198#2
192.92#3
...
IP addresses are hierarchical. When two IP addresses start with the same prefix, that often means they're on the same large network, like the Comcast SF network. Router forwarding tables take advantage of that fact so that they can store far less information.
Once the router locates the most specific row in the table for the destination IP address, it sends the packet along that path.
Diagram with router on left and 3 routers on right. The left router has a line going to each of the right routers, and the lines are labeled 1, 2, and 3. The second line, labeled 2, is highlighted with green arrows going from left to right, and shows a packet above it.

Step 4: Final router forwards message

If all goes well, the packet should eventually arrive at a router that knows exactly where to send it.
IP address prefixpath
91.112#1
91.198.174.192Direct
192.92#2
...
The router can now send the message to the destination IP address, which may be a personal computer or a server.
Diagram with router on left side and laptop on right side. Arrow goes from router to laptop with packet displayed above it.

🙋🏽🙋🏻‍♀️🙋🏿‍♂️Do you have any questions about this topic? We'd love to answer—just ask in the questions area below!

Want to join the conversation?

  • old spice man green style avatar for user roarser2004
    How do routers get their routing table? Do they build it themselves or do they get it from some server or from other routers P2P style?
    (21 votes)
    Default Khan Academy avatar avatar for user
    • aqualine ultimate style avatar for user Martin
      Routing tables can be built in two ways. The first method is the manual one, you basically have a system administrator who enters possible routes.
      For the second method you basically use routing protocols (e.g. the OSPF - Open Shortest Path First) that automatically create and update a database of possible routes.
      (31 votes)
  • leaf red style avatar for user layaz7717
    In part 3, it says, "The router has multiple paths it could send a packet along, and its goal is to send the packet to a router that's closer to its final destination." Does that mean that different routers communicate with one another, and that your router is used to transport other people's data? Is so, how do they do so (e.g. wirelessly, which means that they would have to be close together)? Additionally, wouldn't that decrease the speed of routers in heavily populated areas, since they would be processing more information that routers in, say, rural areas?
    (12 votes)
    Default Khan Academy avatar avatar for user
    • aqualine ultimate style avatar for user Martin
      Routers work with each other, but those are public routers made for this purpose (think huge information hubs, a bit like airports for information). Running internet connections over private routers would be incredibly dangerous because anyone could just trap the message flow, then decode it or change it or just block it altogether.

      Transport happens over cables.

      Heavily populated areas have stronger internet infrastructure (much higher demand and of course business interests) which is why internet speeds in city areas tend to be much faster than in rural ones.
      (24 votes)
  • blobby green style avatar for user 6110008
    In the field of computer networks, what is a protocol?
    (1 vote)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user ankitrajput5618
    what if we send message to suppose ip 12.131.31.31 and he change his network ,will he recive message .if so then how?
    (8 votes)
    Default Khan Academy avatar avatar for user
    • aqualine ultimate style avatar for user Martin
      If you tell your system to send packets to a specific IP it will try to do that. Identifying that it got the wrong recipient is too complex of a task and trying to actually look for the targets new location would be like randomly running through a large city and trying to find a package recipient by just yelling their name.
      (16 votes)
  • leaf red style avatar for user layaz7717
    What does, "If all goes well, the packet should eventually arrive at a router that knows exactly where to send it.
    The router can now send the message to the destination IP address, which may be a personal computer or a server," mean?" How would some routers know exactly where to send it, but others don't?
    (4 votes)
    Default Khan Academy avatar avatar for user
    • aqualine ultimate style avatar for user Martin
      Not all routers contain all the information, that just wouldn't be feasible. Imagine it like each router knows what happens in its area, so if one router doesn't know where the target is it sends you to the router that's in the general area and therefore should know where to send information.

      It's like someone might know where the east side of the city is, but they have no idea where 123 Main Street is located. So they give you directions to the east side and once you're there you have to find someone to give you directions to 123 Main Street.
      (14 votes)
  • old spice man blue style avatar for user William Pan
    this is too much
    (9 votes)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user fowlerr
    So, I often hear the term "Subnet table" associated with routing protocols. What is a subnet table?
    (5 votes)
    Default Khan Academy avatar avatar for user
  • winston default style avatar for user Jcim Grant
    Can you plug an Internet Routing Protocol in a TV Cords?
    (4 votes)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user AlexS
    how to get a 5 on ap exam
    (4 votes)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user Tingco, Ariene M.
    What is the best description of how routing works on the Internet?
    (3 votes)
    Default Khan Academy avatar avatar for user