When writing compound sentences, use a comma before the coordinating conjunction.
John went to the bank, and he went to the post office.
It was raining hard, but he stayed dry.
When writing complex sentences, use a comma when the subordinating clause is first.
Although the test was canceled, John still studied at the library.
Because the textbooks did not come, the test was canceled.
When the main clause is first, do not use a comma.
John still studied at the library although the test was canceled.
The test was canceled because the textbooks did not come.