No comma:
* Direct object: "The book was written by John."
* Prepositional phrase: "The thief escaped by climbing over the fence."
* Adverbial phrase: "I'll be there by 5 pm."
Comma:
* Parenthetical phrase: "The book, written by John, was a bestseller." Here, "written by John" is a parenthetical phrase that could be removed without changing the meaning of the sentence.
* Non-restrictive clause: "The book, which was written by John, was a bestseller." Here, the clause "which was written by John" provides additional information about the book but is not essential to its identification.
Key takeaway: If the phrase with "by" is essential to the meaning of the sentence, you don't need a comma. If it's optional information, you do.