The United States is certain that there are 50 American hostages being held by Iranian militants in Tehran and that all of them are confined within the U.S. Embassy compound there, a senior U.S. official said yesterday.

Although State Department officials have said for more than three months that they believed there were 50 hostages, some of the militant captors had said the number was 49.

In addition, 49 of the captives had sent letters out at Christmas or had been seen by visitors allowed into the compound during recent weeks.

However, the official, who declined to be identified, said that, based on an accumulation of recent evidence and reports, the State Department has concluded that the correct number is 50 and that all are alive and inside the embassy.

The official refused to identify the sources of the department's information, except to say that they were "sufficiently distant from the militants" to be considered impartial and reliable. He also would not name the 50th hostage about whose presence there had been doubts.

Much of the speculation had centered on Michael J. Metrinko, 33, an embassy consular officer from Olyphant, Pa. He did not write a letter when the hostages were allowed to send mail at Christmas, and he was among seven presumed hostages who were not seen by three American clergymen who visited the captives over the Christmas holiday.

Although the press and other organizations have pieced together a list of those who are believed to be hostages, the State Department has refused to give out its compilation of the captives' identities.

Recent visitors to the compound have included a member of Iran's Revoluntionary Council and a physican whose examination of several hostages was filmed by a Greek television crew and shown in the United States on NBC television Wednesday night.

Referring to the listless appearance of some of the hostages seen in the TV film, State Department spokesman Hodding Carter said yesterday it gave some idea of the range of their health conditions and bolstered the U.S. contention that their physical and mental states could be impaired by continued, lengthy confinement.

One hostage seen in the film, Barry Rosen, the embassy press attache, seemed almost incoherent as he tried to tell the doctor about recurring chest pains. After seeing the film, John Reinhardt, director of the International Communications Agency, issued a statement yesterday expressing "shock and dismay" about Rosen's condition.

"It is obvious that the brutality of the past 131 days has exacted a high price, has affected his health, perhaps seriously," Reinhardt said. "I cannot believe that if they knew the facts the Iranian people, Iranian mothers and sisters and wives, would approve the hardships he and the other captives have endured."

The senior official said the evidence available indicates that different hostages were treated in different ways. Lower-ranking officials and Marine guards seemed to have more freedom and were more visible to visitors, he said.

By contrast, the official added, the embassy's senior officials were more secluded, and it is harder to get a picture of how they are being handled. For that reason, he said, it is not clear whether some hostages are still kept bound and blindfolded and in isolation, as they were in the days immediately after the embassy was seized Nov. 4.

Spokesman Carter said U.S. support for continuing the efforts of the U.N. commission that recently visited Tehran is based in part on hopes that the commission will be able to see the hostages.

The five-member commission suspended its mission and left Iran early this week because of its inability to gain access to the hostages. But Secretary of State Cyrus R. Vance, who conferred with the commission members Wednesday in New York, said he hopes their mission can be revived.