The system of rules governing how words combine into phrases and sentences in a language. Every language has one, every speaker knows it without being taught, and what linguists mean by grammar differs sharply from what the word means in schools.

Prescriptive grammar states how people ought to write or speak, generally according to the conventions of a prestige variety.
Descriptive grammar states how people actually do, and is what linguistics studies.
The distinction matters because prescriptive rules frequently describe nothing. The prohibition on splitting an infinitive in English was imported from Latin, where the infinitive is one word and cannot be split, and it has never described English usage.
Constructions labelled ungrammatical by prescriptivists are usually regular and rule-governed in the varieties that use them. Double negation is standard in French and in many English dialects and follows consistent rules in each.
Linguists therefore treat a construction as grammatical if native speakers produce and accept it, and the notion of a language having a single correct form is a social and political fact rather than a linguistic one.
None of this means prescriptive conventions are unimportant. Standard varieties carry social consequences, and teaching them is teaching a code that opens doors, which is a different claim from saying other varieties are defective.
Morphology concerns word structure: how words are built from smaller meaningful units, and how they change form for tense, number, case or agreement.
Syntax concerns how words combine. The central finding is that sentences are hierarchical rather than merely sequential: words group into phrases, and phrases into larger phrases, and grammatical rules operate on those groups rather than on adjacent words.
The evidence for hierarchy is that rules ignore linear proximity. Forming a question in English moves the auxiliary of the main clause, not the nearest auxiliary, which requires knowing the structure rather than the order.
Phonology concerns sound patterns, and semantics meaning, and both interact with grammar.

Word order varies systematically. Subject-object-verb and subject-verb-object account for the large majority of languages, and other orders occur.
Case marking varies. Some languages mark grammatical role by inflection and permit relatively free word order; others mark it by position.
Agreement varies. Some languages require extensive agreement between verbs and several arguments; others have almost none.
Some categories obligatory in one language are absent in another. Many languages require the speaker to mark evidentiality, meaning whether a statement is known directly or by report. Many have no grammatical tense and express time lexically. Grammatical gender is present in many and absent in many.
What appears essential in a familiar language frequently turns out to be a local option.

Children acquire the grammar of their language without instruction and without correction being necessary or generally effective.
The evidence that they acquire rules rather than memorising sentences is over-regularisation: a child who has said went will later say goed, applying a regular rule to an irregular verb they previously produced correctly. Nobody says goed to them.
Acquisition follows a broadly consistent sequence, and by around age four or five a child controls most of the grammar of their language.
How this is possible is the substance of a long dispute. The nativist account, associated with Noam Chomsky, holds that children are equipped with innate constraints on possible grammars, which is treated in the universal grammar capsule. Usage-based accounts hold that general learning mechanisms plus sufficient input suffice. The argument continues and both positions have shifted substantially.
Second language acquisition after childhood is different in course and outcome, and the critical period hypothesis concerning that difference is treated in its own capsule.
Grammar is the system that allows a finite vocabulary and a finite set of rules to produce an unlimited number of sentences, including ones never previously spoken, which is the property that makes human language different in kind from other communication systems.
The descriptive and prescriptive distinction also carries beyond linguistics. Judgements about how people speak are among the most socially consequential judgements made about them, and the linguistic finding that stigmatised varieties are fully rule-governed has direct implications for education and for how those judgements should be regarded.