The 21-year-old spent the first half of last season on-loan at Coventry before switching to Championship rivals Rotherham for the remaining months of the campaign.
The season before he impressed at Shrewsbury Town before his first short stint with Coventry. The wing-back has come through the Wolves academy as a promising talent and has so far made one senior appearance, in the FA Cup against Shrewsbury in January 2019.
He has been training with new boss Bruno Lage for the last week since the squad returned for pre-season, but now Giles will return to the Championship and team up with former Wolves manager McCarthy at Cardiff.
The deal will last the full 2021/22 season.
Technical director Scott Sellars said: “It’s a fantastic opportunity for Ryan to gain more experience after a good season at Coventry and Rotherham last year, because the Championship is a brilliant league to help a player develop for the Premier League."
“Bruno has seen him work since we returned for pre-season last week and he believes this move will be the next and best step forward for Ryan.
“Cardiff are a fantastic club with a great stadium and training facilities, and with Mick and Terry, two excellent coaches and a vastly experienced management team, we hope he will get the opportunity to do what he does really well, which is take players on and cross into the box.
“His stats last year in terms of his assists and his crosses into the box, while playing for teams who were struggling, were as good as anyone in the league, so we’re hoping this move will really allow Ryan to kick on and demonstrate what he’s best at.”