President Donald Trump and his Republican allies are right about one thing: Former FBI Director James Comey really is the embodiment of the “deep state.”

That’s just not the indictment of his character they think it is.

In his book, A Higher Loyalty, and the media blitz that has accompanied it, Comey has made it clear that even though he’s spent most of his career in government — as a federal prosecutor who went after Mafia families, the US attorney for the Southern District of New York (the most powerful US attorney in the country), deputy attorney general under President George W. Bush — he sees himself as a different, more noble creature than the politicians around him.

Trump, who fired Comey last May (and who has taken to calling him a “slime ball” on Twitter), is reminiscent of a mob boss in his demands for loyalty and constant lying; former Attorney General Loretta Lynch, meanwhile, attempted to intrude into the FBI investigation into Hillary Clinton’s use of a private email server in a way that made Comey “queasy.”

But Comey doesn’t characterize himself as the only noble man in Washington. He’s part of a brotherhood of noble public servants — law enforcement and intelligence officials — whose internal code of honor supersedes their loyalty to the agenda of the government officials they ostensibly serve.

That’s not the conspiratorial, fifth-columnesque “deep state” of fevered Trumpian imaginings. Comey’s Sam the Eagle-like rectitude is an embodiment of the attitude the FBI has often had toward politics in general, and even toward the political appointees who oversee it at the Department of Justice and the White House: an aloof superiority that, when challenged, stiffens into prickly independence.

It’s this institutional culture that’s put the FBI, which is usually characterized as Republican-leaning, in the odd position of being seen as a bastion of the anti-Trump “deep state.” The investigation into Russian influence in the 2016 presidential election, and now into whether the president obstructed justice by firing Comey, is led by former FBI Director Robert Mueller. Comey has become a leading critic of the president. Deputy Director Andrew McCabe was hounded out of the bureau and stripped of his pension; agents Peter Strzok and Lisa Page have become leading figures in a conservative conspiracy theory.

It might seem ironic, if you know the bureau’s history, that the FBI is being cast as a bunch of defenders of the American republic by some in the #resistance, and as a bunch of fifth-columnists by some on the right. But it’s actually perfectly explicable.

The very things that make the FBI, or organizations like it, troublesome or even dangerous under better circumstances and better presidents are the things that make it best equipped to resist abuses of power.

The FBI might take down President Trump; it’s inevitable that they would be the ones to do it.

To successfully be apolitical, there has to be something else for which you’re striving

One of the most striking things about Comey’s public comments in his new life as an author-pundit is his willingness to describe current or former Trump administration officials — his former colleagues — as corrupt or complicit. Take his assessment of Deputy Attorney General Rod Rosenstein, who is currently responsible for overseeing the Mueller probe and who has also been criticized by Trump allies as a Comey crony and a “deep state”-ist:

.@Comey says Deputy AG Rosenstein "had acted dishonorably by putting out this pretext about why I was fired." pic.twitter.com/Yfybm68sgF — Evan McMurry (@evanmcmurry) April 16, 2018

Comey’s distrust of Rosenstein isn’t unjustified. We still don’t know what exactly Rosenstein knew about the real reasons that Trump wanted Comey fired, but the fact that Trump’s recent tweets criticize Comey for going too easy on Clinton, while Rosenstein’s memo justified firing Comey for being too harsh on her, certainly raise good questions about whether the memo was really the main reason Comey got fired.

Rosenstein’s stumble isn’t the exception in this administration; it’s the norm. One of the most striking features of the Trump era is how consistently people who work for or with it end up debasing themselves — whether they’re defending conspiracy theories or fantasy math, praising the intelligence of the president after news reports that they called him a “moron,” or being forced to defend the intelligence decisions of a man who refuses to listen to his intelligence briefings.

The fact of the matter is that, from the inside, it’s not always easy to draw a bright line between doing your job and doing something in defense of your boss that is morally indefensible. While everyone fantasizes that he or she would be the person to refuse an unethical command, it’s not always easy to trust your intuitions that something is immoral — especially if speaking out would go against achieving whatever policy goals one might have as a Republican official in a Republican administration, or a Republican lawmaker under unified Republican government.

If you can’t rely on your own intuitions, then, you need some external code of behavior to guide you.

The “rule of law” is a procedural value: It says that the right thing for the government to do is to set, and adhere to, proper processes in all cases, without favor or prejudice to where those processes might lead. No man is above the law and no man strong enough to defeat it; and upholding the law means going about things “the right way.”

Take the choice Comey faced, as described in his book (and the Senate testimony he delivered last summer), about what to do after President Trump urged him in a private meeting to “see his way” to letting ex-National Security Adviser Michael Flynn go without charges. To act in service to politics (the president being, after all, his ultimate boss), he could have passed on the president’s instruction and urged the investigators to turn their attentions elsewhere. To rebel, he could have passed on the president’s remarks as possible evidence in the investigation — or ordered the bureau to start investigating Trump himself.

