The origins of the Cossacks are unclear and disputed. They were already established in parts of what is now Ukraine and southern Russia in the 15th Century, when they increasingly came to the attention of nearby states as fiercely independent groups or "hordes" raiding Russian, Polish, Tatar, and Ottoman lands.
As Russia expanded, the Cossacks gradually became allies and subjects. In return for military service, they retained considerable autonomy for a long time. The Russian state used them as shock troops and helped establish new hordes along Russian border regions, both as defensive buffers and as springboards to further expansion.
Their independent streak, however, caused them to revolt several times. In later years, they became regarded as highly loyal to the tsar, and, in addition to their military role, they also came to be used as security forces in the capital and throughout Russia. They usually but not always were willing to crush unarmed protests or armed rebellion against the tsar with force.