The Argentina international joined the Citizens from Valencia in 2015 and has gone on to make 118 appearances in all competitions.
Otamendi's initial contract was set to expire in 2020 but the club have taken the decision to extend his stay by a further two years.
"I've enjoyed my time at City since the first day I arrived and I'm really happy to have extended my stay here by a couple more years," Otamendi told his club's official website.
"My only aim is to help the team and give all I can for this Club. I am learning every day under Pep and enjoying my football and I feel I can still improve as a player.
"I'm a family man who enjoys being at home and I love living in Manchester, you sort of get hooked by it. It's a very beautiful city and I'm very happy here."