In the future, humanity, having begun to explore the Universe and master interplanetary spaceflight, encounters an alien race called the Formics, commonly referred to in the series as the "buggers". The discovery of a bugger forward base in the asteroid Eros leads to war between the species that the humans narrowly win, resulting in the discovery of advanced alien technology, including gravity manipulation. Ostensibly in preparation for another bugger invasion, an International Fleet (I.F.) is established on Earth, who create a Battle School in Earth's orbit to develop gifted children into commanders capable of defeating the buggers in the next war.
Protagonist Andrew "Ender" Wiggin is born a "Third": a rare exception to Earth's two-child policy, allowed by the government due to the promise shown by his two older siblings. The eldest, Peter, is a highly intelligent sociopath who sadistically bullies Ender, while his sister, Valentine, is more sympathetic towards him. The I.F. remove Ender's monitoring device at six years old, seemingly ending his chances of Battle School, and he gets teased by a fellow student, Stilson. Ender beats up Stilson before the fight is broken up; unknown to Ender, Stilson dies from his injuries. When explaining his actions to I.F. Colonel Hyrum Graff, Ender states his belief that, by showing superiority now, he has prevented future struggle. Graff, on hearing of this, offers Ender a place in the Battle School.
Graff and the other leaders of the school covertly work to isolate Ender from his fellow recruits and prevent him from growing too comfortable in his environment. The cadets participate in competitive war simulations in zero gravity, where Ender quickly masters the game and dominates his opponents. The school continually tries to break Ender down, first promoting him to command a new army composed of raw recruits, then pitting him against multiple armies at once, but Ender's success continues. Ender's jealous ex-commander, Bonzo Madrid, draws him into a fight outside the simulation, and Ender, once again seeking to preemptively stop all future conflicts with Bonzo, unintentionally kills him.
On Earth, Peter Wiggin uses a global communication system to post political essays under the pseudonym "Locke", hoping to establish himself as a respected orator and thence as a powerful politician. Valentine, despite not trusting Peter, agrees to publish alongside him as "Demosthenes". Their essays are soon taken seriously by the government. Though Graff is told their true identities, he recommends that it be kept a secret, because their writings are politically useful.
Ender, now ten years old, is promoted to Command School on Eros after a brief respite on Earth. After some preliminary battles in the simulator, he is introduced to a former war hero, Mazer Rackham. From now on, Ender participates in simulations created and controlled by Mazer. As the skirmishes become harder, he is joined by some of his friends from the Battle School as sub-commanders. Despite this, Ender becomes depressed by the battles, his isolation, and by the way Mazer treats him.
When told that he is facing his final test, Ender finds his fleet far outnumbered by the buggers surrounding their queens' home world. Hoping to earn himself expulsion from the school for his ruthlessness, he sacrifices his entire fleet to fire a Molecular Detachment Device at the buggers' home world. The Device destroys the planet and the surrounding bugger fleet. Mazer informs Ender that the "simulations" he has been fighting were real battles, directing human spacecraft against bugger fleets via an ansible, and that Ender has won the war. Ender becomes more depressed on learning this, realizing that he has committed genocide.
When he recovers, he learns that, at the end of the bugger war, Earth's powers fought among themselves. He stays on Eros as his friends return home and colonists venture to other worlds, using Eros as a way station. Among the first colonists is Valentine, who apologizes that Ender can never return to Earth, where he would be exploited by Peter and other politicians to fulfill their own purposes. Instead, Ender joins the colony program to populate one of the buggers' former worlds. There, he discovers the dormant egg of a bugger queen, who reveals that the buggers had initially assumed humans were a non-sentient race, for want of collective consciousness, but realized their mistake too late, and requests that Ender take the egg to a new planet to colonize.
Ender takes the egg and, with information from the Queen, writes The Hive Queen under the alias "Speaker for the Dead". Peter, now the leader of Earth and seventy-seven with a failing heart, recognises Ender as the author of The Hive Queen. He requests Ender to write a book about him, which Ender titles The Hegemon. The combined works create a new type of funeral, in which the Speaker for the Dead tells the whole and unapologetic story of the deceased, adopted by many on Earth and its colonies. In the end, Ender and Valentine board a series of near-lightspeed starships and visit many worlds, looking for a safe place to establish the unborn Hive Queen.