Prefectural armies (xingbing 廂兵, xiangjun 廂軍) were troops originally created for local defense during the Song period 宋 (960-1279). They did normally not take part in military campaigns and therefore did not receive proper military training (xunliang 訓練).
The origin of the prefectural armies lay in the local garrison troops of the various military commissioners (jiedushi 節度使) and newly recruited troops (xinjun 新軍) which had various duties (zayi 雜役), like constructing city walls and moats, roads and bridges, dams and dykes, producing weapons and boats, transporting tribute grain, or delivering massages as couriers. Some troops were also deployed to clear land for agriculture. These two types of troops were merged in the early Song period to the prefectural armies.
It was common to select the best men of these units to staff the imperial armies. Emperor Renzong 宋仁宗 (r. 1022-1063) decided to train prefectural armies trained for the suppression of peasant rebellions. Their successful mission was the reason to regularize training for at least part of the prefectural armies. These were called "trained and monitored" (jiaoyue 教閱), the others were from then on called conscripted troops (yibing 役兵). Those of the prefectural troops which were trained, could be used for cavalry units (majun 馬軍), infantry units (bujun 步軍), for naval (riverine) warfare (shuijun 水軍), mounted archery (qishejun 騎射軍), engineering (laochengjun 牢城軍), etc. There were in total 223 different types of use for troops during the Song period (Yang 1987: 778).
Emperor Shenzong 宋神宗 (r. 1067-1085) created a specialized institution supervising the military training (jiaoyuefang 教閱房). The basic military unit was a command (zhihui 指揮), in case of cavalry a squadron (du 都). The highest military commanders of a prefecture was a commander-in-chief (du zhihui shi 都指揮使), who had two deputies, namely a vice commander-in-chief (fu du zhihui shi 副都指揮使) and an inspector-in-chief (duyuhou 都虞候).
Each prefecture was protected by two garrisons (a left and right prefectural garrison, zuo-you xiang 左右廂), each of which was headed by a commander (zhushuai 主帥). The salary of prefectural armies was therefore substantially lower than that of the imperial armies, which were usually called "metropolitan guards" (jinjun 禁軍).
The troops of prefectural armies were enlisted, and were thus professionals, in contract to the garrison militia (fubing 府兵) of the early Tang period 唐 (618-907), which had been drafted from among the peasant population and had to serve for a certain period of time. In the military system of the Song, quite a few enlisted were delinquents who had the chance to escape punishment by delivering military service (see also penal military service).
In the course of time, many prefects began to create "local" imperial armies, and the difference between the metropolitan elite troops and the local troops was blurred.
The western, northern and northwestern border regions of the Song empire were protected by frontier tribal troops (fanbing 蕃兵, fanjun 蕃軍) that were mainly recruited from among local tribes. Local militia were called xiangbing 鄉兵 or xiangjun 鄉軍.