How is this number determined and what does it mean?
In the US the number is generated from ATC computers and is unique to, I believe, the ATC Center in which the flight originates. The number is a 4-digit number with each digit being between 0 and 7. A special radio onboard the aircraft, called a transponder, is the radio in which this code is entered. Once the code is entered and the transponder turned on, it will transmit this squawk code and aircraft pressure altitude (disregarding Mode A for this discussion) back to ground-based receivers every time a radar sweeps the aircraft. This data ultimately ends up on ATC's scope.
As Chef alluded to there are actually a few reserved codes - 7700 indicates emergency onboard, 7600 indicates aircraft radio failure, 7500 indicates that the aircraft has been hijacked, and 1200 indicates that the aircraft is VFR. Note that typically aircraft flying under VFR (visual flight rules) who are not flying through class C, B, or A airspace and not talking to ATC will all be squawking 1200. There might be other special codes, but they are not common.