The outgoing chief of GCHQ has used his valedictory speech to defend the agency's work and methods, and to insist it is not involved in the mass surveillance of internet users.

The surveillance agency has been stung by revelations from former NSA contractor Edward Snowden about the secret mass surveillance of internet users — for example, according to The Guardian, GCHQ intercepted millions of Yahoo webcam images over a four-year period, whether the users were intelligence targets or not.

Read this GCHQ to take hub role in UK cybersecurity The UK government has unveiled a new cybersecurity strategy, which calls on GCHQ to run a hub where businesses can put aside their hesitations to share information on threats between themselves and the public sector Read More

Another leak revealed GCHQ's interest in monitoring use of Facebook and YouTube, while another detailed GCHQ's attempts to collect data from smartphone apps.

Sir Iain Lobban, the departing director of GCHQ, gave his farewell speech at Whitehall's Cabinet War Rooms and, while he did not mention Snowden directly, much of it was given over to the emergence of the internet both as a source of intelligence and as a venue for crime.

He described the growth in internet usage as "the biggest migration in human history" with almost 1.5 billion people going online in the last six years, but insisted that it needed to be policed.

"We all know that the beautiful dream of the internet as a totally ungoverned space was just that — a beautiful dream. Like all utopian visions, it was flawed because it failed to account for the persistence of the worst aspects of human nature," Lobban said.

"From what we know of ungoverned spaces in the real world, do we really believe that the world would be a better place if the internet becomes an ungoverned space where anybody can act freely with impunity?"

Lobban said that the vast majority of these threats to the UK are posed by groups or individuals based overseas. This means that GCHQ needs strong intelligence and cyber capabilities to identify them and, where international law enforcement doesn’t work, "to disrupt them directly", he said noting that "this combination is increasingly essential".

"Those who would do us harm don't want to be found. They choose certain routers or applications to hide in the darkest places of the internet. We have to enter that labyrinth to find them. We work to crack their defences."

He said to find these threats GCHQ needed to "search for them in the vast morass of the internet", but insisted that only a "small percentage" of global communications were within reach of GCHQ's sensors — and of that it only intercepts a small percentage of them, of which only a small percentage is ever viewed or listened to.

However, he conceded "we access the internet at scale", but said this was done "so as to dissect it with surgical precision. Practically, it is now impossible to operate successfully in any other way," and insisted it wasn't possible to catch terrorists without what he described as "incidental collection of data at scale".

Lobban also said that the core of GCHQ's mission is to protect liberty, not erode it, adding: "The people who work at GCHQ would sooner walk out the door than be involved in anything remotely resembling 'mass surveillance'."

As a result of the controversy around GCHQs surveillance efforts, the spy agency has been forced to be more open about its work and the threats it tackles.

For example, Lobban said that in the middle of the summer as he had been preparing the speech "nearly 200 cyber incidents against the UK’s networks of national significance were detected and responded to". Earlier this year it was revealed that state-sponsored hackers had infiltrated the UK government's secure network .

Now read this