The Simplest Example You Have Ever Seen
Let's say we have four subnets in our network named A, B, C, & D
Now let's say they are arranged in just that order
A can ping B B can ping C C can ping D
Now let's say (lot's of let's says in this example) that Subnet A is hooked up to the Internet.
So now we have:
Internet ← → A ← → B ← → C ← → D
Packet Coming In
So, what happens when a packet from Subnet X comes into our network destined for a client on Subnet D?
First, Subnet X Packet asks Subnet A "Where is Subnet D?".
Subnet A says "Not sure, but I've got a route that says Subnet B knows".
Subnet X Packet goes on to Subnet B and asks the same question again.
Subnet B says "Not sure, but I've got a route that says Subnet C knows".
Subnet X Packet goes on to Subnet C and asks one more time.
Subnet C says "Subnet D is right here"
Subnet X Packet is a happy little camper.
Packet Going Out
Now, the client on Subnet D sends a packet back to Subnet X
Subnet D doesn't have a route to Subnet X so he sends it out his default gateway which happens to be Subnet C.
Subnet C receives the packet going to Subnet X and says "I don't have a route to Subnet X" and sends it out his default gateway which just happens to be Subnet B.
Subnet B receives the packet going to Subnet X and says "Don't know, I don't have a route to Subnet X" and sends it out his default gateway which just happens to be Subnet A.
Subnet A receives the packet going to Subnet X and says "No clue, I don't have a route to Subnet X" and sends it out his default gateway which is the Internet (otherwise known as the "Upstream Provider").
From there, the Packet is going to ask every router it encounters along the way where Subnet X is located. If the router knows, it directs the packet. If the router doesn't know, it sends it out its default gateway. The Packet may hit 5 more routers or 50 routers. It may even cross a few bridges between routers. Eventually, it will find its way home, or a dead end. If it hits a dead end, a message comes all the way back to the client that originally sent the Packet saying "Sorry, dead end. No idea where he's supposed to go."
That's it. No magic. No Voodoo. Just plain and simple routing. Now doing it with numbers is a little more difficult, but not much. As long as A can ping B can ping C can ping D, you can add the routes needed to make A capable of pinging C & D and vice-versa.