The military had earlier declined to name the suspect. A senior U.S. official said Friday it was Bales, speaking on condition of anonymity because of the sensitivity of the investigation into an incident that has roiled relations with Afghanistan.
John Henry Browne, a defense attorney from Seattle, confirmed his client's identity.
Bales has not yet been charged. He was being flown Friday from Kuwait to a military detention center at Fort Leavenworth, Kan., the military's only maximum-security prison.
Reporters swarmed Bales' neighborhood in Washington state on Friday night in the rural community, a wooded area filled with pine trees about 20 miles northeast from the base.
Kassie Holland, who lives next door, said she would often see Bales playing with his two kids and the family together at the modern split-level home.
"My reaction is that I'm shocked," she said. "I can't believe it was him. There were no signs. It's really sad. I don't want to believe that he did it."
"He always had a good attitude about being in the service. He was never really angry about it. When I heard him talk, he said, it seemed like, yeah, that's my job. That's what I do. He never expressed a lot of emotion toward it."
Military officials say the soldier received sniper training and is assigned to the 2nd Battalion, 3rd Infantry Regiment of the 3rd Stryker Brigade Combat Team, of the 2nd Infantry Division, which is based at Lewis-McChord and has been dispatched to Iraq three times since 2003.
Beau Britt, who lives across the street, said: "For something like that to be right across the street from us is just amazing."
"I kind of sympathize for him, being gone, being sent over there four times. I can understand he's probably quite wracked mentally, so I just hope that things are justified in court. I hope it goes OK."
Browne said his client was injured twice while deployed to Iraq. He suffered a concussion in a vehicle accident caused by an improvised explosive device, and sustained a battle-related injury requiring surgery that removed part of one foot. Browne said his client was "highly decorated."
Browne said when the 11-year veteran heard he was being sent to Afghanistan late last year, he did not want to go.
"He wasn't thrilled about going on another deployment," Browne said. "He was told he wasn't going back, and then he was told he was going."
Bales completed 20 hours of anger-management counseling following a 2002 arrest at a Tacoma hotel for investigation of assault. Browne said the case involved a woman who was not his wife. It was not immediately clear how long Browne has been married to his wife.
Tacoma Municipal court administrator Yvonne Pettus provided a copy of the court docket, but said clerks could not immediately locate the case file, which is either in archives or destroyed. The docket shows that Bales pleaded not guilty, underwent the 20 hours of anger management treatment, and the case was dismissed.
The staff sergeant arrived in Afghanistan in December. On Feb. 1 he was assigned to a base in the Panjwai District, near Kandahar, to work with a village stability force that pairs special operations troops with villagers to help provide neighborhood security.
On Saturday, the day before the shooting spree, Browne said the soldier saw his friend's leg blown off. Browne said his client's family provided him with that information, which has not been independently verified.
Wearing a NATO forces uniform, officials say he moved through the nearby villages of Alkozai and Balandi, barging into homes and opening fire on those inside, then burning some of the bodies. Nine of those killed were children. Eleven of the dead were from a single family.
A surveillance video captured by a blimp that surveys the area around the base shows that the soldier later approached the south gate of the base with an Afghan shawl covering the weapon in his hands, according to an Afghan official who was shown the footage by his U.S. counterparts.
In the video, the man walks up to the base, lays down the weapon and raises his arms in surrender.
The sergeant's family says they saw no signs of aggression or anger. "They were totally shocked," by accounts of the massacre, Browne said. "He's never said anything antagonistic about Muslims. He's in general very mild-mannered."
The lawyer denied reports that the soldier had marital problems, saying he and his wife have a solid relationship.
The identification of the shooter quickly elicited a variety of reactions throughout Twitter. Some used social media to condemn Bales and called him a terrorist. Others called him a war hero who should not have been deployed to Afghanistan after serving three tours in Iraq. Others offered prayers for him and his family.