Dick Costolo is breaking a sweat. The chief executive officer of Twitter (twtr) has plenty to fret over: Earlier in the day hackers had hijacked his chief financial officer’s tweets, sending out hundreds of spam links to followers and bringing to the surface, yet again, fears over compromised accounts. The week before, even as the social media company announced quarterly revenue and earnings that beat expectations, its disappointing user growth came under scrutiny (the company has just a quarter of the user base amassed by social-networking behemoth Facebook (fb)). What’s more, the recent departure of several top executives has refueled concerns over management’s ability to clearly define its strategy, not to mention hold on to key employees. At the moment, though, none of those stresses are the cause of Costolo’s perspiration. The culprit? A grueling fitness craze called CrossFit, which combines Olympic-size body weights and intense cardio moves in a single workout. In a red T-shirt and black shorts, the bespectacled actor turned Google (goog) exec turned CEO crouches down to touch his toes, then hurls his wiry frame back and forth across the 45-pound barbells on the floor in front of him. Finally, he picks up the massive weights and lifts them over his head with a huff.
Welcome to Twitter —or more accurately, the San Francisco–based company’s second-floor gym. The nine-year-old microblogging service, which makes its debut on Fortune’s Best Companies to Work For list at No. 24 this year, has had its fair share of ups and downs. Case in point: After going public in late 2013, its stock rose 282% but is now trading just slightly above its opening price. Despite the fluctuations—not to mention management’s decision to put down roots in one of the Bay Area’s grittiest neighborhoods (more on that later)—Twitter has become a sought-after place to work in the region. An average of 230 applicants vie for every open position, angling for a way to become part of a company many believe will continue to change the way we disseminate and consume information. Onsite perks such as free yoga and improv classes and all the food you can eat help attract talent, but those are staples in many tech companies. Even more attractive, say many employees, is the desire to “make a difference,” both in the world at large and in Twitter’s own backyard. The fact that it’s the kind of place where, despite its ballooning workforce, you can still sweat alongside your CEO is an added bonus.
“When you work at Twitter, you get an opportunity to work at a company and on a platform that is visibly changing the world every day,” Costolo says during a phone interview a week after the CrossFit class (and, incidentally, a few days after he fractured his collarbone on a ski trip).
Before joining Twitter in late 2009, the athletic CEO spent a couple of years as an exec at Google. Its influence on Twitter’s informal culture is apparent. Twice a month Costolo assembles the entire employee base in a light-filled open area near the company’s massive cafeteria. (Twitter occupies seven of the 11 floors in the building; the crown jewel is a 16,500-square-foot rooftop deck, where workers lounge on outdoor couches and synthetic grass.) Costolo and the rest of Twitter’s 10--person management team use the twice-monthly “tea times” to update employees on company milestones and goals, answer impromptu questions from the crowd, and highlight popular tweets and world events captured on the service. The same all-hands approach is taken every time the company releases quarterly earnings—employees are called into the common area, the numbers are explained, and questions are answered.
“I’ve always felt it was important for me to be present, for anyone in the company to feel like they could walk up to me and have a forthright conversation with me,” says Costolo. “As you grow as a company, the view from the top becomes more and more distorted. So I really go out of my way to be present and show the employee base that I think of them as peers and colleagues, and I encourage them to challenge my thinking and engage in sharp questions with me.”
Costolo even makes an appearance on the first day of each weeklong orientation for new hires, internally known as “Flight School.” During the course of the orientation session, recent hires are taught tweeting guidelines—confidential information that is shared during the company’s all-hands meetings, for example, must not be repeated. They’re also given a tour of Twitter’s headquarters, including the Lodge, a communal area where two real log cabins—sourced from Craigs-list—are used for meetings and social events (wine, beer, and kombucha are all on tap). The large television screens, roomy leather booths, and high-rise tables and chairs in the Lodge give the space a comfy, lounge-like feel. Elsewhere in the office employees sit in open-floor formation and are free to move about from place to place, toting laptops stickered with Twitter’s signature blue bird.
“It’s not working in a garage, but it’s also not a place where the future of the company is set in stone,” says Alex Roetter, a VP of engineering.
Indeed, Twitter’s fate is still up in the air. Even as the company’s revenue and earnings continue to rise, Wall Street has worried about its slowing user growth. Some investors have even called on Costolo to step down. (The CEO says he loves his job and told Fortune he doesn’t know where recent rumors of a possible departure came from.) The situation in Twitter’s own neighborhood has also been precarious at times.
Every day about 2,000 workers flock to Twitter’s offices on the outskirts of downtown San Francisco. (Another 1,600 employees work in other hubs around the world.) The so-called Twitterloin—located at the edge of the city’s Tenderloin neighborhood—is home to decrepit hotels, strip clubs, and many of the city’s homeless. It also has a high crime rate. Earlier this year a suitcase full of dismembered body parts was found nearby.
To be sure, Twitter isn’t the only tech company to have set up shop in the area: The city of San Francisco has offered extensive breaks on payroll taxes for companies that move into the long-neglected neighborhood, and the list includes other hot tech startups like Square, Uber, and One Kings Lane. But Twitter was among the first to do so (the tax incentive is colloquially referred to as the “Twitter tax break”) and remains the largest tech employer in the neighborhood. The company’s execs say that they are not only committed to staying in the area but also encouraging their employees to help the local population—and claim the desire to do so is actually enticing workers.
“If you want to attract the best talent, this is key,” Caroline Barlerin, head of community outreach and philanthropy at Twitter, says of the company’s efforts to do good in the neighborhood.
Last year Twitter shelled out more than $367,000 to local nonprofits. Employees regularly volunteer at the nearby Boys & Girls Club, churches, and public schools, mentoring children and serving meals. The company has donated laptops and other equipment to neighborhood centers and provided its office space for nonprofits to host events and fundraisers. The company’s biggest push to aid the nearby community is the soon-to-be-opened Twitter NeighborNest, a learning center it is building just across the street from its office. The space will be fully staffed by Twitter volunteers and will offer free computer classes (with child care) to anyone in the area.
“I wanted the employees here to feel that we are putting down roots in the community,” says Costolo. “In order to do that they have to be a part of that community.”
While Twitter is still far from making a profound impact on the Tenderloin (some argue that its presence will have a detrimental effect on the area’s residents because of the inevitability of gentrification), its dicey location doesn’t seem to be scaring off employees. Neither does its uncertain ability to keep growing its user base at a fast enough rate. And young engineers aren’t the only ones drawn to Twitter’s Art Deco headquarters. Its offices have been visited by a steady stream of celebrities and world leaders, including Seth Rogen, Lena Dunham, and Hillary Clinton.
That kind of exposure is one of the things that has made Twitter a special place to work—even in a region flush with onsite massages, free snacks, and CrossFit sessions with CEOs.
This story is from the March 15, 2015 issue of Fortune.