Consider Company X. Its annual sales—now $27.4 billion, or more than those of Estée Lauder, Hilton Worldwide, and Hershey combined—have risen 50% over the past six years. Its profits have almost tripled, to $2.1 billion. Its shareholders have been the beneficiaries of 18 consecutive years of earnings-per-share growth. In its nearly-four-decade history, it has had only one year of negative same-store sales. And it does all this by selling blouses…pots and pans…and bedding, sunglasses, sriracha seasoning, yoga mats, and the occasional $1,250 Stella McCartney dress.

Company X—make that TJX—may well be the biggest enigma in an industry so fragile and capricious that Starbucks CEO Howard Schultz once likened it to the “human condition.” The business of retail is hard stuff. Chains soar when they manage to sell into the zeitgeist (“Tar-zhay,” anyone?) and collapse when the stars of public taste realign (Abercrombie). In the off-price realm that the TJX TJX Companies dominates, it is, if anything, harder. The past six years have seen the demise of Filene’s Basement, Daffy’s, and Loehmann’s, which has reemerged as an online-only store. The number of customer purchases at TJX, by contrast, has risen in each of the last six years; over that time, TJX shares have climbed over 200%.

“It’s the most consistent, most powerful apparel retailer in the United States,” says Howard Davidowitz, who has run his own retail consulting and investment banking firm for 33 years. “It’s a bold statement, but it’s true.” Ron Hess, a professor of marketing at William & Mary’s Mason School of Business, puts it this way: “They are stunningly good.”

But there is one other salient fact about the Framingham, Mass., retailer that adds to the enigma: It will do almost anything to prevent anybody else from knowing how it has managed all of the above. TJX is Company X: a black box—arguably one of the most secretive retailers around.

CEO Carol Meyrowitz, 60, rarely gives interviews. (In keeping with the tradition, TJX declined to make her or any of the company’s executives available for this story.) And Meyrowitz has been known to tell analysts “nice try,” or offer other quick rebuffs, when they ask probing questions on earnings calls. “My sense of Carol is that telling you less is better than telling you more,” says David Poppe, president of Ruane Cunniff & Goldfarb, a major TJX shareholder. In the end, the most we got from Meyrowitz with regard to this story was an emailed quote, which began: “Our value proposition has resonated with consumers for 37 years, across different geographies, retail climates, and in both strong and weak economies.”

TJX doesn’t talk about its playbook in part because other retailers are eager to peek inside. Hudson’s Bay Co., which owns venerable Saks Fifth Avenue and its Off 5th outlet stores, has acknowledged that it has studied TJX’s T.J. Maxx chain. And at least one other well-known department store company is rapidly chasing the off-price leader, in style if not yet in numbers: Nordstrom’s JWN value-focused Nordstrom Rack stores now have more outlets (151) than its full-line division. TJX, by comparison, has more than 3,200 stores in the U.S., Canada, and Europe, divided among its T.J. Maxx, Marshalls, HomeGoods, and other chains.

The increased competition may have thrown TJX off its game in the most recent quarter (reported in May) when it missed its own earnings estimates for the first time in five years. The gap was small—just a penny off earnings per share—but notable for a company that tends to under-promise and over-deliver on its projections. The stock subsequently had its biggest single-day drop since December 2008. (Executives attributed the miss to factors including unfavorable foreign currency exchange rates and weak apparel sales.)

We’ll know on Aug. 19, when the company reports its next quarterly earnings, whether this was a blip or something larger. But whatever the outcome, TJX’s long history of out- performance has something to teach—and the lessons may go far beyond retail. On the surface, what TJX does is straight- forward: Its various chains sell mostly name-brand goods at a discount to traditional retail prices. How it continuously makes money doing this when so many others have failed is another tale—and that’s the mystery we set out to uncover. Fortune spent four months talking to 50 former TJX employees and other retail insiders—including analysts, consultants, suppliers, and competitors—to re-create the company’s secret playbook. Here’s what we found.

Play No. 1:
Sell “new,” not a “sale.”
The off-price business is a volume game: selling a ton of goods and selling them fast. The measure of speed here is how quickly a company turns over its inventory: TJX does that every 55 days, vs. 85 for its peer group, according to Morningstar. Indeed, the company is structured to whisk items through its distribution centers and stores—and a lot of items they are: TJX shipped some 2 billion units to its stores in its 2014 fiscal year (which ended on Feb. 1), up from 1.6 billion in fiscal 2010.

