Strictly speaking, grammar is the unique patterns of a language, the system of how speakers can put together words and sentences. Grammar encompasses morphology (how to form words), syntax (how to form sentences) and semantics (what words and sentences mean). This is what linguists talk about when they talk about grammar.
The following areas are not grammar in the strict definition, but fall under the larger definition of grammar as “rules and principles of language”: punctuation, phonology (the sound system), orthoepy (correct pronunciation), orthography (correct spelling) and lexicon (vocabulary and usage). These (plus morphology, syntax and semantics) are what most people talk about when they talk about grammar.
The second definition of grammar is pretty broad, but there are language-related rules that fall outside of grammar. Many of these are style rules: whether to put the period inside or outside of quotation marks, whether e-mail is hyphenated or a single word, and so on. Style rules are set to ensure consistency in writing, so readers aren’t distracted by small differences. (And yes, readers do notice when things aren’t consistent.)
Style dictates how words (and numbers) get rendered, how punctuation gets used and how text and graphics get formatted, as well as bigger-picture things like which vulgarities are acceptable for publication and in what contexts, jargon and euphemisms to avoid, and so on. But the thing about style is that many of the rules are decided arbitrarily — and writing that diverges from a particular style isn’t necessarily wrong. So people who hyperventilate over, for example, someone using — or leaving out — an Oxford comma, are wasting their breath. Either choice is OK (as long as the sentence is clear), but a publication’s style dictates which way to go.
Most newspapers in the U.S. follow Associated Press style, and most have a “house” style guide that addresses local usages and policies and notes divergences from AP style. Book publishers tend toward the Chicago Manual of Style, academia goes with APA style or MLA style, and Yahoo has its own style guide focused on websites and other online media. Users of any of these are familiar with the minutiae therein and will take pleasure in the satirical style guide “Write More Good,” by the Bureau Chiefs of @FakeAPStylebook.
Most editors also refer to usage manuals such as Garner’s and Merriam-Webster’s Dictionary of English Usage, as well as general style guides such as Strunk and White’s venerable (or fusty, choose your adjective) “The Elements of Style.”
Stylebooks usually cover grammar and usage matters too, but there are lots of conventions in writing that are strictly matters of style — arbitrarily decided — and have no bearing on grammar. These include spelling numbers out or using figures, certain punctuation preferences, putting titles in italics or quotes, British vs. American spellings* and usages, and so on.
Saying Sept. 1, 2011, is no more or less correct than saying September 1st, 2011, or 1 September 2011 — but one follows AP style and the others don’t. It’s not “wrong” to put a period outside of quotation marks, or inside, for that matter: one is typical of British style and one is more common in the U.S. “Towards” means the same thing as “toward” — neither is inferior — but it may not be the preferred form in the style of a publication.
The important thing to remember is that many aspects of written language are determined by style, not grammar — and just because something diverges from a particular style does not mean it’s wrong.
* “Write More Good” illustrates this point thus: “caliber/calibre: The diameter of a gun barrel; the diametre of a gun barrle.”