Hackerspaces are the digital-age equivalent of English Enlightenment coffee houses. They are places open to all, indifferent to social status, and where ideas and knowledge hold primary value. In 17th-century England, the social equality and merit-ocracy of coffee houses was so deeply troubling to those in power that King Charles II tried to suppress them for being "places where the disaffected met, and spread scandalous reports concerning the conduct of His Majesty and his Ministers". It was in the coffee houses that information previously held in secret and by elites was shared with an emerging middle class. They were held responsible for many of the social reforms of the 18th century, when English public life was transformed.

Hackerspaces could prove to be as important for reform in the digital age. While collectives of rogue hackers such as Anonymous and Lulzsec have grabbed headlines with their mischievous hacks of personal information from Sony, News International and governments, hackerspaces have quietly focused on creating alternatives to the things they see wrong in society: secretive government, unfettered corporate power, invasion of privacy. Bradley Manning, the US Army intelligence analyst accused of leaking files to WikiLeaks, attended the launch of BUILDS, a hackerspace at Boston University last year. In Sweden the hacker collective Telecomix has been involved in keeping lines of communication open in middle eastern countries when political leaders shut down networks.

As part of the research for my book, The Revolution Will Be Digitised, I travelled to Berlin to meet the group of hackers known as the Chaos Computer Club (CCC). The Club was so named not because it set out to cause chaos but rather because one of the founders, Wau Holland, felt chaos theory offered the best explanation for how the world actually worked. Dutch hacker and entrepreneur Rop Gonggrijp says the club is about "adapting to a world which is (and always has been) much more chaotic and non-deterministic than is often believed".

In Berlin, just after Christmas last year, more than 2,000 hackers and information activists gathered at the CCC's annual conference to discuss technology and the future. Gonggrijp gave the keynote speech, which was startlingly prescient in light of subsequent uprisings, revolutions and riots. "Most of today's politicians realise that nobody in their ministries, or any of their expensive consultants, can tell them what is going on any more. They have a steering wheel in their hands without a clue what – if anything – it is connected to. Our leaders are reassuring us that the ship will certainly survive the growing storm. But on closer inspection they are either quietly pocketing the silverware or discreetly making their way to the lifeboats."

The hacker community may be small but it possesses the skills that are driving the global economies of the future. So what is a hacker? Hackers often describe what they do as playfully creative problem solving. It's much easier to attack than to defend a system, so the best hackers are those who build things. The ones who break them are known as "crackers". The world wide web, and free software operating systems such as the GNU Project and the Linux kernel, could all be considered hacker creations. Even Facebook began as a hack. That is not to say hackers don't attack systems and take things apart. They do, with a compulsive glee, and the more adolescent hackers use their skills as much to show off to each other and rebel against authority than for any greater good. There are good hackers and bad hackers. Some of the best hackers say the line between hacker/cracker or white hat/black hat (ie, good/bad) is of little relevance. Some are amoral, interested only in the intellectual challenge, while others think the ethics behind hacking are all-important. A hacker could use his skill to protect a system he knows is used to track down and kill protesters. He's not "cracking" but how can he be considered a white-hat hacker? The ethics of hacking, like life, are slightly more complicated than a 1950s western movie.

Some who have hacking skills want nothing to do with a community they see as comprised of "alpha geeks" – macho, misogynistic thugs and vandals. "A lot of them are just selfish teenage assholes," says Benjamin Mako Hill, a student at MIT's media lab specialising in sociology and online communities. "Most grow out of it, others go on to do computer security." Certainly that is the impression one gets from reading the chat logs of some Anonymous members. Even within the hacker scene there are divisions. An older hacker known as Virus recently described the younger hackers of Anonymous as "nothing but a bunch of fat, pimply basement dwelling losers who masturbate 3+ times a day".

If Anonymous and Lulzsec are the id of hacking, then physical hackerspaces are the heart of the higher-minded hacking ideals: freedom of information, meritocracy of ideas, a joy of learning and anti-authoritarianism. The CCC is Europe's largest hacker organisation and also one of the oldest worldwide, having been set up in 1981 by Wau Holland and others who predicted the rising importance digital technology would have in people's lives. CCC's hackers are often older and run their own businesses. They hold conferences and even consult with the German government. The CCC is famous for exposing the security flaws of major technologies, from chip and PIN to smartphones. Want to know how to listen in on GSM mobile phone traffic? Here's the place to learn (within legal constraints, of course). Among some of their more noteworthy "hacks" is pulling the fingerprints of the German interior minister from a water glass and putting them on a transparent film that could be used to fool fingerprint readers. The Club also worked with activists for voting transparency to expose flaws in computerised voting machines. These were later ruled unconstitutional in Germany and abolished in Holland.

The CCC isn't just about technical hacking, it is a hub of political activism based around a few common goals: transparency of governments, privacy for private people and the removal of excessive restrictions on sharing information. Many of these hacks are demonstrated at the annual conference at the Berlin Congress Centre, and it was here that Julian Assange presented WikiLeaks to an enthusiastic crowd in 2008.