Former employees say that the stuff moves so rapidly that merchandise is often sold before TJX has paid its vendors for it. The busiest stores can take daily delivery of product, which employees put out on the floor right away—a “door to floor” approach that cuts down on the amount of space needed for backroom storage. Sources say items typically go on markdown if the turn rate is slower than about seven weeks, which also contributes to the rapid flow. But don’t expect to see a storewide promotion. That would erode customers’ belief that they’re getting the lowest price possible from the outset—a fundamental driver for the company.

The quick turns throw off a lot of cash but also keep the merchandise fresh. “People love new much more than they love the stuff they saw last time now discounted,” says Paul Sweetenham, who previously ran TJX’s European business. Another former executive said that the most dedicated shoppers know when the store is taking delivery and plan their visits accordingly. By design, the product assortment is broad—cocktail dresses alongside wetsuits—but not deep. (If Jimmy Choo heels are on display, you’re lucky if there’s one pair in your size.) This trains customers to buy it when they see it or it’ll be gone—what retail brand consultant Bill D’Arienzo calls the “buy now or cry later” mentality. “Fast fashion” retailers such as H&M and Zara do something similar, creating demand by controlling and limiting supply, he says. And that’s a key point. Much of TJX’s appeal is selling what’s hot now, not last season’s leftovers.

Play No. 2:
Put real treasure in the treasure hunt.
Hardly anyone goes to a Marshalls or T.J. Maxx to find something specific. That’s not the point. Someone seeking a Tory Burch boatneck tunic ought to go to a department store. At an off-price chain, the lure is the serendipitous discovery. “In academic terms, it’s hedonic shopping motivation,” says William & Mary professor Hess. “You’re shopping for adventure and exploration.” In the industry, the experience is simply called the “treasure hunt.”

TJX makes a point of hiding gems for the well-heeled as well as the middle class. Customers peruse TJX’s stores not because they fall into a certain income strata but because they like to shop the same way. Take Prince Harry and his sister-in-law, the Duchess of Cambridge, for example, who have been known to shop at T.K. Maxx, one of the company’s European chains. Robin Lewis, CEO of retail strategy newsletter The Robin Report, calls the model “demographically democratic.” The investment bank Cowen & Co. conducted a survey of 2,137 shoppers; of the women who make over $100,000 a year, 28% of them said they shop at TJX stores.

The focus is on “value,” not on “cheap.” A $3.99 T-shirt at Wal-Mart WMT is cheap. A $499.99 price tag for a $1,250 Stella McCartney dress, many would say, is value. And it’s a formula that works well in the coveted 18- to 34-year-old crowd, an age group of shoppers that have been increasingly flocking to TJX.

(Full disclosure: This reporter, who happens to be in that growing demographic, found herself particularly susceptible to TJX’s dark arts. Over the course of reporting this story, she purchased, in the following order: a baby outfit, a slotted spoon, pimiento picante spice, a pair of jeans, running sneakers and socks, two shirts, a dress, roasted edamame, potato chips, kitchen tongs, a dresser, headphones, an iPhone case, an umbrella, and wrapping paper. Total bill: $800.)

Play No. 3:
“The money is in the buy.”
TJX’s buyers make the model tick. “If you can buy it right, you can sell it cheap,” Davidowitz explains. “The money is in the buy. They know that better than anyone.” The company’s buying organization is considered one of the best in the business, and on Meyrowitz’s watch it has grown from a force of 450 to more than 900. In order to develop an expertise in a specific category of goods, TJX’s buyers focus much more narrowly than their department store counterparts; rather than be responsible for accessories, a TJX buyer might specialize in just handbags.

The off-price buying strategy differs so sharply from traditional retail that TJX spends a good deal of effort training its workforce. The company is one of the few retailers that still runs a robust training program, dubbed TJX University, where up-and-comers learn everything from handling themselves in the marketplace to the art of the deal. “It takes them years to perfect their craft,” says Avondale Partners analyst Mark Montagna. Adds a former executive, “It flies in the face of what you learn in Retail 101.” The training is rigorous because buyers are handed an enormous amount of autonomy. “Buyers are empowered to make decisions that most company directors would have to approve,” Sweetenham says. “It’s pretty hardcore because it has to be,” a former buyer told Fortune. “You’re negotiating millions of dollars.”

