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.”