The CCC has its own permanent base on Marienstraße in Berlin. It's not a secret and you'll find "Chaos Computer Club" listed on the bell push of the neo-classical building. You pass through a stone walkway to an inner courtyard and on the far right side is the entrance to the CCC. Inside, there's a collection of desks pushed together, well-worn office chairs and sofas and coils of wires strewn across most surfaces. Crates of Club-Mate, a soft drink beloved by hackers for its high caffeine content, are piled at the back and dispensed from a defaced Coke machine. Someone has drawn a noughts and crosses board in the dusty screen of an old video game, Ideal Twinline, and underneath, the words, "How about a nice game of chess?" There are posters on the walls: "Liberty waits on your fingers" and "Keep on blogging".

Hackerspaces aren't just about hacking with computers. The ideals can be applied to every aspect of life including politics – which is considered just another "system" by which humans live together. Like any other system, it can therefore be hacked and these spaces offer a real-time experiment in political hacking. They often contain power tools, industrial cutting machines, sewing machines and sometimes even kitchens for "culinary hacking". At the tiny hackerspace HACK (the Hungarian Autonomous Center for Knowledge) in Budapest, members have built an electronic plantwatering system, and at Sprout in Cambridge, Massachusetts, I saw an MIT student building a jet propeller. In large spaces such as Noisebridge in San Francisco members have created an active space-exploration programme sending weather-balloon probes up to 70,000ft in the sky to collect images and data using GPS smartphones and digital cameras. Access to and membership of the spaces is usually governed by commonly agreed norms, but notably there is a lack of formal rules. Asking permission is frowned upon as it implies a power imbalance. The chosen way is to observe the culture and then seek agreement.

"What we've done at Noisebridge is not to say how bad everything is but to create a viable alternative," says Jacob Appelbaum, one of its founders. "I wanted a space where we could make things come true. Almost like a magical environment where we could decide one day we wanted to have a space programme and then ... we did. That's not going to happen in a cafe. There currently isn't a public place where you can have a lathe or a table saw or computer access or couches where you can sit, where no one feels entitled to throw you out. The closest thing is the university lab where I work now but there we're beholden to university administrators. In this place we are beholden to no one but ourselves."

I caught up with Appelbaum in Seattle, where he's now a staff research scientist at the University of Washington. He explained that the political ideology of the hackerspace is probably nearest to libertarian, "in the liberty sense". Anyone who wants to contribute something, whether time, money or ideas, is welcome. The ability to do things is dependent on being accepted by the group, and that comes when one's actions have merit. Appelbaum says that Noisebridge is run along anarchist principles of mutual aid, solidarity and respect. He is keen to stress that this is not anarchy in the sense of chaos but as author Emma Goldman describes it: the liberation of the human mind from religion, property and government, "a social order based on the free grouping of individuals for the purpose of producing real social wealth".

The group makes decisions based on consensus. "It can take a while," he admits, but the advantages outweigh the costs. "In our society people don't have a lot of agency to change things. And when I say 'our society' I mean 'the world'. Sometimes in our discussions it will be the first time that someone has ever felt listened to in their entire lives. That's actually incredibly sad but I'm happy we can give them that opportunity. I think there are a lot of us who don't think the world is as we would like to see it. And anyone who is not a utopianist is a schmuck."

Even in the world of hackers and web revolutionaries, Appelbaum's dedication to the internet is startling (it is "the only reason I'm alive today", he once told Rolling Stone magazine). He found in computers an escape from a chaotic upbringing and credits his skill in technology for moving him out of America's underclass and into the middle class. As well as working at the university he is also a spokesman for Tor, a free internet-anonymising software that helps people defend themselves against surveillance, and he is spent five years teaching activists how to install and use the service to avoid being monitored by repressive governments. Now he himself is frequently targeted by the US government as a result of his relationship with WikiLeaks, which used Tor software.

Sometimes, though, hackers don't realise they are no longer outsiders but have their hands on the levers of power. Tech writer Danny O'Brien points to Bill Gates, who continued to believe right up until the anti-trust lawsuits of the 1990s that Microsoft would be destroyed by big powerful companies such as IBM – despite the fact that he was, by then, one of the world's richest men and Microsoft the world's biggest IT company. Furthermore, it can prove difficult to reconcile the subversive hacker mindset with the demands of running a multinational firm. A robust disregard for intellectual property in youth, for example, is often replaced with a cadre of lawyers enforcing draconian copyright law once the requisite information has been hacked, the product built and the company made profitable.

O'Brien is himself an embodiment of the transformation. This once-shabby Londoner, who wrote a tech newsletter called Need To Know, meets me in a swish cocktail bar in Palo Alto, California. "When we wrote [NTK] originally, geeks were under-represented; an unconnected group of outsiders who were excited about technology. But now the story is how much ridiculous power we have and how we're misusing that power or unaware of it."

• The Revolution Will Be Digitised is published by Heinemann at £12.99. To order a copy for £10.39 with free UK p&p go to theguardian.com/bookshop or call 0330 333 6846.