The Secrets of Whitehall reveals it is the cabinet secretary who holds the real power in government.

A seasoned Whitehall observer once said: "All the great Whitehall offices are about something. The Treasury is about money, the Home Office is about crime and the Cabinet Office is about power."

The Cabinet Office is the secret powerhouse of British politics. With the key task of keeping the government show on the road, it likes to do its work out of the limelight.

But a year ago the Cabinet Office became the centre of the political and media world when negotiating teams from the Tories and Lib Dems went to a series of meetings there to hammer out the Cameron-Clegg coalition deal.

Its entrance on 70 Whitehall briefly became the most photographed front door in Britain, eclipsing even the black door of Number 10.

Behind the Cabinet Office's green doors you find the sinister-sounding Cobra - the government's high tech anti-terrorist intelligence and emergency centre.

Image caption Current incumbent Sir Gus O'Donnell has been called "the man who really holds the ring"

The task of overseeing the security of the state is delegated by the prime minister personally to his top civil servant, the cabinet secretary.

Working from one of the grandest offices in Whitehall, the cabinet secretary is the most powerful unelected member of the government - the real-life Sir Humphrey from the programme Yes, Prime Minister, and he pulls the invisible strings across the whole of government.

There have only been 10 cabinet secretaries since the Cabinet Office was formed nearly a century ago, but there have been three times that many different governments.

The relationship between the Sir Humphreys and their prime ministers form a hidden history of modern Britain.

In Whitehall where knowledge is power, the cabinet secretary knows the most of all.

To beat the record of the first Cabinet Secretary, Sir Maurice Hankey, I would have to do another 17 years - and I am not going to do that Sir Gus O'Donnell, Cabinet Secretary

He (they have always so far been men) is allowed to see the papers of previous governments, a privilege not even extended to the prime minister, to whom the cabinet secretary is the chief adviser and "father confessor". He sits at the right hand of the prime minister in all cabinet meetings.

My documentary for BBC Four tells the story of these discreet but hugely influential figures, most of whose names are unknown to public. For until recently they remained in the shadows - the anonymous keepers of the government's secrets.

The Cabinet Office itself was born in 1916 during World War I which revealed the shambles of communication between the Cabinet and the military, with orders being confused and not acted on.

Things came to a climax with the disastrous battle of the Somme, which cost many thousands of British lives and led directly to the creation of the Cabinet Office.

The first cabinet secretary was a marine called Maurice Hankey, known in Whitehall as the "Man of Secrets".

The then Prime Minister Lloyd George gave Hankey the key task of completely reorganising the way his government was run.

A streamlined war cabinet was created and Hankey's job was to ensure its decisions were circulated and carried out across Whitehall.

At the end of the war Hankey was voted a bonus equivalent to £1m in today's money.

Image caption The historic cockpit passage links the Cabinet Office and Number 10

All five of the surviving cabinet secretaries, including the current holder Sir Gus O'Donnell, talked to me candidly about their way of operating within Whitehall's secret citadel.

And they told of how they got on - or not - with the different prime ministers they served.

The Cabinet Office itself is joined to Number 10 by a passageway with a high-security entrance.

Sir Gus himself has now served three different prime ministers, but he told me: "To beat the record of the first Cabinet Secretary, Sir Maurice Hankey, I would have to do another 17 years - and I am not going to do that."

But he added: "I still love it. It's the most fantastic job, with new challenges every day."

The coalition government has made Sir Gus the highest profile cabinet secretary so far.

He takes the stage at public events with the prime minister and his deputy, looking every inch the third among equals.

Indeed, at a recent event, the deputy prime minister introduced the cabinet secretary as "the man who really holds the ring". Maurice Hankey would have been proud.

The Real Sir Humphrey, the first of Michael Cockerell's new three-part series The Secret World of Whitehall, is on BBC Four at 2100 GMT Wednesday 16 March.