Cotton has been one of the best-performing commodities on the market in the last year, outpacing even gold by far. You'd expect a cotton-intensive business like Hanesbrands (NYSE: HBI) to unravel over a tripling of a key input, but the latest earnings report spins a different yarn. Sales were up 12%, and earnings per share rose 32%, as the company was actually able to lower its costs.

Hanes improved margins by 60 basis points over last year, an impressive feat given the increase in its input costs. The company owes this success to initiatives made from 2006 to 2009, following its spinoff from Sara Lee (NYSE: SLE). The company eliminated a third of the employees at its headquarters and shifted much of its manufacturing to Asia, where manufacturing costs are cheaper, while also consolidating into fewer, larger facilities. These measures helped improve net margin from 2.8% in 2007 to 4.9% in 2010.

Hanes also improved profitability by passing some of its cost increases on to customers. This is important, because the company doesn't exactly cater to a demographic for whom money is no object. Indeed, Hanesbrands is the exclusive underwear provider to Dollar General (NYSE: DG), which is about as far from high fashion as you can get. Hanes' ability to grow sales by an impressive 12% while raising prices not only bodes well for the company itself, but also for low-cost clothing retailers like Aeropostale (NYSE: ARO) and Gap (NYSE: GPS).

Hanes has certain advantages over its competitors, however. For starters, most of the company's sales come from basic clothing -- things like socks, underwear, and plain white Ts. These are to the wardrobe what bread and milk are to the kitchen: basic necessities, and thus not as susceptible to fashion trends or economic downturns. Having the top market share in basic clothing staples gives the company the benefit of a massive customer base as well. Almost 90% of Americans have at least one Hanesbrands product in their homes.

The company has also done well to plan ahead. While cotton spent most of the quarter north of $1.80 per pound, Hanes bought in advance, giving it an effective price of $0.83. Hanes has also recently begun experimenting with fabric made from flax, supposedly cheaper and stronger than cotton but just as comfortable. A successful product will put the company on track to further improve margins and protect against any future problems in the cotton market.