Understanding brain function is one of the most important problems in human history. At present, there is no concrete theory for how the brain works. Here, a theory is presented that provides a detailed mechanistic biological account of the brain's capacities, including motor control, functional states, language, and thinking. Brain function is managed by a well-defined r e sponse ( R ) p r ocess t h at i s generally similar to the process underlying the immune system. The R process is strongly reflected in the brain's anatomy, physiology, and external i n teractions. Different R process stages are supported by distinct excitatory networks located in different cortical layers, hippocampal fields, and bagal ganglia paths, by distinct coordination networks comprised of GABAergic interneurons, and by distinct molecular agents. The roles of norepinephrine, serotonin, dopamine and acetylcholine is to promote the alert, planning, goal-setting and execution R process modes, respectively. Opioids and oxytocin promote termination by success, failure, fight o r r un, w hile g lucocorticoids and cannabinoids suppress acute responses to protect cells. The R process has two instances occurring at different time scales. The millisecondscale Quax process implements the execution of hierarchical sequences of movements and thoughts, in which the selection of the next action is determined via interaction between top-down predictions and sensory inputs. The slower Need process controls the satisfaction of internal and external needs. The theory differs from the existing standard accounts in many of the major topics (e.g., the basal ganglia, dopamine, language), and shows how cognition results from biological processes.