The 25-year-old, who is the brother of Birmingham City midfielder Craig Gardner, scored once in 27 Championship appearances for Villa last term.
Gardner has not been involved in the league at the start of the new season, however, and has been allowed to leave Villa Park in search of first-team football.
"We're really pleased with the signing of Gary, he's an important addition to give us greater flexibility within the squad and we look forward to working with him," Barnsley boss Paul Heckingbottom told the club's official website.
"He is going to help us this season and we're definitely looking forward to that as well. I would like to thank Aston Villa for allowing Gary to come here."
Gardner has previously spent time on loan with Coventry City, Sheffield Wednesday and Brighton & Hove Albion.