According to standard economic theory, the division of labour occurs with internal market development (Adam Smith). However, according to economist John Hicks, merchants and artisans originated as servants to the rulers, which occured much earlier.
In the Middle Ages they were usually organised into guilds. The guild was an association of master artisans that were granted charters by the local sovereign authority. The guilds controlled all aspects of production and distribution to ensure quality and to prevent competition from outside markets. Along with the merchants, the artisans occupied the "middle tier" of the social hierarchy, between the landowning aristocrats and the agricultural workers.
To become an artisan in the guilds, a person was placed under a master artisan as an unpaid apprentice at a young age. If the apprentice completed the training, the appentice became a paid journeyman. For a journeyman to become a master artisan, he would have to produce a "masterpiece" that met the standards of the guild.