FORTUNE — As the double-decker bus turns onto Charleston Road and starts winding through Google’s Mountain View, Calif., campus, I stretch out in the business-class-size seat, admiring the smoothness of the black leather and the plush gray carpeting at my feet. A spacious table expands to hold a laptop, which can connect to the vehicle’s Wi-Fi system. This $800,000 luxury double-decker is one of 73 buses that Google owns and operates. (It leases 26 others.) Each day the fleet transports about 4,500 employees, or about a third of those working at the Googleplex, as the company’s headquarters is known.
It turns out that Google (GOOG) isn’t offering a free ride simply as an employee perk — the buses actually save the company money. Yes, there’s the added productivity of 4,500 employees working an extra couple of hours each day while riding to and from work. But Google’s bus service is about much more than that. Real estate in Mountain View is expensive. Underground parking spaces cost as much as $85,000 to construct. (Really!) If Google had to build a parking space for each of the bus riders, the price tag would run to almost $400 million. And that’s not counting the lost opportunity cost of not using that land for new office buildings.
Google has made other investments in transportation too. If, during the day, a Google-ite needs to run an errand or pick up a sick kid at school, he or she can hop into one of 52 electric and hybrid cars parked on campus. The company also encourages employees to drive electrics. It has spent an estimated $3 million to $4 million to install 395 chargers — the largest corporate electric-vehicle infrastructure in the country.
More: Google – the best company to work for in the Fortune 500
Finding creative solutions to energy issues has become a major priority for Google co-founder and CEO Larry Page in recent years. For the obvious reasons — a growing population, increasingly scarce resources, and climate change — he believes that the corporate world needs to operate more sustainably, and he is determined to build the nation’s first zero-carbon company. This means a business that ultimately is so energy efficient and uses so much clean power that it emits no greenhouse gas — a very tall order indeed. Experts aren’t sure whether it’s even possible for a company to emit no carbon, but Google is trying to come as close to that goal as possible. “As we became a bigger user of energy, we wanted to make sure we were not just part of the problem, but part of the solution,” says Urs Hölzle, Google’s employee No. 8 and a senior vice president who oversees the company’s green initiatives.
To reach its audacious zero-carbon goal, Google is taking a three-pronged approach. First, it’s making its server farms, office buildings, and commuting habits more energy efficient. (Apparently Page’s Boeing 767, which he owns with co-founder Sergey Brin, doesn’t get counted in the equation.) Then the company is investing heavily — $915 million to date — in solar and wind producers to make clean energy more available. And finally it is buying enough carbon offsets to make the company carbon neutral — at least on paper — until it can meet its overall goal.
If the plan works, Page will have created a blueprint that other companies can use to reduce their own energy use and — as important — save money at the same time. But Google has already learned some hard lessons.
In June 2007, Page and his top execs issued a staff memo declaring that the company would become carbon neutral. The catch? The existing power infrastructure is so dependent on fossil fuels that no major company in the world has yet achieved this goal without buying carbon credits. Page began buying carbon credits from organizations that, say, capture methane from landfills to offset the greenhouse gas Google emits. Then he set the company on a long march to reduce the amount of energy it consumes while increasing its use of carbon-free wind and solar power.
Later that year Page, to the amazement of many in the IT industry, also announced that Google was getting into the clean-energy business. In a Nov. 27, 2007, press release, the company introduced an additional initiative based on the formula RE 9 C, which translates as “renewable energy is cheaper than coal.” Page believed Google could become carbon neutral faster by applying the formidable brainpower of its engineers to the problem. He wanted to help produce one gigawatt of renewable power — about the equivalent produced by a nuclear power plant — that was cheaper than coal within a few years. This goal, however, turned out to be more devilish than anyone thought.
Page asked his managers to focus on a basic question: How much carbon are we emitting? Google’s executives started asking themselves how they could use less power in their data centers, how they could make their office buildings more efficient, and where they could buy clean energy for their operations.
Becoming a zero-carbon company is no easy task. In 2011 — some four years after Page’s memo — Google reported that it still had emitted 1.5 million tons of carbon in the previous year. It was the first time Google had publicly revealed its carbon footprint. To put that in perspective, Google’s 30,000 employees and its fleet of data centers last year emitted the same amount of CO2 as a city the size of Fargo, N.D. (pop. 202,000). The good news: If the company hadn’t embarked on Page’s quest to become carbon neutral, the numbers would have been much worse. That 1.5 million tons of carbon is more than Google emitted in 2007, but much less than would have been expected considering that the company’s annual revenue since then has more than doubled, to $38 billion.
Google’s largest source of greenhouse gas emissions is its data centers — those buildings stuffed with computers that handle each of the 3 billion searches its customers perform every day. According to Jonathan Koomey, a Stanford professor, server farms account for about 2% of America’s total electricity use. (That’s roughly the same greenhouse gas impact as the airline industry’s.) However, they are one of the fastest-growing sources of CO2 emissions.
Server farms also account for Google’s biggest use of energy. One thing the company realized early on is that the managers in charge of building data centers were not the same people who operated them. “It’s incredible how much people waste in a company,” says Google executive Hölzle. “The facility department pays construction costs and utility bills, but the IT people buy the servers, so they don’t care about how much electricity they use.” To eliminate that conflict, Google made sure that the person paying the utility bills and the one buying the computers was the same.
Now the economic incentive exists to cut energy use. Typically a server farm consumes as much energy for lighting and cooling as for the computers themselves. By using customized hardware and applying innovative cooling techniques, the need for air conditioning is reduced. Joe Kava, Google’s director of data center operations, cites as an example the search giant’s new server farm in Finland — on the site of a former paper mill — that sits on the Gulf of Finland and uses seawater in its cooling system.
No matter how efficient Google makes its server farms, it will still need clean power to meet its zero-carbon goals. Soon after Page launched the RE < C program in 2007, he set up a handful of green skunkworks projects and created a team to make venture investments in green energy. Google put money into promising companies like BrightSource Energy, which is building a cutting-edge, solar thermal plant in the Mojave Desert. The search giant even had an internal engineering team working to improve a type of concentrating solar power technology called the solar power tower. It invested in AltaRock to foster innovations in geothermal energy. It also sponsored research to develop the first geothermal map of the U.S. to better understand the potential for geothermal energy.
Driving the price of renewables below that of fossil fuels is an ambitious goal, especially for a company that has no background in power generation. The energy field, as Google eventually learned, is much more capital-intensive and has a far longer time horizon than is typical in Silicon Valley — where a new company with a garage full of software geeks can scale to billions in revenue seemingly overnight. After four years of effort, Google quietly dropped its RE < C program in late 2011.
Google execs explain that relatively speaking, not much money was invested — perhaps $50 million. (Google has kept its equity investments in BrightSource and AltaRock but has disbanded its green-tech engineering efforts.) It couldn’t have helped that the company had been taking flak from a group of shareholders who didn’t understand why Google was spending money on clean tech. In 2011, Justin Danhof, the general counsel of a conservative think tank, the National Center for Public Policy Research, filed a shareholder proposal criticizing Google’s lack of transparency about its green investments. (It didn’t pass.)
More: Three keys to the next green business boom
While Google has abandoned its quest to be an innovator in clean-energy technology, it hasn’t stopped investing in green power. Today Google has signed contracts to buy about 12% of its total energy from wind and solar farms, up from 4% just two years ago. (Add in existing sources of clean energy on the grid, and that number rises to 27%.) “As a company we are looking at ways we can support the renewables industry,” says Rick Needham, Google’s director of energy and sustainability. “We have a long vision of being a company powered by renewable energy, but how do we get from here to there?” Google pays more for clean energy than it would for power off the grid. However, it has locked into long-term pricing contracts for renewables and expects those contracts to eventually make money as conventional power becomes more expensive over time.
Google has also been investing directly in wind and solar projects to the tune of $915 million. It began in 2008 by financing a couple of wind farms — in North Dakota and Oregon — in need of funding after the financial meltdown had frozen the capital markets. A key to Google’s strategy is that it wants the money it invests to expand utilities’ solar and wind operations; otherwise it won’t be adding capacity to the system. As the wind projects become operational and begin selling electricity to big utilities, Google gets a piece of the cash flow. This type of deal — a form of tax equity investment — gets sweetened by federal tax credits.
Google was one of the first companies — if not the first — outside the banking, energy, and utility sectors to start investing in these tax deals. Instead of keeping its cash in the corporate treasury and earning only 1% or 2% on it, it can earn as much as 15% to 20% through the tax credit investments, says Google.
The company may be increasingly cleaning up its act, but it is still a polluter. In the meantime, it continues to buy carbon offsets. Carbon offsets, however, are controversial. One common way is to, say, pay an organization to plant a tree to offset the carbon you emit when you fly cross-country. But how do you know if the tree ever gets planted or if someday a drought kills it? Some criticize offsets as just a guilt-free way to indulge in polluting habits.
Well aware of the problems posed by offsets, Google searched for ones that were verifiable and additional — meaning that the reduction in carbon is real and wouldn’t have happened without Google’s buying the offset. It decided the best way to create carbon offsets was to pay for reductions in methane emissions from landfills and swine farms. Says Jolanka Nickerman, Google’s program manager for carbon offsets: “The gold standard for offsets is methane gas, which is 20 to 25 times more potent than carbon dioxide.” These methane-capture projects can cost anywhere from $500,000 to $1 million. In Yadkinville, N.C., Google, in partnership with Duke Energy (DUK) and Duke University, helps the Loyd Ray Farms, home to 9,000 hogs, capture methane from manure to power its operations.
So far the company has spent upwards of $15 million investing in or purchasing carbon credits for dozens of such projects. That will offset about 5 million tons of CO2 — more than enough to make Google a carbon-neutral company on paper.
When asked how long it will take to become a truly zero-carbon company, Google execs say they don’t really know. What they do know is that the green program has made the company stand for something more than just making money. That’s a message that Google’s bus riders are reminded of each day.
This story is from the July 23, 2012 issue of Fortune.