Good question. I think the numbers are 7777 though, at least thats the highest i can ever get on the transponders i have flown with. I cannot however answer your question, but i am sure it has something to do with the amount of different combinations you can make from four numbers ranging from 0 to 7. I suck at math so i don't know how to exactly say how many combinations are possible, but i think it is like 7 to the fourth or something like that.
Actually it's only 7777, allowing for 4096 different codes. I have no idea why it is limited to this. My guess is that it was some limitation on memory or processing speed of early models, and the air traffic control software displayed the targets, and associated info about the aircraft.
Its been awhile since I have studied this topic but the reason they were limited to seven digits was because the 4096 codes have to be made into digital information and then transmitted over radio waves. When transponders were conceived the maximum amount of information that could be sent on a reply signal was equivelent to 4096 codes. Modern technology has found ways to get around this limitation (I think its due to better utilization of the frequency band). Mode C and mode S transponders are both capable of much higher amounts of data that can be transmitted but the standard 4096 codes have been sufficent for the current airspace system so it hasn't been changed.
The trandponders are based on the "octal" notation system. Basically, octal notation is composed of three-bit groups (Just like pink Panther showed, except he left out 0= 0 0 0). Thus you can only go from 0-7 (eight numbers)
Because there are only 8 numbers to play with...8 to the 4th power is 4096.
If you tried to represent all the possible codes without octal, straight binary, going up to 10 total numbers (0-9) you would end up with something like 14 bits for every transmission. Even simply using 0-7 with straight binary gives you 13 bits.
Using octal (0-7) you can send out all possible codes with only 12 bits. If you move up to hexidecimal (0-15) you would be sending 16 bits in each transmission.
So, out of all of those, octal is the most efficient for a system with 4 separate numbers to be used.