Cantonist schools were established by the 1721 decree of Tsar Peter the Great that stipulated that every regiment was required to maintain a school for 50 boys. Their enrollment was increased in 1732, and the term was set from the age of 7 to 15. The curriculum included grammar and arithmetic, and those with a corresponding aptitude were taught artillery, fortification, music and singing, scrivenery, equine veterinary science, or mechanics. Those lacking in any talent were taught carpentry, blacksmithing, shoemaking and other trades useful to the military. The ablest ones were taught for additional 3 years, until the age of 18. All entered military service at the completion of their studies. The decree of 1758 required all male children of the military personnel to be taught in the cantonist schools. In 1798 a military "asylum-orphanage" was established in St Petersburg, and all regimental schools were renamed after it, the total enrollment reaching 16,400.- Wikipedia
The schools were reorganized in 1805 and all children were now referred to as cantonists. After the War of 1812 their number increased dramatically, when many orphaned children of military personnel killed in the war enrolled in cantonist schools voluntarily. During this period the curriculum of cantonist schools was equivalent to that of gymnasia, and military subjects were not taught.
In 1824 all cantonist schools were made answerable to the Director of Military Settlements Count Aleksey Arakcheyev, and in 1826 they were organized into cantonist battalions. The standards of curriculum dropped significantly, and it was limited to the subjects useful to the military.
During the reign of the Nicholas I of Russia the number of cantonists reached 36,000. Several cantonist battalions became specialized: they prepared auditors, artillerists, engineers, military surgeons, cartographers.
More children were added to the category of cantonists. Eventually children of the discharged soldiers were also included, illegitimate children of soldiers' wives' or widows', and even foundlings.
There were several exemptions:
Legitimate sons of staff-officers, and all officers awarded the Order of St. Vladimir 4th class.
A single son of a junior staff-officer, out of a total number of his children, if he had no sons born after his attainment of the officer's rank.
A single son of a junior officer maimed in battle.
A single son of a widow of a junior officer or an enlisted man killed in action or deceased during service.
There were considerable differences in cantonists' service obligations:
Children of nobility were required to serve for 3 years at the completion of their studies.
Children of senior officers - 6 years.
Children of clergy - 8 years.
All other social categories - 25 years.