The 28-year-old who moved to the club from Crystal Palace in 2016, broke into the first team halfway through the season, and has now established himself as the top choice.
He kept seven clean sheets in his 18 Premier League appearances, and helped Southampton avoid the drop.
Hughes was keen to reward McCarthy, telling Sky Sports: "Alex played a key role for us last season, and we are delighted he has agreed a new deal here."
"His performances last season speak for themselves, and it is clear how highly regarded he is by his team-mates and also the supporters."
"It was clearly a priority this summer to ensure the commitment between him and the club was strengthened, and we believe Alex is very much in the right place to continue to grow and improve his game."
The goalkeepers current deal was due to run out next summer, and he is excited to extent his time with the club.
"I'm massively pleased," he said. "I had one year left on my current deal and obviously I'm over the moon to sign a new four-year deal."
"I think the club is going in the right direction. With the way we finished the season, we can take that into this one and hopefully finish a lot higher up the table."