The mechanics are rule based.
- If you have only one hero, he gains experience for creeps killed no matter where he is on the map.
- If you have multiple heroes, a hero gains experience when he or any unit under his "command" kills a hostile unit. If multiple heroes are commanding a unit that makes a kill, then the XP is split evenly.
- If no hero "commands" the unit that makes the kill, then all heroes share the XP.
When getting experience from a creep, the hero only gets a percentage of the XP that he would have received had the hostile unit not been a creep, depending on the hero's level.
- Level 1 -> 80%
- Level 2 -> 70%
- Level 3 -> 62%
- Level 4 -> 55%
- Levels 5+ -> 0%
Hence, if you are supposed to get 100 exp, which is to be shared between 2 heroes of level 2 and 3, they will receive 50*70% = 35 and 50*62% = 31, respectively. This is worse than if only the lower leveled one of them got the experience (100*70% = 70 vs. 100*62 = 62).
That is why you creep with just one hero if heroes are of different levels.
"commands" (it is not defined in the page) - I think this means that the hero is actively engaged in combat along with unit in question. This unit can be in a defined radius of the hero. IIRC, that radius is 600, but I don't have sources for that.