Assuming we are talking about IP version 4, the IP address contains 32 bits. In the standard X.X.X.X notation, each octet X is 8 bits. (Note that there is nothing "special" about grouping them into 4 octets other than to make it easier for humans to write - machines have no issue dividing anywhere within the 32 bits.)
A subnet mask splits that address into two parts, the network (left) and host (right) portion.
Realize also that IP addresses are assigned to INTERFACES (NICs, etc.) and not individual MACHINES.
Basically everything on the same subnet can talk to each other without going through a router. Anything on different subnets, a router needs to be in the middle forwarding for traffic to move back and forth.
If a machine wants to talk to another machine through a given interface, and the network part on that interface is the same as that of the other machine, it should just be able to shove what it wants to say out on the wire, tagged with its own address (source) and who it wants to talk to (destination), and the other machine will pick it up. In the old days of 10BaseT, etc. all were physically connected to the same physical wire and this would literally happen. Now hubs and switches have replaced that.
If a machine wants to talk to another machine through a given interface, and the network part on that interface is NOT the same as that of the other machine, the traffic needs to go through a router. The machine will need to have a record of what the router's IP address (in this case the router is usually called the gateway) for that subnet is and will then send the traffic there. The router/gateway is then expected to forward the traffic to the destination or another router closer to it.
On most home networking equipment, all machines connected to a switch will usually be configured to be on the same subnet, since the point of connecting all of them to the same switch is to allow all of them to talk to each other. Should one be misconfigured, it won't be able to participate in any communications. However, if the device was a hub and not a switch, the hub would forward all traffic to it (since hubs do not remember MAC addresses and just forward or flood everything out of all ports), and the connected system could "snoop" on all traffic if the NIC was put into promiscuous mode. If that system would send traffic back, if it was not on the same subnet, no other NIC would pick it up (unless it was in promiscuous mode as well.)
Advanced networking equipment can be "partitioned" into VLANs, the machines connected which don't see each others traffic. For machines on different VLANs to communicate, forwarding/a router needs to be involved.