How many ships? Enough. Try to get a feel for what you lack, if anything.
I build some battle fleets to kill space ports, and other large fleets. I can hardly ever see the need for 10 of these.
I build some raider fleets able to bust pirate bases, mining stations, small enemy fleets. Maybe one per sector in areas where I have presence? How many you need to protect yourself depend on the hyper drives, the faster into hyper space, and the the faster speed while there, the more they can be spread out. If your area is large, and parts of it "safe" (nowhere for pirates to pop up), you don't need fleets sitting there. Also, if you have lots of automated ships, you only need some fleets around to kill pirate bases, and a few to use during wars. If you have no automated ships, you need more fleets...
At some point in the game the pirates becomes an annoyance that attacks all the time, and your empire has some size. This is when I start hire automated frigates. 80 at a time. The theory should be that there is a frigate somewhere near any attack that can be diverted to kill the pirate.
If I discover that I lack a raider fleet, I build one more. If I discover they have become too weak, I add ships, or redesign them if doing manual ship design (or both). If I fight a war, I rarely attack with more than 4 main battle fleets. If I have 6 fleets, I have two in reserve in case of backstabs. I build more and improve their strength as needed.
My 45 colony empire in the current game has:
6 battle fleets of 11 cruisers and 4 carriers. Almost a separate fleet backing up the ones chasing Silvermist (the ships there tend to die, and it is nice to have replacements close-ish). Capitals will be added once 650 ship size is available, and over time they will move towards capitals+carriers.
16 2 ship destroyer fleets that have become too weak. Enough to cover my empire with sector posture circles, and have a few extra in areas harried by pirates. I have to decide what to do with these.
I have 15 somewhat larger than normal troop transports, but they have not been in action for ages, since I have been busy fighting Silvermist. They have 9 troops each.
I got a 4 ships cruiser-carrier fleet to kill pirate bases in a cloud where they pop up all the time.
79 automated frigates (pirates became annoying). I thought I ordered 80, so maybe one died.
3 resupply ships. It should be 4, but a silvermist ate one, and I don't need any more right now.
In total, just over 200 military ships