There is a really good post on this site that is only a couple of weeks old. Do a search on this site and you'll find a good explanation for subnet masks, DNS, IP address, and the like.
The subnet mask defines what IP addresses are on the local network. To talk to any of the IPs on the local network your device simply sends a packet to the destination IP. To talk to IPs that are not on the local network your device sends a packet to the gateway IP; this packet must include the ultimate destination IP.
Lets say you've got the following settings on your PC:
IP = 192.168.0.101
Gateway = 192.168.0.1
Subnet = 255.255.255.0
This means that your PC can communicate directly with any IP address of 192.168.0.0 through 192.168.0.255.
For all other IP addresses data must be sent to the gateway.
If your subnet was 255.255.0.0 then your computer could communicate with IPs from 192.168.0.0 through 192.168.255.255.