Military science fiction
Characteristics: Traditional military values of courage under fire, sense of duty, honor, sacrifice, loyalty, and camaraderie are often emphasized. The action is typically described from the point of view of a soldier in a science fictional setting of or near battle. Typically, the technology is more advanced than that of the present and described in detail. In some stories, however, technology is fairly static, and weapons that would be familiar to present-day soldiers are used, but other aspects of society have changed. Technology may not be emphasized in such stories as much as other aspects of the characters' military lives, cultures, or societies. For example, women may be accepted as equal partners for combat roles, or preferred over men.
When the "extravagan[t]" depictions of war in space operas faded along with pulp fiction more generally, military science fiction developed with a "more disciplined and more realistic notion of the kind of armies which might fight interplanetary and interstellar wars, and the kinds of weapons they might use".
In many stories, the usage or advancement of a specific technology plays a role in advancing the plot, such as deploying a new weapon or spaceship. Some works draw heavy parallels to human history and how a scientific breakthrough or new military doctrine can significantly change how war is fought, the outcome of a battle, and the fortunes of the combatants. Many works explore how human progress, discovery, and suffering affect military doctrine or battle, and how the protagonists and antagonists reflect on and adapt to such changes.
Many authors have either used a galaxy-spanning fictional empire as a background for the story, or have explored the growth and/or decline of such an empire. The capital of a galactic empire is sometimes a "core world," such as a planet relatively near a galaxy's centrally-located supermassive black hole, which has advanced considerably in science and technology compared to current human civilization. Characterizations of these empires can vary wildly from malevolent forces that attack sympathetic victims, to apathetic or amoral bureaucracies, to more reasonable entities focused on social progress.
A writer may posit a form of faster-than-light travel in order to facilitate the enormous scale of interstellar war. The long spans of time (e.g., decades or centuries) required for human soldiers to travel interstellar distances, even at relativistic speeds, and the consequences for the characters, is a dilemma examined by authors such as Joe Haldeman and Alastair Reynolds. Other writers such as Larry Niven have created plausible interplanetary conflict based on human colonization of the asteroid belt and outer planets by means of technologies utilizing the laws of physics as currently understood.

Definitions by contrast: Several subsets of military science fiction share characteristics of the space opera subgenre, concentrating on large-scale space battles with futuristic weapons in an interstellar war. Many stories can be considered to be in one or both the military science fiction and space opera subgenres, such as The Sten Chronicles by Allan Cole and Chris Bunch, Ender's Game series by Orson Scott Card, Honorverse by David Weber, Deathstalker by Simon R. Green, and Armor by John Steakley.
At one extreme, a military science fiction story can speculate about war in the future, in space, or involving space travel, or the effects of such a war on humans; at the other, a story with a fictional military plot may have relatively superficial science fictional elements. The term "military space opera" may occasionally denote this latter style, as used for example by critic Sylvia Kelso when describing Lois McMaster Bujold's Vorkosigan Saga.  Examples that feature aspects of both military science fiction and space opera include the Battlestar Galactica franchise and Robert A. Heinlein's 1959 novel Starship Troopers.
A key distinction of military science fiction from space opera is that space operas focus more on adventurous stories and melodrama, while military science fiction focuses more on warfare and technical aspects. The principal characters in a space opera are also not military personnel, but civilians or paramilitary. Stories in both subgenres often concern an interstellar war in which humans fight themselves and/or nonhuman entities. Military science fiction, however, is not necessarily set in outer space or on multiple worlds, as in space opera and the space Western.
Both military science fiction and the space Western may consider an interstellar war and oppression by a galactic empire as the story's backdrop. They may focus on a lone gunslinger, soldier, or veteran in a futuristic space frontier setting. Western elements and conventions in military science fiction may be explicit, such as cowboys in outer space, or more subtle, as in a space colony requiring defense against attack out on the frontier. Gene Roddenberry described Star Trek: The Original Series as a Space Western (or more poetically, as "Wagon Train to the stars"). The TV series Firefly and its cinematic follow-up Serenity literalized the Western aspects of the space Western subgenre as popularized by Star Trek: it features frontier towns, horses, and a visual style evocative of classic John Ford Westerns. Worlds that have been terraformed may be depicted as presenting similar challenges as that of a frontier settlement in a classic Western. Six-shooters and horses may be replaced by ray guns and rockets.
A "thematic subdivision" of MSF are works where "ex-military protagonists [are] drawing on their battle experience for tough and violent operations in (more or less) civilian life", typically in a law enforcement setting. Some examples include Richard Morgan's Takashi Kovacs book such as Altered Carbon (2002) and Elizabeth Bear's Jenny Casey books, such as Hammered (2004).

