Bits and masks
Host A's address, 192.168.1.10, is really 32 bits (binary digits, 0 or 1), in four groups of 8 called octets. Each pin is one bit: up means 1, down means 0. So 192 is 11000000.
A subnet mask is 32 bits too. /24 means the first 24 bits are 1 and the last 8 are 0, written 255.255.255.0. Our stencil has a hole over every 1 and is solid over every 0.
Bits under the holes are the network part: 192.168.1. Bits under the solid end are the host part: 10. Every device on this network shares the network part and has its own host part.
Set every host bit to 0 and you get the network address, 192.168.1.0. It is the name of the whole network, so no device uses it.
Set every host bit to 1 and you get the broadcast address, 192.168.1.255: a message sent there reaches every device here. That leaves 2⁸ − 2 = 254 addresses for devices.
Same network or not?
Host A wants 192.168.1.77. It lays its mask over that address (a bitwise AND): bits under holes stay, bits under the solid part become 0. The result, 192.168.1.0, is its own network, so it sends straight to host B.
Now host A wants 198.51.100.20. Masked, it becomes 198.51.100.0, not 192.168.1.0, so that address is somewhere else. Host A hands the message to its default gateway, the router at 192.168.1.1.
Splitting a network
To cut the network into four, lend 2 host bits to the network part. The mask becomes /26, which is 255.255.255.192. Those 2 bits can be 00, 01, 10 or 11: four subnets.
Each subnet keeps 6 host bits: 2⁶ = 64 addresses. Minus the network and broadcast addresses, that leaves 62 for devices. The blocks start at .0, .64, .128 and .192.
With the /26 mask, host A masks 192.168.1.77 and gets 192.168.1.64, not its own 192.168.1.0. Host B is now on another subnet, so the message goes through the router.
The bits, step by step
;; step 1/10 · address-bits ;; at: address ;; mask /24 = 255.255.255.0 192.168.1.10 11000000.10101000.00000001.00001010 192 = 128 + 64 = 11000000
A bitwise AND keeps a bit only when both bits are 1. Laying the mask over an address does exactly that, so the network part survives and the host part becomes 0 (RFC 1122 §3.3.1). The "minus 2" rule has exceptions: a /31 has no broadcast and uses both addresses on point-to-point links (RFC 3021), and old advice to skip the first and last subnet is obsolete (RFC 1878).