It sounds like you're building a large army and using it to gain map control, but then are falling prey to things like drops and backdooring.
If you have map control your first thought should never be: Crush my opponent, as you're essentially sacrificing an advantage (map control) for an unsure victory (because he doesn't control the map doesn't mean he can't take you). Instead your thought should be: take the map. I think you'll find this change in philosophy will lead to situations where you have a much more powerful economy than him and you're able to kill him with attrition.
Now if you're falling prey to things like BD here is a quick check list for you:
- Are you scouting? an Observer should be the first thing you build out of Robo. If you don't go Robo, a Hallucination works just as well. Sometimes scouting means sacrificing some Zealots in a pointless charge to just get inside his base.
- If you're scouting, are you seeing it coming? Overlords on the edge of your base, Starport with Reactor + 3 Rax, all of these are indicative of certain strategies you should watch out for.
- If you see it coming, how are you responding? If you have map control that means you should be able to respond quickly. Shutting down these back door attempts is often a bigger victory than a straight up conflict
- Finally, Do you have map control? If you don't have map control that means he does, and if he's beating you with map control then your problem is not "how do I deal with a base trade?" but rather, how do I regain the advantage.
The most important thing to realize is that 3 workers per mineral is the max you would want. It is not necessarily optimal however. The third worker is not as effective as the first 2. Once you have more than 2 workers, one of them will always be "hanging around" waiting for its turn to be useful. Therefore, if you have an expo with less than 2 workers per patch, you would do better to move some workers there. You will get more minerals per minute by having 2 workers per patch at your main and 1 per patch at your expo than you would with 3 workers per patch at your main.
With that in mind, here are some answers:
How to keep track of how many you have at a specific base?
Make sure all your mineral patches and gas geysers are visible on the screen. Now double click on one of your workers. This will select all your workers. At the bottom middle of your screen you'll see wireframes of all of them, 8 per row. if you have 3 rows full, that's 24 workers, which is a decently saturated base. "Full" saturation would be about 24 on minerals and 6 on gas, or 30. But if you have an expo, you're better off moving some of them... (Note that MULEs do not conflict with SCV's for mining time, so they should not factor into your counts.)
When you expand, should you build workers from that base or transfer?
This depends on the situation. If your expo is far away from your main, and there are potentially enemy forces in between, then transferring is probably a bad idea. If you have more than 2 workers per patch in your main, and your natural is nearby and well defended, then transferring makes sense. In my experience, Zerg players usually expand before they have much more than 2 workers per patch, while a 1 base terran or protoss will often build up 30 workers on one base before expanding.
**Rebuilding after some being killed **
I'm not sure what the question is here - you can just rebuild them like you normally build them.
Transferring when minerals run out
There is no automatic way to have workers move to an expansion when minerals or gas run out. However, you can listen for the voice that says "mineral patch depleted" and start transferring them. You can also look for the idle worker icon that pops up on the lower left hand side of your screen, that will alert you to a worker who is not doing anything.
Race Specific Tidbits
Protoss can chronoboost workers to help get an economy up and running, or recover from an attack.
Terrans can get by with less SCVs if they have a lot of orbital commands to summon MULEs with.
Terrans can load SCV's into command centers, then fly them to a new base.
Zerg players need to remember to build more drones to replace drones used to build buildings.
Best Answer
So, there is no correct answer to this question.
Traditional doctrine said about 3 bases (80-90 Probes). This is necessary to continue adding to the standard Protoss "death ball" out of 6 Gate + 2 Robo, while adding in HT. Supporting your death ball requires at least 2 bases in mid to late game, and to make the tech transition to HT on 2 base is usually a blunder which will cost you the game. So if you're going for the standard Colossus into HT, you have to have that third base saturated.
More recently, high end Protoss players (oGsMC), have been moving away from the classic Colossus into High Templar and have been moving towards even heavier economic builds (like Colossus Void Ray). Whether these are strategies which favor the more macro centric 1 Gate Expanding Protoss, or responses to the new Khaydarin Amulet nerf (which was announced weeks ago), we're now seeing Protoss players getting 110+ Probes on 4 Bases.
Ultimately, how many Probes you build is a function of what your timing windows are. The question should never be: How many Probes do I build? Rather the question you should be asking is When do I stop building Probes?
Knowing when to cut Probe production is a skill, and that timing is what makes your BO effective.