The answer to this question depends of your definition of a computer.
The first known counting devices or tools were Tally Sticks from about 35,000 BC.
The Abacus was then invented by the Babylonians in 2400 BC.
In 1837, Charles Babbage, a British professor of mathematics described his idea for the Analytical Engine, the first stored-program mechanical computer. The Analytical Engine was designed to be powered by a steam engine and was to use Punched Cards, which was used to program mechanical looms at the time.
What made the Analytical Engine unique was that it was designed to be programmed.
It was because of this and the fact that it would be more than 100 years that any similar devices would be constructed, Charles Babbage, would be considered by many as the "father of computing”. Because of legal, financial, and political obstacles, the Analytical Machine would never be completed. Charles Babbage was also difficult to work with and alienated the supporters of his work.
In 1939, John V. Atanasoff and Clifford Berry developed the Atanasoff-Berry Computer (ABC) at Iowa State University, which was regarded as the first electronic digital computer. The ABC was built by hand and the design used over 300 Vacuum Tubes and had capacitors fixed in a mechanically rotating drum for memory.
The ENIAC (Electronic Numerical Integrator and Computer), constructed in the US in 1943, is widely regarded as the first functionally useful electronic general-purpose computer. Influenced by the ABC, it was a turning point in the history of computing and was used to perform ballistics trajectory calculations and used 160 kW of power. World War II is known to be the driving force of computing hardware development and one of such use of computers was in communications encryption and decryption.
The UNIVAC I (Universal Automatic Computer) was the first commercially available, "mass produced” electronic computer manufactured by Remington Rand in the USA and was delivered to the US Census Bureau in June 1951. It used 5,200 vacuum tubes and consumed 125 kW of power. 46 machines were sold at more than $1 million each.
The microprocessor eventually led to the development of the microcomputer, small, low-cost computers that individuals and small businesses could afford.
By the 1990s, the microcomputer or Personal Computer (PC) became a common household appliance, and became even more widespread with the advent of the Internet.