Of all English punctuation, quotation marks seem like they should be straightforward, whether they are being used for dialogue or quoting another author's material. If the text is part of the quotation, it goes inside the quotation marks, but if not, it should be placed outside. But like so many other aspects of English grammar and punctuation, it's just not that simple, and for that reason, I've seen a number of writers, especially nonnative English speakers, struggle with the placement of closing quotation marks.

Quotation Marks with Commas and Periods
Opening quotes are simple regardless of the situation. The punctuation is placed immediately preceding the quotation, but closing quotation marks pose more of a problem. For example, the rule for closing quotes in reference to commas and periods seems almost counterintuitive. Commas and periods should precede the closing quotation marks, whether they are part of the quote or not.

Wait,” Amy said. “I'm not ready to leave yet.”

Since the pause seems natural after “wait,” it makes sense to include the comma in the quotation marks as well as the period since the full sentence that follows is still Amy speaking. Now, consider the following example:

They studied the Robert Frost poem “Mending Wall.”

Obviously, the period is not part of the poem's title, but it's punctuated this way nonetheless.

Quotation Marks with Question Marks, Colons, Semicolons, and Exclamation Points
But not all punctuation in this matter defies logic. Unlike commas and periods, question marks, colons, semicolons, and exclamation points do not always appear within quotation marks. In fact, these punctuation marks consistently follow the closing quotation mark unless it is part of the quote.

Marie asked, “Where are you going?”

Are you familiar with Robert Frost's poem “Departmental”?

Alternative System of Quotation Marks with Other Punctuation
This inconsistency in punctuation rules is not universal in English grammar. In fact, it seems to be only an American style. According to British style, only punctuation marks that are part of the quotation should be included within the quotation marks. All other punctuation marks should follow them. But then, British style also favors single quotation marks rather than the American double.

While it seems counterintuitive, keep in mind that most American publishers will prefer the American style and will expect you to use it as well. 

Just keep in mind when you are writing that commas and periods precede the closing quotation mark at all times, but the rest of the punctuation marks follow the “common sense” rule.