There isn't a set number. Really depends on your faction. Italian factions, Egypt, and the Turks can get by with very few castles (2 or 3 in a large empire of 30+ provinces).
For other factions, I'd say anywhere from 1/7 to 1/4 of your total territories. Specialize them for troop production (infantry, ranged, cavalry etc.)
As for the defense bit, I think that huge cities are actually better right now due to the fact that a city's cannon towers aren't bugged. Citadel's cannon towers only shoot ballista bolts.
Bookmarks