A federal appeals court on Tuesday for the first time heard oral arguments over whether the government’s mass collection of data about Americans’ phone calls is constitutional and legal.

In a case that may be headed to the Supreme Court, a lawyer for the government faced pointed questioning over whether the National Security Agency’s gathering of vast amounts of Americans’ call records from U.S. phone companies violates the Fourth Amendment and a law known as Section 215 of the Patriot Act.

At issue is a major government counterterrorism program begun shortly after the Sept. 11, 2001, attacks, put under secret court oversight in 2006 and revealed through a leak by former NSA contractor Edward Snowden in July 2013.

The American Civil Liberties Union filed a statutory and constitutional challenge shortly after the program was revealed. A district court judge in December ruled against the ACLU, and the group appealed.

Under the program, the NSA each day collects millions of call records — numbers dialed, call length and time, but not call content — from phone companies. It analyzes them to find connections between people inside the United States and numbers reasonably suspected to belong to foreign terrorists. The government has justified the collection under a controversial, once-secret interpretation of Section 215.

The statute requires that records sought be “relevant” to an authorized investigation, but it was not publicly revealed until last year that the government had determined — and a surveillance court had agreed — that such relevance could extend to all customer call records belonging to a phone company.

In nearly two hours of argument, a three-judge panel of the U.S. Court of Appeals for the 2nd Circuit questioned whether Congress knowingly consented to the formerly classified program when it twice reauthorized the statute and whether the government’s interpretation of the law opens the way to bulk collection of other types of personal data.

“It’s hard to imagine that [Section 215’s] rather innocuous language” means the government could collect so many records in bulk that have never been acquired before with a grand jury subpoena, Judge Gerard E. Lynch told Assistant Attorney General Stuart Delery.

“You’re really saying, ‘They’re not relevant to an investigation right now; we just want to have them in case they become relevant’ ” in the future, he said.

The panel’s three judges, all appointed by Democrats, seemed concerned that the same argument could be extended to other data, such as credit card or bank records.

“You can collect everything there is to know about everybody and have it all in one big government cloud,” Lynch said. “. . . I just don’t understand the argument as to what’s so special about telephone records that makes them so valuable, so uniquely interactive, that the same arguments you’re making don’t apply to every record in the hands of a third-party business entity of every American’s everything.”

Delery argued that Congress was briefed on and subsequently “ratified” the program when it reauthorized the statute in 2010 and in 2011, and that a series of judges on the Foreign Intelligence Surveillance Court have found the program to be lawful and constitutional in light of past Supreme Court cases. That panel meets in secret and hears only from the government.

The government needs to collect phone data in bulk, Delery said, “to detect and disrupt future plots before an attack can be made.”

He said that phone records “by their nature are quite standardized” and allow for “rapid” identification of connections between “known and unknown terrorists.”

The judges expressed skepticism about the government’s ratification theory.

“I wonder about how valid the ratification argument is when you’re dealing with secret law,” Judge Robert D. Sack said, referring to the fact that the program was not publicly known until last year.

Swayed by the public debate, President Obama in January called for an end to the NSA’s bulk collection of phone data and asked Congress to craft legislation to enable the government to obtain the intelligence it needs without using such invasive means.

The House passed a bill, but the Senate has yet to act.

“The legal theories that [the government] advances are a road map to a world in which the government routinely collects vast quantities of information on Americans who have done absolutely nothing wrong,” Alex Abdo, an ACLU staff attorney, told the court.

“I don’t think that’s the world that Congress envisioned when it enacted Section 215, and it’s certainly not the world that the framers envisioned when they crafted the Fourth Amendment.”

At least two other appeals courts are likely to hear arguments over the program’s constitutionality this year.