He did neither. Instead, he recorded the conversation in a memo but deliberately didn’t tell the people working on the Russia investigation about it because he wanted the investigation to unfold exactly as it would have in the absence of presidential pressure.

That certainly wasn’t the only correct decision, or even the most correct one. But it’s the decision that Comey could make without having to trust his own gut about right and wrong — it’s the decision that he could be held accountable for and defend according to the code of his agency.

That’s what professionalism meant to him. He immediately, and clearly, saw an ethical breach open up and sought to prevent it from occurring. But, in Comey’s telling, it simply deepened his commitment to doing the job.

Of course, everyone’s the hero of his own story, and Comey may well be engaging in a little self-aggrandizing. But it’s all the more revealing that, given the chance to cast himself as a hero, this is the heroism he chose. Comey was self-consciously making himself into an avatar of the “dogged FBI agent” — and by doing so, reinforcing (for current FBI agents as well as the general public) the idea that this is what every FBI agent should strive to be.

The institutions strong enough to undermine leaders are also the ones strong enough to resist tyrants

The term “deep state” has gotten stretched beyond recognition in the hands of Trump allies. As often as not, they use it to mean nothing more than “there are lots of people in the federal government who are liberals, and therefore they’re going to try to undermine the president’s agenda from the inside.”

It’s a conspiratorial concept that barely deserves debunking, but here goes: The federal government doesn’t act with a single mind. There’s a tremendous amount of squabbling between departments, agencies, offices, and individuals: everything from debates over strategy to fights over scarce resources to management/labor disputes and bureaucratic turf wars.

The institutions that come the closest to acting with a single mind are the ones with a robust internal culture, where everyone agrees on what it means to do the job well and defends each other for it.

A proper “deep state” — an institution whose control over the government not only can’t be touched by elected officials but actually exceeds their power — takes that one step further. It sees itself as the protector of not only its own values but the values of the entire nation.

Arguably, America really did have a “deep state” once: the FBI under J. Edgar Hoover. Hoover’s FBI really did operate without political accountability and saw itself as superior to the presidents who ruled it. The values, in this case, were Hoover’s own law-and-order self-righteousness. Men, as a rule, were weak and needed aggressive reminders to stay on the straight and narrow; politicians were simply men. But G-men were G-men.

The FBI doesn’t have the overweening power it had under Hoover. But there’s still some of that self-righteousness in its institutional DNA. That can be a problem in some cases, in the way that full-hearted dedication to any morality can create excess.

But you can’t create an institution that is transparent, humble, and open to suggestion in good times, and resilient, independent, and resistant in bad ones. It’s the organizations that are least willing to take direction from the outside about what they ought to value that are most likely to retain their identity in the face of attempted subversion. It’s the organizations that take threats to their own independence personally that are the ones most likely to act in self-defense when someone tries to overpower them.

This can be bad for democracy. But it’s a good weapon against despotism.

The complicating factor here is that civil servants are also public servants. If politicians are elected to carry out their agenda, it only makes sense that that agenda should change the way government employees do their jobs. There is, even in the best of times, a tension between apolitical professionalism and serving the public will.

Immigration agents under the Obama administration, for example, saw their job as enforcing immigration law — that was their definition of professionalism. But Obama and his political appointees, especially in their second term, believed they had been (re)elected in part to protect unauthorized immigrant families who hadn’t committed crimes from deportation. They had run on that platform and had been rewarded for it. The result was a grinding, years-long battle between labor and management that looked like a fight over “morale” but was really a fight over what job field agents were supposed to do.

It’s a tough balance to strike. But that isn’t the situation we’re in right now.

Donald Trump isn’t going hard at the FBI because they’re getting in the way of his agenda. He’s attacking them because they’re scrutinizing his behavior and he is trying to protect himself.

The Russia scandal might get in the way of Trump’s agenda because it reduces the amount of public attention paid to it, or Trump’s sway with lawmakers to enact it. But that’s not an argument that Trump should be exempt from scrutiny. If the notion of republican government is to mean anything, it must mean that the act of electing a man does not permit him legal impunity. His policy agenda does not come before the law.

If Trump were the sort of person willing to learn things, he might have interpreted the FBI’s reaction to Comey’s firing, and the appointment of Mueller, as a brushback pitch — a reminder of where the boundaries are. And it would have been welcome, even to those with no love for the FBI. But he didn’t take those signals. He ratcheted up his attacks on FBI leadership, and Republican officials followed his lead.

New York Times reporter and Trump whisperer Maggie Haberman explained one motivation for the president’s attacks: Whether or not he is seriously considering firing Rosenstein or dispatching Mueller, he thinks the constant threats to their jobs will successfully scare them into being careful — that he, in other words, is the one throwing the brushback pitches.

But what Donald Trump doesn’t understand is that not everyone in government is solely motivated by the desire to keep their jobs. Some of them have had it drilled into their minds, for decades, that their job is to serve the republic. And maybe sometimes they might even be right.

CORRECTION: This article originally identified Sam the Eagle as Sam Eagle. The author gravely apologizes for this grievous mistake.