The work “hack” used to be a term of approbation among geeks, as a means of describing an elegant way of circumventing a difficulty that had defeated lesser minds. In the old days, a good hacker was someone constantly on the lookout for better ways of writing code and there’s a sense in which the young Edward Snowden was one of those. At high school, he resented the way homework absorbed valuable time that he would have preferred to spend at a computer. So he analysed the marking system and realised that it could be “hacked”: if he just did the quizzes, he could get enough points to get by. He stopped turning in homework until one day his maths teacher questioned him and discovered his methods. “Pretty clever, Eddie,” he said, “but you should be using that brain of yours not to figure out how to avoid work, but to do the best work you can. You have to start thinking about your permanent record.”

Well, eventually Snowden did, and this fascinating autobiography is the result. It tells the story of how an intense, bright, serious boy from a patriotic, quasi-military family (father in the coast guard, mother working as a clerk at the National Security Agency) came to tell the world how his beloved country’s intelligence services had covertly pivoted from protection to mass surveillance in the name of national security. And in the process did us a great service.

As a teenager, Snowden once visited the website of the Los Alamos nuclear research laboratory and noticed that it had a gaping security hole. So, being the kind of kid he was, he phoned the lab and left a message telling them about it. Nothing happened for a while; then one day the Snowdens’ phone rang. It was a guy from Los Alamos thanking him for spotting the vulnerability, which they had now fixed. The man asked if he was looking for a job. Snowden replied that he was currently pretty busy at high school. “Well, kid,” said the lab guy after a pause, “you’ve got my contact number. Be sure and get in touch when you turn 18.”

The first pivotal moment in Snowden’s life was 11 September 2001. Living, as he did, in the shadow of NSA HQ in Maryland, he felt the seismic shock of the 9/11 attacks on the US. His response was to join the army as a way of serving his country. His parents, being navy folks, were not amused. The army flagged him as a possible special forces prospect and sent him off to Fort Benning for training. But a bad fall broke some bones and led to him being effectively invalided out of the service. Concluding that if he couldn’t serve his country by parachuting into dangerous places that he’d have to do it using his computing skills, he applied for security clearance and spent the year recuperating from his injuries while Uncle Sam crawled over his background, family, records and innermost thoughts.

Instead of being in the business of targeted surveillance, the NSA had moved into the business of mass surveillance

He got the top-level clearance – TS/CSI in the jargon – which was the requirement for serving in the NSA and the CIA. But jobs in those agencies were scarce, while jobs in the contractors that worked for them were plentiful, so Snowden went to work for one of those. In the process, he discovered that much of the work of the US’s intelligence agencies is actually done by private contractors rather than by civil servants. This is partly an administrative dodge to circumvent federal limits on hiring government employees and the fact that Snowden was for most of his career “merely” a contractor was later used to discredit him.

This was misleading because contractors with Snowden’s level of security clearance were effectively employees of the NSA or the CIA, depending on the nature of their employers’ contracts. In Snowden’s case, as a system administrator (sysadmin in the jargon), he consistently had astonishing access to the most sensitive files of both agencies, access that he eventually used to great effect. One of the biggest mistakes that hierarchies in big organisations make is to underestimate the importance of the sysadmins who keep the IT systems going. They are often the people who know everything, because everything is digital and they have to have access to it to do their jobs.

It was his unparalleled access to sensitive material that led to the second pivotal moment in Snowden’s life. Working for the NSA in Japan, he came on the classified version of a government inquiry into the controversial “President’s Surveillance Program” (PSP), authorised by George W Bush in the wake of 9/11.

This, Snowden realised, bore no relation to the unclassified report that had been released to Congress. Instead, the secret version provided “a complete accounting of the NSA’s most secret surveillance programs, and the agency directives and Department of Justice policies that had been used to subvert American law and contravene the US constitution”.

Instead of being in the business of targeted surveillance, of which Snowden approved, the NSA had secretly moved into the business of mass surveillance – collecting every kind of electronic communications and storing it indefinitely. This was dynamite for a young man who read the constitution the way devout Christians read the Bible. And it eventually led to Snowden becoming the most celebrated whistleblower of our times.

The closing part of the book is a riveting account of the way Snowden went about acquiring documentary evidence of the tools and approaches that the NSA developed in order to comply with the “never again” orders they had received from their political masters in the wake of 9/11. He turned out to be astute and careful in both amassing the material and in choosing who his journalistic partners in the revelatory enterprise should be. He is also refreshingly frank about the emotional torment that this secretive project imposed on him, particularly his anguish at having suddenly to abandon his beloved girlfriend, Lindsay, without being able to give her any warning of what he was about to do. If anybody thinks that whistleblowing is easy, then they haven’t ever done it.

Snowden is paying a heavy price for his actions, living in Moscow, though reunited with (and happily married to) Lindsay. Many people in the US regard him as a traitor or a criminal; many others, me included, see him as a hero. The key question is whether, in the end, his revelations led to constructive change. The answer, I believe, is that they did – up to a point. Before Snowden, for example, western democracies had lamentably inadequate democratic oversight of their intelligence agencies. Post-Snowden, they have slightly less inadequate oversight arrangements, for example, the UK’s Investigatory Powers Act. In an imperfect world, that’s something. So two cheers for Edward’s neat hack.

• Permanent Record by Edward Snowden is published by Pan Macmillan (£20). To order a copy go to guardianbookshop.com or call 0330 333 6846. Free UK p&p over £15, online orders only. Phone orders min p&p of £1.99