To execute a recount in the Virginia attorney general’s race, Alexandria elections officials think they will have to tally by hand all the ballots in that race — 40,817 of them.

Registrar Tom Parkins said the Hart InterCivic eScan scanner that is used to record paper ballots in Alexandria can’t be programmed to recount the attorney general’s race without also recounting the other races on the ballot. Virginia law mandates that only the contested race be recounted.

“Because of the technology we use, I don’t believe we can isolate the attorney general race,” Parkins said. “If that’s the case, we’ll have to recount manually.”

Parkins said later Wednesday that although it will involve some work, the recount won’t be a problem.

“I think we actually prefer a manual recount because it’s speedier,” he said. The precinct-based scanner Alexandria uses takes only one ballot at a time, and it pauses while it tabulates the numbers. Because there’s only one race to recount, having people do the job will be quicker, Parkins said.

Undervotes — in which a voter might have marked a ballot in a way that the scanner cannot identify but a human can — could also be a factor in the recount, election officials said.

Just 165 votes statewide separate state Sen. Mark R. Herring (D-Loudoun) from state Sen. Mark D. Obenshain (R-Harrisonburg), out of about 2.2 million cast, and Obenshain has asked for a recount. Alexandria, like most of Northern Virginia, voted strongly Democratic, with Herring receiving 30,279 votes (74 percent) to Obenshain’s 10,423 (25.5 percent). About 115 voters exercised the write-in option and named someone else.

A manual recount could take two days or more, Parkins and deputy registrar Anna Lieder said. Much will depend on the instructions from a special recount court, led by the chief judge of the Circuit Court in Richmond. Every ballot that can be recounted by hand will be, and those counted by optical-scan machines will be run through the machines again.

Most jurisdictions in Northern Virginia will be able to re-scan their paper ballots and hand-count only the provisional ballots and e-mailed ballots from military voters. Ballots cast from touch-screen voting machines have tapes that record the votes, and elections officials will reexamine those tapes, registrars from across the region said in interviews this week.

Both Falls Church and Charlottesville, which use systems similar to Alexandria’s, expressed no concern about the recount. Only 4,900 votes in the attorney general’s race were cast in Falls Church, which means a count done by hand would be more efficient, registrar David Bjerke said. In Charlottesville, where 12,317 votes were cast in the race, deputy registrar Dianne Gililand said she thinks that the city has a scanning system that allows races to be separated in a recount.

The duration of the recount in Alexandria will be determined by how many teams of election officials are authorized by the court, Parkins said. Depending on when the recount starts, he thinks it can be completed in a couple of days.

He expects that it will conclude before the end of December; he is scheduled to retire Jan. 1.