A cotton gin – meaning "cotton engine" – is a machine that quickly and easily separates cotton fibers from their seeds, enabling much greater productivity than manual cotton separation. The fibers are then processed into various cotton goods such as calico, while any undamaged cotton is used largely for textiles like clothing. The separated seeds may be used to grow more cotton or to produce cottonseed oil.
Handheld roller gins had been used in the Indian subcontinent since at earliest AD 500 and then in other regions. The Indian worm-gear roller gin, invented sometime around the 16th century, has, according to Lakwete, remained virtually unchanged up to the present time. A modern mechanical cotton gin was created by American inventor Eli Whitney in 1793 and patented in 1794.
Whitney's gin used a combination of a wire screen and small wire hooks to pull the cotton through, while brushes continuously removed the loose cotton lint to prevent jams. It revolutionized the cotton industry in the United States, but also led to the growth of slavery in the American South as the demand for cotton harvesting rapidly increased. The invention has thus been identified as an inadvertent contributing factor to the outbreak of the American Civil War. Modern automated cotton gins use multiple powered cleaning cylinders and saws, and offer far higher productivity than their hand-powered precursors.
A single-roller cotton gin came into use in India by the 5th century. An improvement invented in India was the two-roller gin, known as the "churka", "charki", or "wooden-worm-worked roller". 
Cotton fibers are produced in the seed pods ("bolls") of the cotton plant where the fibers ("lint") in the bolls are tightly interwoven with seeds. To make the fibers usable, the seeds and fibers must first be separated, a task which had been previously performed manually, with production of cotton requiring hours of labor for the separation. Many simple seed-removing devices had been invented, but until the innovation of the cotton gin, most required significant operator attention and worked only on a small scale.
The earliest versions of the cotton gin consisted of a single roller made of iron or wood and a flat piece of stone or wood. The earliest evidence of the cotton gin is found in the fifth century, in the form of Buddhist paintings depicting a single-roller gin in the Ajanta Caves in western India. These early gins were difficult to use and required a great deal of skill. A narrow single roller was necessary to expel the seeds from the cotton without crushing the seeds. The design was similar to that of a mealing stone, which was used to grind grain. The early history of the cotton gin is ambiguous, because archeologists likely mistook the cotton gin's parts for other tools.
Between the 12th and 14th centuries, dual-roller gins appeared in India and China. The Indian version of the dual-roller gin was prevalent throughout the Mediterranean cotton trade by the 16th century. This mechanical device was, in some areas, driven by water power.
Main article: Mughal Empire
The worm gear roller gin, which was invented in the Indian subcontinent during the early Delhi Sultanate era of the 13th to 14th centuries, came into use in the Mughal Empire sometime around the 16th century, and is still used in the Indian subcontinent through to the present day. Another innovation, the incorporation of the crank handle in the cotton gin, first appeared sometime during the late Delhi Sultanate or the early Mughal Empire. The incorporation of the worm gear and crank handle into the roller cotton gin led to greatly expanded Indian cotton textile production during the Mughal era.
It was reported that, with an Indian cotton gin, which is half machine and half tool, one man and one woman could clean 28 pounds of cotton per day. With a modified Forbes version, one man and a boy could produce 250 pounds per day. If oxen were used to power 16 of these machines, and a few people's labour was used to feed them, they could produce as much work as 750 people did formerly.
The Indian roller cotton gin, known as the churka or charkha, was introduced to the United States in the mid-18th century, when it was adopted in the southern United States. The device was adopted for cleaning long-staple cotton, but was not suitable for the short-staple cotton that was more common in certain states such as Georgia. Several modifications were made to the Indian roller gin by Mr. Krebs in 1772 and Joseph Eve in 1788, but their uses remained limited to the long-staple variety, up until Eli Whitney's development of a short-staple cotton gin in 1793.
Eli Whitney (1765–1825) applied for a patent of his cotton gin on October 28, 1793; the patent was granted on March 14, 1794, but was not validated until 1807. Whitney's patent was assigned patent number 72X. There is slight controversy over whether the idea of the modern cotton gin and its constituent elements are correctly attributed to Eli Whitney. The popular image of Whitney inventing the cotton gin is attributed to an article on the subject written in the early 1870s and later reprinted in 1910 in The Library of Southern Literature. In this article, the author claimed Catharine Littlefield Greene suggested to Whitney the use of a brush-like component instrumental in separating out the seeds and cotton. To date, Greene's role in the invention of the gin has not been verified independently.
Whitney's cotton gin model was capable of cleaning 50 pounds (23 kg) of lint per day. The model consisted of a wooden cylinder surrounded by rows of slender spikes, which pulled the lint through the bars of a comb-like grid. The grids were closely spaced, preventing the seeds from passing through. Loose cotton was brushed off, preventing the mechanism from jamming.
Many contemporary inventors attempted to develop a design that would process short staple cotton, and Hodgen Holmes, Robert Watkins, William Longstreet, and John Murray had all been issued patents for improvements to the cotton gin by 1796. However, the evidence indicates Whitney did invent the saw gin, for which he is famous. Although he spent many years in court attempting to enforce his patent against planters who made unauthorized copies, a change in patent law ultimately made his claim legally enforceable – too late for him to make much money from the device in the single year remaining before the patent expired.
While Whitney's gin facilitated the cleaning of seeds from short-staple cotton, it damaged the fibers of extra-long staple cotton (Gossypium barbadense). In 1840 Fones McCarthy received a patent for a "Smooth Cylinder Cotton-gin", a roller gin. McCarthy's gin was marketed for use with both short-staple and extra-long staple cotton, but was particularly useful for processing long-staple cotton. After McCarthy's patent expired in 1861, McCarthy type gins were manufactured in Britain and sold around the world. McCarthy's gin was adopted for cleaning the Sea Island variety of extra-long staple cotton grown in Florida, Georgia and South Carolina. It cleaned cotton several times faster than the older gins, and, when powered by one horse, produced 150 to 200 pounds of lint a day. The McCarthy gin used a reciprocating knife to detach seed from the lint. Vibration caused by the reciprocating motion limited the speed at which the gin could operate. In the middle of the 20th Century gins using a rotating blade replaced ones using a reciprocating blade. These descendants of the McCarthy gin are the only gins now used for extra-long staple cotton in the United States.
For a decade and a half after the end of the Civil War in 1865, a number of innovative features became widely used for ginning in the United States. They included steam power instead of animal power, an automatic feeder to assure that the gin stand ran smoothly, a condenser to make the clean cotton coming out of the gin easier to handle, and indoor presses so that cotton no longer had to be carried across the gin yard to be baled. Then, in 1879, while he was running his father's gin in Rutersville, Texas, Robert S. Munger invented additional system ginning techniques. Robert and his wife, Mary Collett, later moved to Mexia, Texas, built a system gin, and obtained related patents.
The Munger System Ginning Outfit (or system gin) integrated all the ginning operation machinery, thus assuring the cotton would flow through the machines smoothly. Such system gins use air to move cotton from machine to machine. Munger's motivation for his inventions included improving employee working conditions in the gin. However, the selling point for most gin owners was the accompanying cost savings while producing cotton both more speedily and of higher quality.
By the 1960s, many other advances had been made in ginning machinery, but the manner in which cotton flowed through the gin machinery continued to be the Munger system.
Economic Historian William H. Phillips referred to the development of system ginning as "The Munger Revolution" in cotton ginning. He wrote,
"[The Munger] innovations were the culmination of what geographer Charles S. Aiken has termed the second ginning revolution, in which the privately owned plantation gins were replaced by large-scale public ginneries. This revolution, in turn, led to a major restructuring of the cotton gin industry, as the small, scattered gin factories and shops of the nineteenth century gave way to a dwindling number of large twentieth-century corporations designing and constructing entire ginning operations."
One of the few (and perhaps only) examples of a Munger gin left in existence is on display at Frogmore Plantation in Louisiana.
Prior to the introduction of the mechanical cotton gin, cotton had required considerable labor to clean and separate the fibers from the seeds. With Eli Whitney's gin, cotton became a tremendously profitable business, creating many fortunes in the Antebellum South. Cities such as New Orleans, Louisiana; Mobile, Alabama; Charleston, South Carolina; and Galveston, Texas became major shipping ports, deriving substantial economic benefit from cotton raised throughout the South. Additionally, the greatly expanded supply of cotton created strong demand for textile machinery and improved machine designs that replaced wooden parts with metal. This led to the invention of many machine tools in the early 19th century.
The invention of the cotton gin caused massive growth in the production of cotton in the United States, concentrated mostly in the South. Cotton production expanded from 750,000 bales in 1830 to 2.85 million bales in 1850. As a result, the region became even more dependent on plantations that used black slave labor, with plantation agriculture becoming the largest sector of its economy. While it took a single slave about ten hours to separate a single pound of fiber from the seeds, a team of two or three slaves using a cotton gin could produce around fifty pounds of cotton in just one day. The number of slaves rose in concert with the increase in cotton production, increasing from around 700,000 in 1790 to around 3.2 million in 1850. The invention of the cotton gin led to an increased demands for slaves in the American South, reversing the economic decline that had occurred in the region during the late 18th-century. The cotton gin thus "transformed cotton as a crop and the American South into the globe's first agricultural powerhouse".
Because of its inadvertent effect on American slavery, and on its ensuring that the South's economy developed in the direction of plantation-based agriculture (while encouraging the growth of the textile industry elsewhere, such as in the North), the invention of the cotton gin is frequently cited as one of the indirect causes of the American Civil War.
In modern cotton production, cotton arrives at industrial cotton gins either in trailers, in compressed rectangular "modules" weighing up to 10 metric tons each or in polyethylene wrapped round modules similar to a bale of hay produced during the picking process by the most recent generation of cotton pickers. Cotton arriving at the gin is sucked in via a pipe, approximately 16 inches (41 cm) in diameter, that is swung over the cotton. This pipe is usually manually operated, but is increasingly automated in modern cotton plants. The need for trailers to haul the product to the gin has been drastically reduced since the introduction of modules. If the cotton is shipped in modules, the module feeder breaks the modules apart using spiked rollers and extracts the largest pieces of foreign material from the cotton. The module feeder's loose cotton is then sucked into the same starting point as the trailer cotton.
The cotton then enters a dryer, which removes excess moisture. The cylinder cleaner uses six or seven rotating, spiked cylinders to break up large clumps of cotton. Finer foreign material, such as soil and leaves, passes through rods or screens for removal. The stick machine uses centrifugal force to remove larger foreign matter, such as sticks and burrs, while the cotton is held by rapidly rotating saw cylinders.
The gin stand uses the teeth of rotating saws to pull the cotton through a series of "ginning ribs", which pull the fibers from the seeds which are too large to pass through the ribs. The cleaned seed is then removed from the gin via an auger conveyor system. The seed is reused for planting or is sent to an oil mill to be further processed into cottonseed oil and cottonseed meal. The lint cleaners again use saws and grid bars, this time to separate immature seeds and any remaining foreign matter from the fibers. The bale press then compresses the cotton into bales for storage and shipping. Modern gins can process up to 15 tonnes (33,000 lb) of cotton per hour.
Modern cotton gins create a substantial amount of cotton gin residue (CGR) consisting of sticks, leaves, dirt, immature bolls, and cottonseed. Research is currently under way to investigate the use of this waste in producing ethanol. Due to fluctuations in the chemical composition in processing, there is difficulty in creating a consistent ethanol process, but there is potential to further maximize the utilization of waste in the cotton production.