A federal judge ruled Monday that a US National Security Agency surveillance program that collects phone record metadata on all US citizens is likely unconstitutional.

US District Judge Richard Leon found (PDF) that the government's "bulk collection and querying of phone record metadata" may violate the Fourth Amendment and "certainly does violate a reasonable expectation of privacy." But it's not a question of whether all phone metadata should be considered private all the time, Leon said -- this ruling hangs on the particulars of the NSA's sweeping collection of that metadata:

The question I will ultimately have to answer when I reach the merits of this case someday is whether people have a reasonable expectation of privacy that is violated when the Government, without any basis whatsoever to suspect them of any wrongdoing, collects and stores for five years their telephony metadata for purposes of subjecting it to high-tech querying and analysis without any case-by-case judicial approval. For many of the reasons set forth above, it is significantly likely that on that day, I will answer that question in the plaintiffs' favor.

Leon, who sits on the District Court for the District of Columbia, issued a preliminary injunction in the case, which is the combination of related lawsuits filed against the government by legal activist Larry Klayman, that bars the NSA from collecting metadata associated with the Verizon account of Klayman and one of his clients. Leon also issued a second injunction that says the government must destroy any phone metadata on Klayman in its possession that was collected through the program.

However, the judged stayed the order to allow for an appeal.

"We've seen the opinion and are studying it," a Justice Department spokesman said in a statement. "We believe the program is constitutional as previous judges have found."

This case, and severalothers, stem from revelations about the NSA's collection of US citizens' phone and Internet data that were detailed in documents leaked by former NSA contractor Edward Snowden.

In June, documents from Snowden revealed that the NSA had been vacuuming up records of millions of phone calls made inside the US under a top secret Foreign Intelligence Surveillance Court order. The court order required Verizon to hand over information on all domestic and overseas calls to the NSA on an "ongoing daily basis." Verizon denied providing data to the NSA, but its careful wording left open the possibility that metadata was turned over.

In coming to this ruling, Leon took his analysis back to the 1979 Supreme Court case Smith v. Maryland, which found that no one has an expectation of privacy when it comes to phone records. But Leon pointed out that not only is the "Government's ability to collect, store, and analyze phone data greater now than it was in 1979, but the nature and quantity of the information contained in people's telephony metadata is much greater, as well."

The ruling notes that in 1979 just shy of 72 million homes had telephones, but that today there are a "whopping" 326 million mobile subscriber connections in the US, of which approximately 304 million are for phones and 22 million for computers, tablets, and modems. In addition to there being more phones, the metadata has also changed. In 1979 during the Smith case, metadata mainly included "phone numbers dialed, date, time and the like," but today, phone metadata includes text messages, GPS mapping, pictures, and more.

"The Government, in its understandable zeal to protect our homeland, has crafted a counterterrorism program with respect to telephone metadata," Leon wrote, "that strikes the balance based in large part on a thirty-four-year-old Supreme Court precedent, the relevance of which has been eclipsed by technological advances and a cell phone-centric lifestyle heretofore inconceivable."

In the 68-page opinion, Leon also calls the government's arguments in the case conflicting. He writes that the government wants him to infer that the NSA may not have actually collected phone records from carriers but also believe that the NSA's repository of "terrorist-related communications across multiple telecommunications networks" is vital to preventing future terrorist attacks.

Put simply, the Government wants it both ways. Virtually all of the Government's briefs and arguments to this Court explain how the Government has acted in good faith to create a comprehensive metadata database that serves as a potentially valuable tool in combating terrorism -- in which case the NSA must have collected metadata from Verizon Wireless ... as well as AT&T and Sprint. .... Yet in one footnote, the Government asks me to find that plaintiffs lack standing based on the theoretical possibility that the NSA has collected a universe of metadata so incomplete that the program could not possibly serve its putative function. Candor of this type defies common sense and does not exactly inspire confidence!

The judge says he expects the appellate process will consume "at least the next six months."