It bothers me whenever I see people who don't even grasp the very basics of networking. It bothers me even more when they get responses by people who are equally clueless.
Let's start with a lesson in binary -
Each digit in binary represents a power of 2. The right most digit represents 2^0 and each digit to the left represents a power of 2 higher than the previous. It might help if we make a table, so for an 8 digit binary number, the values are:
2^7 2^6 2^5 2^4 2^3 2^2 2^1 2^0
Or alternatively
So, if we have a binary number like 00011011, we can compute the decimal value using the above table:
128 64 32 16 8 4 2 1
0 0 0 1 1 0 1 1
Or
0 * 128 + 0 * 64 + 0 * 32 + 1 * 16 + 1 * 8 + 0 * 4 + 1 * 2 + 1 * 1
= 16 + 8 + 2 + 1
= 27
This means that 00011011 in binary means 27 in decimal.
To convert from decimal to binary we can also use the above table, only this time we'll start from the left side of the table. If we can subtract the value from our current number we write a 1, otherwise we write a 0. Let's start by converting 168 to binary.
128 64 32 16 8 4 2 1
1 ... 168 - 128 = 40, continue with 40
0 ... can't subtract 40 - 64
1 ... 40 - 32 = 8
0 ... can't subtract 8 - 16
1 ... 8 - 8 = 0
0 0 0 ... can't subtract anything else from 0
So, looking at our table, 168 is 10101000 in binary.
If we convert a whole IP address like 192.168.1.2 we end up with:
11000000 10101000 00000001 00000010
And a netmask of 255.255.255.0
11111111 11111111 11111111 00000000
Notice how the netmask has a series of 1's on the left? There's 24 of them, which is why you'll sometimes see a "255.255.255.0" netmask called a "/24". A netmask determines which bits of the IP address are constant, so in this example we have a range of:
11000000 10101000 00000001 00000000
...
11000000 10101000 00000001 11111111
Or, 192.168.1.0 - 192.168.1.255. This is called our subnet. The lowest number, 192.168.1.0 is reserved as the network address. The nighest number, 192.168.1.255 is called the broadcast address. This gives us a usable IP range from 192.168.1.1 to 192.168.1.254.
Before we continue we need to talk about mac addresses. Each Ethernet interface has it's own unique mac address; communication between Ethernet devices actually uses the mac address, not IP addresses. ARP stands for "Address Resolution Protocol" and is the mechanism used to resolve an IP address to a mac address.
In our example, we have a computer with an IP of 192.168.1.2 and a netmask of 255.255.255.0; this defines our subnet as 192.168.1.1-192.168.1.254 -- these are the computers that can be reached directly at the mac address layer. If we want to talk to any machines outside our subnet, we need a gateway. A gateway is nothing more than a machine on multiple subnets which is able to forward traffic on our behalf.
To understand what I mean, let's look at a routing table.
1: Destination Gateway Genmask Flags Metric Ref Use Iface
2: 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
3: 0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
Routing tables are a set of rules to be followed to reach an IP address, they are ordered from the most specific to the least specific. Each line shows a network address, netmask (Genmask) and a gateway to reach that subnet. Line 2 shows us that 192.168.1.1-192.168.1.255 can be reached on eth0 without using a gateway (0.0.0.0). Look carefully at line 3, here is a network address of 0.0.0.0 and a netmask of 0.0.0.0; this means a 0.0.0.0-255.255.255.255 can be reached via the gateway 192.168.1.1.
That, in a nutshell is how networking works. The internet is a massive collection of networks connected by various gateways. So from 192.168.1.2 it uses 192.168.1.1 as a gateway, 192.168.1.1 will use another gateway and the packet will travel according to each gateway's routing rules until it reaches the destination. To prevent endless loops, each packet has a ttl (time to live), which is decreased each time the packet is forwarded; when the ttl expires, an error message is sent back to the source. Traceroute takes advantage of this by purposely setting the ttl low and slowly incrementing it, causing error messages from every hop (gateway) along the path to the destination.
Ah, but we still need to talk about NAT.
So far we've been talking about addresses in the 192.168.x.x range. These are private addresses which aren't routed across the internet. I don't want to connect to google telling it that I'm 192.168.1.2 because google would have a tough time sending the response back to a 192.168.x.x address. This is where NAT comes in handy; NAT stands for Network Address Translation, and it allows us to substitute one IP address for another. Suppose my network looks like this:
my pc (192.168.1.2) --- router (192.168.1.1, 1.2.3.4) --- google
When I send a request to google, it goes through my router, and the router then performs a NAT changing the original source (192.168.1.2) to the router's internet IP (1.2.3.4), while writing a record in the router's NAT table that 192.168.1.2 tried to access google. When the response from google comes back, the router looks at it's NAT table and sees that the request came from 192.168.1.2 and forwards the packet. This acts as a natural firewall, because if the router receives a packet from openwrt.org instead, it will look at the NAT table and not find any requests for openwrt.org.
...
I've indirectly answered all of your questions.