Overall, however many are needed to tell a long story. It is a story that can't be concluded in just one book and although finishing it in two might be possible, it depends on how much I'm able to cover by the time I reach that point with other ideas I have in mind. As for the characters, I suppose I plan on trying to use all of those that I introduce to what could be their fullest so as to not waste a character. The story is told from a third-person point of view and while it mainly focuses around the MC herself it would occasionally shift to another character depending on their importance to the plot at hand in terms of telling this story. The new characters, who I am still on the fence of introducing, are more meant to introduce greater variety in the world as well as to create a more unpredictable sense of danger while they fill antagonistic roles.
They would expand upon a certain idea introduced in the first book through their own unique ways and would give readers more of an insight into said idea and the possibilities of it.
With 40 characters, the bolded seems a good way to get out of hand depending on what exactly you mean by it.
I think there's two ways forwards in situations like this.
One is to just follow your gut and wing it and find out later if you did okay.
The other is to look at good books that remind you of what you want to achieve, and do what they do with modifications as suitable.
A good example of a story that couldn't be told in one book is
Lord of the Rings. That has the following number of discernible meaningful characters:
The Fellowship - 9
Hobbits of Note (Bilbo, Fatty Bolger, Farmer Cottan, Lobelia, Farmer Maggot, Gaffer Gamgee) - 6
Barliman Butterbur, Bill Ferny, Tom Bombadil - 3
Elrond, Arwen, Galadriel - 3
The Rohirrim (Eomer, Eowyn, Theoden, Wormtongue) - 4
Treebeard, Saruman - 2
Gondor (Denethor, Faramir, Imrahil, Beregond, Bergil, Ioreth) - 6
Herald of Sauron, Lord of the Nazgul - 2
Gollum - 1
That gives you 36 characters of some note, give or take how you might feel about my count of who's important or not (there's a great many omitted).
But not all of these characters are given a great amount of rope. Some are there for a couple of chapters only with little known about their history.
So. If you have a little over 40 characters, some major and some minor, many seen only for a few chapters, and a story of roughly LotR length, that's probably okay. If you want to have 40 characters where most of them matter for most of the story, then you might be running into issues.