When you start your game, you're assigned two 16-bits IDs (Which explains why you cannot get an ID starting with 7, 8 or 9)
Now, the first ID is the one you can see on your trainer card, pokemon page summary, etc, while the other one cannot be seen; it's a "hidden ID". Translating them into...