TJX-2

Unlike their department store brethren who purchase inventory seasonally, TJX buyers are in the marketplace most weeks of the year. (Many of the former buyers Fortune talked with said they left because the travel got to be too much.) Executives control “the open to buy”—the amount of money available to acquire inventory—in order to compel buyers to make purchases as close to need as possible. Meyrowitz once noted on an earnings call that the merchandise her buyers acquired only a week before Christmas made it into stores in time for the holiday.

Waiting longer often results in a better price but also gives the buyer more information about current fashion trends. The better the fashion, the lower the markdowns. “The department stores and specialty stores take the fashion risk,” explains Poppe of Ruane Cunniff & Goldfarb, “and TJX waits longer until they see what the reaction in the marketplace actually is.”

Most department stores set their pricing based on keystoning (essentially doubling the wholesale cost), but TJX buyers instead go into a negotiation knowing the price they need the product to sell for and work backward. If a buyer really loves a product, she might buy it for the likely selling price—expecting zero profit margin—just so she can have it on the floor.

Play No. 4:
Have the vendor make it for you.
Most shoppers think all of the goods at T.J. Maxx, Marshalls, and their sister chains are what the company calls “opportunistic buys”—overruns, closeouts, irregulars, etc. It’s a myth. For one thing, there simply isn’t enough of that kind of inventory to supply TJX, let alone the other off-pricers. (If there were, it wouldn’t reflect well on the business savvy of legions of suppliers.) Says Paul F. Rosengard, president and CEO of supplier Boston Traders, which sells outdoor lifestyle men’s apparel: “If, as a manufacturer, all of your shipments to the off-price channel were truly distressed goods, you’d be going out of business.”

TJX does get product from the opportunistic category. Department stores, for example, routinely return or cancel orders from manufacturers, and TJX finds deals there. But the company buys a surprising share of merchandise from its suppliers upfront, insiders say. Hard numbers are difficult to come by. “But if you saw the vendor’s revenue plan, TJX is included,” says D’Arienzo. Vendors, say experts, also produce excess inventory on purpose, hoping TJX will buy it. “It becomes a little bit of a blurry line between what’s off-price and what was built for TJX,” Poppe says. A former buyer explained it this way: “The vendor is fronting it.” One supplier told Fortune it’s risky, but it has allowed her to double her business.

In the past, the company has acknowledged that it also produces roughly 10% of its merchandise under hundreds of in-house labels—names like Frou Frou for pet products or Mercer & Madison for leather handbags. (TJX declined to provide an updated share.) Insiders say the ability to contract on the fly with manufacturers lets TJX offer customers at least some merchandise in a hot fashion trend (say, crop tops or slide sandals) when it can’t get enough brand-name supply. Notably, the private labels help in just the opposite circumstances as well: when brand names don’t matter a whit. Says Michael Tesler, a partner at consultancy Retail Concepts: “You don’t treasure hunt white sheets.”

Play No. 5:
Take it all.
Even when TJX is buying upfront, it can still secure a good price, thanks in part to its huge size. TJX’s suppliers likewise benefit from the same economies of scale. But an even more compelling reason to sell to TJX is that the company can help its vendors grow. “The magic sentence manufacturers wants to hear is, ‘We’ll take it all,’” a CEO of a rival retailer told Fortune. “Marmaxx [the division that houses Marshalls and T.J. Maxx] can do that.” The company is big enough that it can spread the merchandise—both the diamonds and the roughs—throughout its thousands of retail outlets. That also means that brands that don’t want to advertise that they’re selling in off-price chains aren’t as visible. TJX, in fact, doesn’t advertise any of the brands that are in its stores. Meyrowitz told USA Today in 2011 in a rare interview: “We’re absolutely fine with every vendor saying they don’t do business with us. It’s a very important part of our relationship.”

