The Physics of Defogging
To complement Ameriwire's fine WU above, I'd like to say something about the physics of defogging. If you want to know what to do look at his WU; this one will address why it works. Let's talk specifically about the (much more common) case that the fog is forming on the inside of the windshield.
When your windshield “fogs up”, it is generally because air near the windshield is too moist and too cold. The air around you contains water (H2O) in gaseous form, called steam or water vapor (I'll use the latter). The amount of water vapor that a certain volume of air can contain depends on its temperature; the hotter air is the more water vapor it can hold (see this node for details). At a set temperature, a certain volume air can hold up to a certain amount of water vapor, and then it becomes saturated. If you put in any more water vapor, then water will start to condense into liquid on any available surface or particulate matter (the latter is how clouds form). How close the amount of water vapor in the air is to saturation is the relative humidity, so when relative humidity reaches 100% condensation starts to form. Now, if you cool the air down, the amount of water vapor it can hold becomes less and less, so even if you don't add any more water, the relative humidity will keep going up. Eventually, if you cool the air to a low enough temperature, it will reach saturation and condensation (a.k.a. dew) will form; that temperature is called the dew point.
Condensation (“fog”) forms on your windshield when the air becomes saturated, meaning it was cooled below the dewpoint or a lot of moisture was added to it, usually both. Normally, the cause of the fogging is people breathing inside the car. We're made of mostly water, so the air we exhale is going to have a high relative humidity, and the air will be close to our rather hot body temperature (around 98 °F), so that means the air will be holding a lot of moisture. As people in the car breathe, they add moisture to the air inside the car and gradually raise the humidity. If it's cold the air can't hold much moisture, so the relative humidity increases rapidly. If it's rainy, then the relative humidity is already high and it doesn't take much extra moisture to push it to saturation. Since your car is not hermetically sealed, humidity is slowly balanced by outside air (which is why it doesn't always fog up), but if it's particularly cold and/or moist, this may not happen fast enough, so the relative humidity gets very high. Generally, the humidity in the whole car often won't be all that close to 100%, but the windshield is in contact with the, generally colder, outide air, so it will cool air next to the inside surface of the windshield down causing the air right there to become saturated and form condensation on the windshield.
What to do
Ameriwire outlines the 3 basic strategies. You want to lower the relative humidity of the air near the windshield. You can do that by either warming the air or removing the moisture. This is achieved by blowing air from your car's heating and cooling system though the vents by the windshield and across the windshield. Using those vents is often called the defrost or defog setting.
The first step to try is to use outside air rather than recirculated air. The air close to the windshield is probably about the same temperature on both sides, so if the outside isn't fogging up and the inside is (almost always the case) then the outside air must be less moist, and blowing outside air in will lower the humidity. To augment this you can also open the windows if the situation permits.
The second thing to try is using hot air, because since it's hot is can hold more moisture. That hot air will carry away some of the moisture from the air near the windshild, and hopefully evaporate some of the condensation. The downside of this is that the car may become uncomfortably hot if it's not terribly cold outside; however, you can do this in concert with opening the windows if you want and achieve some balance of temperature.
The final, and most effective, thing you can do is turn on the air conditioning. The A/C takes air and cools it down with the compressor. As we discussed cold air holds less moisture, so during the cooling down process, the very cold air drops below the dew point and a lot of the water vapor condenses out of the air (this is part of the reason why wall A/C units usually drip water). Then the air is blown out, now with a lot less moisture, and as it comes out and mixes with air in the car it usually heats up significantly, meaning its relative humidity is low. Thus, you can think of the air as a wet sponge and imagine that the A/C is wringing out the sponge. This now dry air is blown out across your windshield and soaks up the moisture very quickly. Though the A/C cools down the air, you can also turn on your heat at the same time if you want (it isn't any more wasteful 1). For fastest results, use A/C and heat together, though you probably don't want to do that if it's already hot out. You might want to start out using outside air, though eventually the air inside will be drier, and then you'd want to switch. Honestly it probably doesn't matter much either way. There are two down sides to this approach. The first is that unlike the heat and fan 1, the A/C compressor uses a significant amount of extra gasoline. The second is that if you use cold air and you're too overzealous, then the A/C can cool the windshield so much that the air on the outside drops below its dew point and condensation forms on the outside of the windshield.
I should mention that the rear window often has a completely different mechanism for defogging. Since you're blowing all this air up near the front of the car, it will take quite a while to affect the rear of the car; however, the rear window usually has a set of electric heating elements embedded in it. By turning this on (usually called something like “rear defrost”) you heat up the rear window, raising the temperature of it and the air around it and evaporating the condensation.
Hopefully this sheds some light on things, or else it's another installment in the series called “trival things that unperson can make needlessly complex”.
1. The fan uses negligible power (I think), and heat in your car is just waste heat from your engine that is produced whether or not you use it, so you might as well make use of it.