Defenses
There is no such thing as a perfect defense. No matter what you have protecting your base, eventually someone will bring enough guns to bare to take it down. It is not a matter of if, it is a matter of when. So you MUST have defenses. They are there for 3 reasons:
1) Deterrent. Given a choice between attacking a base with no defenses and one with some (if few), an agressor will almost always go for the undefended base first. It also prevents random scout and recycler raids.
2) Victory. Utterly destroying the attacking fleet. A sweet victory indeed.
3) Punishment. If you can't win, you can at least make them pay for the victory. This is the ultimate goal, regardless of what happens: Make it so the pillaging of your base and the recycling of the combat debris is less than the total amount the enemy lost. It's a phyrric victory for them, and a few more like that and they'll lose the war.
So, what goes into a great defense? Let us start with the single most important element of any defense:
The Command Centers
They don't shoot, they can't move, but they're more vital to your defenses than you can imagine. Each command center gives a 5% increase in your fleet's fire power over that base. Doesn't sound like a lot, does it? Ah, but it can make all the difference in killing the other guy faster than they can kill you. Since the attacker will often have more ships than the defender, every little bit extra helps.
You should have, at bare minimum, 5 command centers on every base. Bulldoze buildings, build powerplants, terraform, whatever, just get at least 5 of them. That 25% increase in fire power is completely worth it.
That said, while 5 is bare minimum, 10 should be standard, giving you 50% increase in power. At 15, your base shifts from being mearly a decently defended base into being a fortress of doom for whoever crosses you. At 20 or more, as long as you have ships NO ONE will screw with you without bringing millions of points of fleet.
So for reference:
5 = minimum
10 = Standard
15 = Outstanding
20 = Insane
Turrets
There are 6 catagories of turrets, each with their own advantages and disatvantages. I shall begin this list now:
1) Barracks - Barracks are, well, worthless in most cases. The only advantage they have over all other turrets is they require NO energy to use. That's it. There is no reason to ever build a barracks unless you are completely out of power and need extra turret fodder like NOW.
2) Low Level - Laser and Missile turrets occupy this level. They're cheap and take little power. They're also weak offensively and defenseivly. They're basically the equivilant of a heavy bomber and a frigate, but not quite that good. If you see a big fleet coming and want to take some more of them out, these are cheap and fast to build and will give you that much more power, but don't count on them to defend your planet for long.
3) Mid Level - Plasma and Ion turrets. At 14 Plasma and 10 Ion (minimum techs for ships), these two turrets are very nearly the same. Plasma uses less energy (1 less) and Ion has shields (very low shields). They're the equivilant of cruisers in that respect. Which one you go with, you should invest your tech value toward them, but Ion's are usually more cost effecient in the end.
4) Upper Level - Photon and Disruptor turrets. Heavy Cruisers and Battleships, respectively. The big guns of the turret world, you should always strive to have a few of these on every planet. Having 2 levels of Disruptors is like planting 10 battleships in orbit, and that can make a massive difference (5 BBs, used correctly, can take down a dread). Photons are weaker, but use half the energy. They also do a bit more than a quarter of the damage. Disruptors are always better.
5) Planetary Rings - A catagory all their own, they are the biggest guns in the game. They're not quite the strength of a titan, and building one is the same as building about 3 titans. It makes you almost impossible to kill without a concentrated effort. That said are massive power hogs, so be ready with the infrastructure to support them. Having 1 on every planet should be your ultimate goal.
6) Shields - Deflection and Planetary Shields add life back to your turrets IF they survive the first combat. Your turrets will likely not be back to full power, but they'll at least be able to fire in the next round of combat. It also means that the attacker will need to bring that much more firepower to bare to take your planet. The only downside is that the shields do jack squat offensively. So which is more important? Destroying as much as possible or surviving to destroy again? Hard to say actually, it probably depends on preference.
In my opinion, having two of every turret from plasma up, 1 shield (either type) and a pring is the best general defense you can have. This is more a balance of cost, energy consumption and firepower more than anything else. Would building all disruptor turrets be better? Possibly, and if you have that much money to spend, by all means go for it. In the end, it's up to you what you want to spend.
Fleets and Tactics
You may be thinking that the best defensive fleet is the one with all big guns. Heavy Cruisers, Battleships, Dreads and so on, but you're wrong. Terribly, awfully wrong.
Those ships are actually the most vulnerable ships in the game. Without fodder cover of some sort, they become easy targets, expecially against similar ships WITH fodder cover.
Most attacking fleets from experianced players are FILLED with fodder ships. Everything less than a Frigate is generally considered a fodder ship, and more than half of a respectable fleet will be fodder. Fodder ships are so important to combat that losing fodder ships can render a fleet useless for extended periods of time. Even the mighty titans can be downed if they have no cover. What fodder does is deflects some of the firepower of the big ships from other big ships to themselves. So a titan attacking a fleet with sufficiant fodder will hit the biggest guns of the fleet (dreads and BBs) far less then the defender is being hit if it has no fodder, resulting in eventual defeat.
That said, your target in every defensive engagement isn't the big guns, but the fodder. Kill the fodder and you grind an offensive to a halt. And the best way to kill fodder is with fighters, LOTS of fighters.
Fighters backed with command centers become vicious killers at a very small cost. 1000 fighters is dangerous to almost any fleet, more than that and you're doing serious damage. Back it with 10 command centers and you can start to seriously damage everything up through cruisers. At twice the cost (and nearly twice the damage if you have the tech) bombers will do just as well, often better. 1000 fighters and bombers will ruin all but the largest fleet's day. Corvettes do about as much damage as bombers at 4 times the cost of a fighter, so aren't great for defensive purposes. Destroyers and Frigates are on the same level as Corvettes in their defensive effectiveness. Heavy Bombers and Ion Bombers, well, suck at defensive actions. Yes, they can do serious damage to big gun ships, but if there is sufficant fodder, they'll be wiped out. Best to pull them out and use them for a counter attack then straight up defense. Ion Frigates as well.
But what of the big guns? Unless you are sure you can win in a defensive operation, take them and run. The investment cost of a even a cruiser isn't worth it if they can't bring their guns to bare on the the big guns of the attacking force. Pull them away and look for an oppertunity to launch a counterattack.
And that is the core tactic of defending a base: Clear out your big, expensive ships and let the fighters, bombers, vettes, destroyers and frigates do the fighting. With command centers and decent turrets behind them, you won't need to put your big guns in harm's way to win.
If you lose, take heart that all is not lost. If you played it right, the attacker will have suffered MASSIVE losses in attacking your base, and likely didn't make it up via pillaging. The only way they can start to reclaim their money is to gather the debris, and here, again, you have the advantage.
Kill the recyclers. That's all you have to do. Set your build ques early so you can produce fighters and or bombers that will pop out just before the tick of the half hour and ATTACK! Kill as many recyclers as you can and deprive them of those extra credits. You'll also strip the occupying forces of MORE fodder, prepping them for your counter attack, or if you don't have one, the waves of HBs and IBs you'll start cranking out on your planet. The goal when occupied is to make them pay for every hour they hold your planet.
That's about as good as it's going to get when it comes to a defensive war. Keep this in mind for when you're on the offensive, as you'll be on the recieving end of this. Adjust your strategy to match.