That’s part of why brands that 10 years ago would never sell to TJX today want to get in. Four sources tell Fortune that the company is Ralph Lauren’s biggest client. (Both Ralph Lauren and TJX declined to comment.) “Outside of true luxury brands, anyone who tells you TJX isn’t one of their top five customers is either lying or doesn’t have a successful business,” Rosengard says. Many vendors can actually make more money selling to TJX than to the department stores. That said, a brand that doesn’t sell in department stores is not as valuable to TJX buyers. If Macy’s M carries the label it helps validate the brands as well as the pricing.
TJX[1]

Play No. 6:
Suppliers aren’t used-car dealers.
One reason the supplier relationship with TJX is so strong is that it has gotten so bad with the department stores. “A lot of buyers beat up people in the market to try to get what they want, as if they’re making a one-time car buy and they’re never going to go back,” says a former TJX buyer. Department stores want concessions for advertising and markdown allowances. They want money for delayed deliveries and returns. D’Arienzo says he had a client pay $1 million in markdown money to a department store for a product that didn’t sell. “The contention between the two partners is really serious,” he says. Many describe it as adversarial.

By contrast, the buyer-supplier relationship with TJX has historically been more of a partnership. “They grew up needing to be the nice guy, needing people to sell to them,” Tesler says. TJX buyers are taught to make the vendor feel like it’s a win-win and to leave the door open if they can’t come to an agreement this time around. “They’ll make a deal with a vendor they know isn’t a great deal to maintain or establish a relationship with a brand they know is important,” Tesler explains. TJX also pays on time, which seems like a given, but suppliers can go out of business because they don’t always get paid.

With TJX, myriad sources told Fortune, you know what you’re getting. “TJX is going to squeeze you for the best price upfront, but that’s it,” Rosengard says. “That’s the good and the bad.” Some suppliers said the biggest drawback to selling to TJX is that the company doesn’t share as much data on how their products are selling as the department stores do.

Play No. 7:
Find a CEO who gets retail.
The emphasis on the buying culture goes back to Meyrowitz, who has retail in her blood. Her father was a wholesaler, her mother an artist. She was a salesclerk at Fortunoff while attending Rider University and started as an assistant buyer at Saks after graduating. In 1983 she landed at Hit or Miss, part of an earlier iteration of TJX (see sidebar), where sources say she became a protégé of T.J. Maxx founder Ben Cammarata. “He knew she had something special when it came to being a merchant,” says Steven Wishner, a former executive for the company. “She had it.” Cammarata is still the company’s chairman of the board. Meyrowitz became CEO in January 2007, not long after TJX suffered what at the time was reportedly the largest data breach in history. Today she’s the third-highest-paid woman CEO of a U.S. public company, according to Equilar.

People who have worked with Meyrowitz say she has an intuitive sense of the business because she’s been on the frontlines. “She’s one of the few executives that could do almost any merchant job in the company,” Sweetenham says. Meyrowitz has upgraded the stores, taking merchandise out and replenishing more frequently so they’re not as messy. She’s also raised the stores’ taste level, expanding T.J. Maxx’s Runway, which offers designer labels like Valentino and Armani, often from last season. TJX’s European business had been a particularly bright spot and is key to its overall growth. Here again, TJX seems to do things differently. U.S. retailers struggle in Europe, but TJX has prospered, by hiring European buyers to buy European product rather than attempting to force American brands on shoppers.

Meyrowitz is also finally addressing the one area where the company has clearly lagged: e-commerce. After acquiring Sierra Trading Post in 2012 to beef up its online sales operations, the company rolled out tjmaxx.com last year. The retail giant wants to have e-commerce sites for all of its businesses eventually, but it’s taking the time to figure out how to translate that treasure hunt feel online.

A hint of caution, maybe. But don’t take that to mean the company isn’t without grand ambitions. TJX executives have made it clear to analysts that, even without adding new retail chains and geographic markets to its roster, it has the potential to increase its store base by some 60%, to 5,150. (The company has not announced a time frame for this.) As for sales, even mighty Macy’s may one day seem like a piker compared with its off-price competitor. If both companies continue on their current growth trajectories, TJX will surpass Macy’s in annual sales in 2015. When that happens, it won’t be a secret.

This story is from the August 11, 2014 issue of Fortune.