A comma is used to separate a quotation from the rest of the sentence. A quotation is when you repeat something another person has said or written. The British and American styles have slight differences. The Americans put the comma before the quotation mark, the British put it afterwards.
"Hello," said Tom. (USA)
"Hello", said Tom. (UK)
When a full sentence is quoted both British and Americans put an exclamation point or full stop inside the quotation marks.
Tom said "I am feeling very tired today!"
Both British and Americans use single quotation marks for a quotation inside a quotation. Both don't use the comma after a full sentence quotation.
The British put the full stop after a single quotation mark. The Americans keep it before the single quotation mark and after the last word.
"He said, 'I am feeling very tired today.' after walking to school." (USA)
"He said, 'I am feeling very tired today'. after walking to school." (UK)
Did you notice that I did not use a comma after the internal quotation? In this case it would interrupt the flow of the sentence.
Sometimes writers do not use commas when the word said is in front of the quotation. Others insist on it. However in very short sentences as shown below the comma can be dropped.
Tom said "Goodbye!"
by John Larrysson
A native English speaker who has been teaching practical English in Hong Kong for more than a decade.