The origin of counting systems

Not all languages count by 10s. Some count by 5s, or 6s, or 8s, or 12s, or 20s, or even by 60s! But how do these counting systems emerge?