History: 

19th century and up to early 20th century: Precursors for military science fiction can be found in "future war" stories dating back at least to George Chesney's story "The Battle of Dorking" (1871). Written just after the Prussian victory in the Franco-Prussian War, it describes an invasion of Britain by a German-speaking country in which the Royal Navy is destroyed by a futuristic wonder-weapon ("fatal engines").
Other works of military science fiction followed, including H.G. Wells's "The Land Ironclads". It described tank-like "land ironclads," 80-to-100-foot-long (24 to 30 m) armoured fighting vehicles that carry riflemen, engineers, and a captain, and are armed with semi-automatic rifles.

Post-WWII era: Eventually, as science fiction became an established and separate genre, military science fiction established itself as a subgenre.  One such work is H. Beam Piper's Uller Uprising (1952) (based on the events of the Sepoy Mutiny). Robert A. Heinlein's Starship Troopers (1959) is another work of military science fiction, along with Gordon Dickson's Dorsai (1960), and these are thought to be mostly responsible for popularizing this subgenre's popularity among young readers of the time.
The Vietnam War led to the "polarization of the sf community", which can be seen in the June 1968 issue of Galaxy Science Fiction, in which one page of pro-war sf authors listed their names and on another page, anti-war sf authors put their names.
The Vietnam War has been noted by the Encyclopedia of Science Fiction as having impacted anthologies such as In the Field of Fire (1987) and novels such as The Healer's War (1988) by Elizabeth Ann Scarborough and Dream Baby (1989) by Bruce McAllister.
The Encyclopedia of Science Fiction states that the Vietnam War's influence can be seen indirectly in novels such as Joe Haldeman's The Forever War (published in Analog over 1972–1975) and Lucius Shepard's Life During Wartime (1987).
The Vietnam War resulted in veterans with combat experience deciding to write science fiction, including Joe Haldeman and David Drake.  Throughout the 1970s, works such as Haldeman's The Forever War and Drake's Hammer's Slammers helped increase the popularity of the genre. Short stories also were popular, collected in books such as Combat SF, edited by Gordon R. Dickson. This anthology includes one of the first Hammer's Slammers stories, as well as one of the BOLO stories by Keith Laumer and one of the Berserker stories by Fred Saberhagen. This anthology seems to have been the first time these stories specifically dealing with war as a subject were collected and marketed as such. The series of anthologies with the group title There Will be War edited by Pournelle and John F. Carr (nine volumes from 1983 through 1990) helped keep the category active, and encouraged new writers to add to it.
David Drake wrote stories about future mercenaries, including the Hammer's Slammers series (1979), which follows the career of a future mercenary tank regiment. Drake's series which "helped initiate a fashion for sf about mercenaries", including The Warrior's Apprentice (1986) by Lois McMaster Bujold.
A twist was introduced in Harry Turtledove's Worldwar series depicting an alternate history in which WWII is disrupted by extraterrestrials invading Earth in 1942, forcing humans to stop fighting each other and unite against this common enemy. Turtledove depicts the tactics and strategy of this new course of the war in detail, showing how American, British, Soviet, and German soldiers and Jewish guerrillas (some of them historical figures) deal with this extraordinary new situation, as well as providing a not unsympathetic detailed point of view of individual invader warriors.