US senators on the powerful appropriations committee sharply challenged the director of the National Security Agency on Wednesday about the extent of the agency's domestic surveillance first disclosed by the Guardian.

During a tense, two-hour-plus afternoon hearing that was not intended to focus on the recent revelations about domestic surveillance, senators of both parties used General Keith Alexander's first public appearance on Capitol Hill since the Guardian's stories broke to press him for answers about how its widespread surveillance programs operate.

Alexander responded by repeating claims that the programs had thwarted terror attacks. He said that "dozens" of terrorist attacks had been thwarted in part because of the domestic surveillance dragnet. But he did not give specific details.

In one testy exchange, senator Jeff Merkley, a Democrat from Oregon, and a Verizon customer, waved his smartphone at Alexander. "What authorized investigation gave you the grounds for acquiring my cellphone data," Merkley asked.

Senator Barbara Mikulski, a Maryland Democrat, the committee chairman, said: "Many of us are concerned about what is the access to people and businesses' information. There are those, because of the Snowden revelation, who wonder about the government's access to that information."

Alexander said he struggled with how much detail to provide in public about the surveillance. "I would rather take a public beating, and let people think I'm hiding something, than jeopardize the security of this country," Alexander testified. He said he would aim to declassify specific cases in which the two surveillance programs described by the Guardian had contributed to government efforts at thwarting terrorist attacks.

But Alexander added some new details about how the NSA surveillance works – and he also raised unanswered questions about it.

The two programs in question are distinct, at least as matters of law. One, justified under Section 215 of the Patriot Act, collects the phone records of millions of Americans, but is said not to examine at their content. The other, justified under Section 702 of the 2008 Fisa Amendments Act and known as Prism, relates to the online communications of people believed not to be inside the United States.

But Alexander said it was difficult, in practice, to separate them, and credit one of the programs for contributing to an investigation without crediting the other. "The reality is, they work together," Alexander said.

Alexander defended the bulk collection by saying it was necessary to give the NSA the widest possible data pool so it can then query the phone-records database for specific terrorist interaction with Americans. Once the NSA has "reasonable, articulable suspicions" of a person's suspected involvement in terrorism, Alexander said, "we can go backwards in time and see who he was talking to," and pass that information to the FBI.

"If you don't have that, how do you know who [a terrorist] was talking to?" Alexander told senator Mike Johanns, Republican of Nebraska, who worried that the database could lead to a "telephone records search for all of Omaha."

Alexander added that there were strict rules preventing the NSA from querying its phone records database without that suspicion, but he left it unclear who performs the certification that such suspicion rises to the standards under which the database can be accessed.

A June 6 factsheet from James Clapper, the director of national intelligence, claimed that the secret Fisa court that oversees surveillance "only allows the data to be queried when there is a reasonable suspicion, based on specific facts, that the particular basis for the query is associated with a foreign terrorist organization".

But the factsheet is ambiguous about whether the court must approve each specific database search of Americans' phone records, or merely has created guidelines that the NSA unilaterally executes. Representatives of Clapper and the NSA did not respond to the Guardian's request for clarification.

Members of the panel did not appear satisfied with those safeguards. "That seems to me overly broad," said senator Richard Durbin, an Illinois Democrat. Merkley pointed out that the language of Section 215 of the Patriot Act did not govern database queries from collected phone records. "These are requirements to acquire the data" in the first place, Merkley told Alexander.

In an exchange with senator Dianne Feinstein, Democrat of California, Alexander affirmed that after "five years", the NSA purges the phone records data it collects from Americans. Representatives from the NSA, the Director of National Intelligence, and Feinstein's office did not respond by press time to the Guardian's question whether any outside body affirms the purge.