Pinning down the "first" video game is a surprisingly debated topic, and the story stretches back further than most people expect.
The concept of a computer that could play games dates all the way back to Charles Babbage. While designing his never-completed Analytical Engine in 1837, he realized a machine built to handle any mathematical function could also play simple games like tic-tac-toe and chess.
The first actual computer built to play a game was the Nimatron, developed by Edward U. Condon in 1940 to play the ancient game of Nim. It displayed the game using columns of lightbulbs and was shown at the New York World's Fair that same year, where around 50,000 people played it.
The first computer game shown on an actual screen was OXO, written by Alexander S. Douglas in 1952 for the EDSAC computer as part of his PhD thesis at Cambridge.
In 1962, Steve Russell created Spacewar! for the PDP-1, making it the first game developed for an existing computer and the first to be distributed, since its source code was freely shared. Then in 1971, Computer Space by Nutting Associates became the first commercially sold video game, created by Nolan Bushnell and Ted Dabney, who would go on to found Atari. A year later, in 1972, Ralph H. Baer's Magnavox Odyssey became the first commercially sold home console.
From a Victorian-era idea to the arcade and the living room, the invention of the video game was a gradual, fascinating journey.