The number of characters isn't, by itself, a good or bad thing. What you need is the ability to write characters that are memorable and interesting.
There is a type of novel where the author seems to be flexing with their ability to generate names. I am thinking of a particular classic novel involving combat between armies on horseback. It's set in China round about the year 100 AD. According to the novel it was standard for the officers of two armies to come out and do single combat before the main battle. That way if one side was clearly going to win, the other could have a chance to back off without a huge slaughter.
And the author lists the names of all the officers in a battle. Dozens of them. Each with their family name, given name, childhood name, and the name their friends use. And I'm there saying "too many names." I'm skipping page after page of character names.
Later in the novel there is a tendency for single heroes to last through many battles. That way I feel some confidence in getting emotionally invested in the character. Additionally, the characters that last have various things that make them memorable. For example, this guy has a special horse and particular way of riding. And that guy has a white robe and a fan of eagle feathers. And so on.
It's OK, by the way, to have "spear carriers" in some circumstances. When you have armies in your story, then the "rank and file" are permitted to be uniform. You just don't try to make every single one a character. They can even have lines. They can even do "business" in the sense of a Shakespeare play. But they usually do it in an "anonymous" manner. Similarly, you can have "bystanders" or such. Again, don't try to make every one of them a character.
So your challenge is to make your characters interesting and memorable. These are the payoffs to you audience to convince them to actually read carefully and remember your characters. And your work in the long run. If you have two dozen characters that nobody can remember or tell the difference, maybe it is too many. But if you have whatever number of characters that are memorable individuals, even briefly, it's probably not too many.