A subtle change with major implications is coming to the H-1B visa program that could give large tech companies an edge in bringing highly skilled workers to their sprawling Silicon Valley campuses, while hurting outsourcing firms that hire entry-level workers to fill software jobs.

The Department of Homeland Security announced a rule change Wednesday that will transform the lottery that decides who gets the 85,000 H-1B visas granted to for-profit companies every year.

Previously, an initial lottery granted 20,000 visas only to those holding advanced degrees granted by U.S. institutions — master’s degrees or doctorates — and then a general lottery granted 65,000 visas to all qualified applicants.

The Department of Homeland Security switched the order of these lotteries, it said in a notice of the final rule change, which will bolster the odds for highly educated foreign nationals. The change reduces the likelihood that people with just a bachelor’s degree will win in the general lottery, said Lisa Spiegel, an attorney at Duane Morris in San Francisco and head of the firm’s immigration group.

“I think we’re going to be seeing a lot of people going back to school,” Spiegel said.

The rule change is effective this year.

Francis Cissna, director of United States Citizenship and Immigration Services, the agency that oversees the program, described the changes as “simple and smart” in a statement, adding that they advanced “President Trump’s goal of improving our immigration system.”

Jason Finkelman, an immigration attorney based in Austin, Texas, said now employers will think differently about what candidates they put up for the H-1B visa.

“Everyone wants to hire the most qualified candidate they can. But if I’m an employer and I have two candidates who are equally qualified for a position, and both require me to sponsor them for a visa, I’m probably going to want to file for the one with the master’s degree because now, mathematically, I have a better chance of getting them picked,” he said.

Smaller employers, in particular, may become more selective. Large tech companies in the Bay Area have the means to support more foreign nationals entering the lottery — and “play the law of averages,” Finkelman added.

The department said the rule change will result in an estimated increase of up to 16 percent in the number of H-1B visa holders with advanced degrees, or about 5,300 workers.

The program shift could hurt technology staffing companies, also known as outsourcers, who have a reputation for flooding the lottery with applications. Three Indian firms — Tata Consultancy Services, Infosys and Wipro — often account for a majority of the H-1B applications, an analysis of government data shows.

“The administration’s attempt here to give preference to people who have exceptional qualifications is definitely a step in the right direction,” said Ira Mehlman, a spokesman for the Federation for American Immigration Reform. His group, which seeks to reduce overall immigration levels, still wants to see the H-1B visa program reformed by Congress, Mehlman said.

The Washington Alliance of Technology Workers, a union that represents tech workers, also known as WashTech, said while it finds most of Trump’s immigration policy “abhorrent,” the rule change to the program is “long overdue.”

“For whatever Trump’s true motives are, it is good that the H-1B visa system is becoming more focused on ensuring that those who are awarded H-1B visas truly are highly skilled,” said spokesman Rennie Sawade, who works at Microsoft.

“There has been too much abuse of the system, particularly within outsourcing firms,” Sawade said. WashTech has sued the Department of Homeland Security to block a visa program known as Optional Practical Training, or OPT, that helps foreign students in the country extend their stays in order to pursue work in technical fields.

President Trump hinted at the final rule change in a tweet earlier this month.

“H-1B holders in the United States can rest assured that changes are soon coming which will bring both simplicity and certainty to your stay, including a potential path to citizenship,” he wrote.

In addition to swapping the totals in the lottery categories, the department said it will postpone plans to change the way companies enter their H-1B applicants into the lottery. Currently, employers have to prepare a full petition for each applicant before they’re picked. The planned rule change would let employers register them online before the lottery and work on their cases only if applicants are selected.

The department said it will delay rolling out the electronic registration system until after it completes testing.

Melia Russell is a San Francisco Chronicle staff writer. Email: melia.russell@sfchronicle.com Twitter: @meliarobin