It's a big question. First, if the wind isn't uniform in strength, tack over to the good wind.
Assuming uniform wind strength, when to tack depends largely on shifts in wind direction. Generally, if it's shifting, stay on the tack that is being Lifted, and tack off a tack that's being Headed, since it's a lift on the other tack. In general, stay on the tack that takes you closer to your destination, and once that destination is more than 50-60 degrees off your windward bow, think about tacking, as the other tack will now be the "major" tack.
Don't "shoot the corner" (meaning don't go all the way out to the layline) from way, way out--if you get lifted, you'll overstand and will have wasted distance; if you get headed, then you'll have wasted distance in a different way.
Picture a windward course to a mark as a christmas tree shape. You start at the bottom with lots of width, then it narrows as you get closer. Try to stay in or near the middle of the "tree", that way you will have room to tack when you get headed, without overstanding.
You can reduce the number of tacks by not tacking til you get, say, a 10-degree header. Crew size, sail size, and fatigue will also govern how many times you want to tack.. In general, watch your compass, it's your friend, and will tell you if you're getting lifted, or headed, or neither.
Hope this of some help. But there's no "correct" number of tacks, it just all depends...