ID is different from unitid. ID is a hidden and fixed number assigned to every unit when it is created. Commanders and troops are always arranged by their ID. ID's are normally assigned in ascending order: a Commander recruited on Turn 1 always appears before a Commander recruited on Turn 3, and a troop at the very front of the recruitment queue will always appear before the rest of that queue. Commanders act in ID order, so within each phase the commander at the top of the setup screen will go first and the commander at the bottom will go last. This becomes very important for things like Communions, Summon Stormpower, and every other situation where spell order would matter.