What role do the subnet & default gateway play in a network? Are networks differentiated by IP address and what to the subnet mask & default gateway do?
As Oron said networking is a very complex topic and a proper explanation on how it works would become quit extensive. It would involve explaining basic networking, part of the OSI (abstraction) layers, routing and what not.
Keeping it very short and simple (while neglecting a lot of this topic):
Each device or host on an IP network has an (unique) IP address.
The subnet mask tells your system which other IP addresses (hosts) are part of your (sub)network.
The gateway is your networks "gate" to the outside world, to hosts outside of your (sub)network.
These are things that are a little difficult to explain if you don't have some background in computer networks, but I'll try... A network is a collection of computers connected to each other, for example, the computers you have at home, which are all connected via the same router (the internet is a "network of networks" as it were, not a single network).
All of this is important because, for networks to operate, the IP addresses must make sense. If your computer has an address which is not part of its own network, other computers/routers will not be able to find it, if your gateway address is wrong then traffic won't be routed properly (which in the home would mean no Internet access) and if you have machines with duplicate IP addresses, well, who knows what will happen... I hope this helps.
The easy explanation of a subnet mask: It allows the computer to identify what part of an IP address is referring to a network address and what part is referring to the host address (the individual device, or node). It is a string of binary 1s followed by a string of binary 0s that the computer (or router) uses to perform a bitwise-AND with the IP address to determine the network address where the host computer resides. A computer may reside on a network that has gateways to more than one other network, so it will use the network address to determine which gateway it needs to forward the data packet through. A router does the same thing in determining if the packet needs to go to a node that is on a network the router has a direct connection to or if it needs to forward it to another router to get it closer to its destination.
A couple of clarifications: A host number of 0 or 'max' (the value of max can change depending on the subnet mask used) might not be assigned to a device on the network for legacy support reasons. For example, a network using an IP range of 192.168.0.0-192.168.0.255 and a subnet mask of 255.255.255.0 (also expressed as 192.168.0.0/24) can have a maximum of 254 hosts on it if it doesn't support CIDR. The network itself would be identified as 192.168.0.0 and the network broadcast address would be 192.168.0.255. If the network supports CIDR (most current setups do), this does not apply. Even today, most home routers use a subnet mask of 255.255.255.0 but do not use the .0 network address or the .255 broadcast address for any devices it allocates via DHCP and the router will almost always take the host address of .1.
A default gateway is where a device will ship any packets that are not destined for a node on the (sub)network with the source device that is not explicitly directed elsewhere based on entries in the source machine's routing table. In my apartment, for example, I have 2 networks that are separated by a router/firewall. The routing table on the computer I am using right now has these entries (others irrelevant to discussion omitted):
0.0.0.0 0.0.0.0 192.168.2.1
192.168.10.0 255.255.255.0 192.168.2.2
The second one is telling the computer that if it needs to send a packet to an address on network 192.168.10.0, it needs to send it to the machine at the address 192.168.2.2 on this network. The entry for 0.0.0.0 is the default gateway which is my router that is attached to my broadband modem to connect me to the Internet and the outside world. Any packet that is not addressed to a host on either 192.168.2.0 or 192.168.10.0 will go through the router at 192.168.2.1.
Clear as mud, right?