Rifling consists of spiral grooves cut into the inside of a barrel of a gun. It causes the bullet or projectile to spin as it flies through the air. This greatly improves the accuracy of the bullet over longer distances. The first muskets to use this technology were called rifles. Barrels are rifled using a left or right twist. The number of turns per inch is called the "twist rate". These are expressed as a ratio. For example, a 1:7 twist means the bullet will turn once for each seven inches of barrel length. As a general rule, the heavier the bullet, the higher the twist rate.

History 
Gaspard Kollner, a 15th century gunmaker in Vienna, is thought by many to have invented rifling. Others think it was Augustus Kotter of Nuremberg who invented rifling in about 1520. At about that same time some crossbows fired a bolt (short heavy arrow) through a tube with spiral grooving. This gave the bolt more stability in flight. Whether these were used before rifling in gun barrels is not certain. 

The "hand cannon" was first used in China in 1288. From this early beginning and a number of different guns, the smoothbore  Musket was in use in Europe by the 15th century. While it could not fire and reload as fast as an archer and could not be reloaded on horseback, it could penetrate armor. Its greatest advantage over the bow was that anyone could learn to fire a musket in a very short period of time. It took much longer to properly train an archer. The British army used the musket along with pikemen until about 1705 when the pikes were abandoned. In 1722 the army adopted a standard musket called the Brown Bess and continued to use it until about the 1830s. Muskets used a round cast ball that was smaller in diameter than the gun barrel. As a consequence, when the musket was fired, the ball bounced along the inside the barrel. When it exited the barrel it could take a variety of paths making the musket inaccurate. So soldiers were massed together very closely and fired in volly (all at the same time). This sent bullets flying generally in the direction of the enemy on the theory that at least some of the bullets would hit some of the soldiers. The smoke from repeated vollies prevented soldiers from seeing what they were shooting at. In the heat of battle, soldiers who wanted reload and fire faster sometimes omitted ramming the bullet and powder into the barrel with the ramrod. Instead, they would try to seat the ball by sharply hitting the butt of the musket on the ground. This reduced the effectiveness even more. Sometimes the bullet would do little more than dribble out of the barrel and travel only a short distance.

The use of rifled muskets called rifles, changed this. During the American Revolutionary War Americans used muskets. But they also had marksmen who used their Kentucky rifles. The longer barrel was rifled for accuracy at a long range. American riflemen began targeting British officers in battle instead of just individual soldiers. Without their officers giving them every command, the British soldiers could not function as a unit. The British command despised the tactic calling it “unsportsmanlike”. But the Americans continued the practice up to the end of the war.

In 1849, a French army officer, Claude-Étienne Minié, invented a bullet with a hollow base named for him called the Minié ball. When fired, the bullet expanded to fit the rifling inside the gun barrel. This gave it even greater accuracy over a longer distance. The British used it in the Crimean War against Russian forces with tremendous success. At the time of the American Civil War, both the Union and the Confederate armies were using smoothbore muskets out of necessity. But soon rifled muskets using the Minié ball replaced the smoothbore muskets. The effects were to devastate the opposing army at much longer distances.

Rifling process 

Most firearms produced today use a rifled barrel. There are basically three machining processes used to produce rifled barrels.
 Broach rifling - Uses a hardened steel broach that has several cutting rings. Each cutting ring is slightly larger and cuts the grooves progressively deeper. The gun barrel material ridges that are left after rifling are called lands.

 Button Rifling - (most commonly used) Pushes a hardened steel button into the unrifled barrel of a gun. The rifling grooves are cut by very high pressure that also polishes the inside of the barrel. 

 Hammer Forged Rifling - This is used to create a type of rifling called "polygonal rifling". A mandrel is inserted into the barrel blank. Then the outside of the barrel is hammered until it becomes smaller and forms the rifling around the mandrel. The mandrel is then removed leaving a rifled barrel. The final step is to finish the outside of the barrel removing any hammer marks.

References

Other websites 
 History of the Gun Part-7: Rifling; Ruger
 Rifling and twist rate explained; YouTube
 The First American Sharpshooters: YouTube

Firearms