Here's the general rule:
* You usually need a comma when a dependent clause (a clause beginning with a subordinate conjunction) comes *before* an independent clause.
Examples:
* Because it was raining, we stayed inside.
* Although she was tired, she finished her work.
* When I saw him, I waved.
However, there are exceptions:
* If the dependent clause is very short (4 words or less) and doesn't create confusion, you can often omit the comma.
* After class, I went home.
* Before lunch, we cleaned up.
* If the dependent clause is embedded within the independent clause, you don't need a comma.
* The dog, which was barking loudly, ran into the street.
Here are some common subordinate conjunctions:
* Time: after, before, since, while, when, until, as soon as
* Cause and Effect: because, since, so that, as
* Contrast: although, though, even though, while, whereas
* Condition: if, unless, whether, in case
* Place: where, wherever
If you are ever unsure about whether to use a comma, it's always better to err on the side of caution and include it.