A default gateway is a network setting on a computer that specifies the IP address of the computer or router that network traffic should be sent to when the traffic is not on the same subnet as the sending computer. The subnet that the computer is on is determined by the netmask and IP address of the computer.
When the netmask is setup, it specifies some number of most significant bits with a 1's value and the rest have values of 0. The most significant part of the netmask with bits set to 1's specifies the network address, and the lower part of the address will specify the host address.
When information is sent across a network a destination IP address is specified. The computer looks at the part of the IP address that matches the part of the netmask where the bits are set to ones. This is the most significant part. If the subnet of the destination address is the same as the subnet of the local computer, the packet is sent out on the network to the destination address. If there is not a match, the packet is sent to the default gateway specified in the network setting.