TALLAHASSEE, Fla. — After living nearly a half century in the United States — marrying and raising a family here, paying taxes and working for decades for the federal government — Mario Hernandez made a discovery recently that rattled him to his core: He is not an American citizen. In fact, he is not even a United States resident.

Nobody had ever told him. Not his mother or his grandparents. Not the United States Army, where he served for three years in the 1970s. Not the election supervisors in four states who tallied his votes in every major election since Jimmy Carter won the White House. Not the two state agencies where he was employed, one in Washington State and the other in Florida. And not the two federal agencies, including the Justice Department, where he spent most of his career as a prison supervisor handling notorious inmates and undergoing thorough background checks every five years. Citizenship is a requirement for the job.

The revelation came only after Mr. Hernandez and his wife, Bonita, started planning a trip to celebrate his recent retirement from the Bureau of Prisons after 22 years. The two had settled on a Caribbean cruise, which would have been Mr. Hernandez’s first time out of the country since arriving in 1965 as a Cuban refugee. On a cruise line website, he found out that a United States passport was a requirement. He did not have one and wondered whether he even had naturalization papers.

“I thought I was a citizen — I’ve always been proud of being a citizen,” said Mr. Hernandez, 58, the father of two grown children, one an engineer who is an Afghan war veteran. “This has really messed with my head.”

Mr. Hernandez was 9 years old when he left Cuba.

BRYAN ANSELM FOR THE NEW YORK TIMES

At a time when immigration overhaul remains on the table in Congress, Mr. Hernandez’s plight is the latest example, and one of the more extreme, of how large federal bureaucracies can stumble when it comes to identifying who is here legally, illegally or somewhere in between. With so many immigrants in the country under so many varying rules, keeping track can sometimes pose monumental challenges.

For Mr. Hernandez, the consequences are worrisome. Deportation is not something he would face as a Cuban refugee and military veteran. But he can no longer vote, and he cannot leave the country. And he could face prison and fines for having falsely claimed citizenship and for voting.

At the moment, he exists in immigration limbo — not fully legal or illegal. After he attended an immigration interview in March, his request for citizenship was denied. It should not have been, said his lawyer, Elizabeth Ricci, from Tallahassee. Mr. Hernandez was entitled to citizenship, she said, because he had served in the Army during a “designated period of hostility” at the end of the Vietnam War era.

A second letter from the immigration service followed. It said the case would be reopened but asked for more information, including why he had claimed to be a citizen, had registered to vote and had voted.

Sharon Scheidhauer, a spokeswoman for United States Citizenship and Immigration Services, said the agency could not comment on individual cases.

“I think they are gravely embarrassed,” Ms. Ricci said, “and are trying to shift the burden on him now to make him look like a criminal.”

Not only did Mr. Hernandez work for the Bureau of Prisons (and before that the Bureau of Indian Affairs), but he had been a supervisor, overseeing day-to-day operations, detainees and inmates, including terrorists.

By the time he retired, he had a desk full of commendations. In 1995, he personally kept watch over the two Oklahoma City bombers, Terry Nichols and Timothy McVeigh, keeping an eye on each in their isolation cells for 12 hours a day on separate weeks over the course of a month. When Willie Falcon, the notorious cocaine trafficker from Miami, had to change prisons, Mr. Hernandez was in charge of the transfer — one of several he oversaw involving high-profile prisoners.

By all accounts, Mr. Hernandez is a make-the-best-of-it kind of man who was taught to be self-reliant at an early age. But he is unnerved by the turn of events.

“It’s like I’m living a bad dream,” he said as he sat in his comfortable home decorated with Holstein cow knickknacks and dozens of framed photographs of his children and grandchildren. “This cannot be real; I’ve been living here 49 years. This is the only country I’ve ever known.”

Elizabeth C. Pines, a longtime immigration lawyer in Miami, said she had run across a handful of similar cases but none as extreme as this one.

“It goes to show you how broken the system is for a federal and a state agency to have not even checked his background — his criminal background, yes, but not his immigration background,” she said.

The only immigration document Mr. Hernandez has is a parole document, which he received as a 9-year-old when he arrived at Miami’s Freedom Tower with his family. The paper allowed him to remain in the United States indefinitely.

Cuban citizens are granted special immigration privileges when they flee Cuba and arrive in the United States. First, they are granted parole. After a year, unless they are criminals, they can become United States residents. Five years later, they can become American citizens. The only hitch is that the paperwork must be filed, which Mr. Hernandez’s parents never did on his behalf.

Growing up in Fullerton, Calif., Mr. Hernandez always assumed that all of this had been done for him as a child. Nobody ever mentioned his immigration status at home — less a topic of conversation in those days, particularly for Cuban refugees, Mr. Hernandez said. He never thought to ask, he added.

Jobs came easily. As a parolee, Mr. Hernandez says, he was given an unrestricted Social Security number, which he has had since childhood. Later, he got a driver’s license.

When he enlisted in the Army in 1975 as a teenager, he said he remembered, he handed officials his parole document and taking some kind of oath. That he may not have been an American citizen crossed his mind then, he said, but the oath he took — a citizenship oath, in his mind — allayed any doubts.

Decades later, worried about his lack of citizenship papers, Mr. Hernandez met with Ms. Ricci. Ms. Ricci said she was stunned at how long he had lived in limbo. She said she was baffled why the Bureau of Prisons had never flagged his lack of citizenship, particularly since Mr. Hernandez did the opposite of remain in the shadows.

“It’s a classic example of government inefficiency,” said Ms. Ricci, who has taken his case pro bono.

Passionate about America and its privileges, Mr. Hernandez said he took his citizenship responsibilities to heart. When Leon County election officials here recently stripped his name from the voter rolls, “I broke down crying,” he said. He could not even tell a friend about it as they pumped gas.

“It was just overwhelming to him,” said Brenda Salvas, the friend and a former colleague. “He said he would call me later on the phone and tell me. That’s the kind of person he is. He cares.