In the Matrix universe, humanity is responsible for the creation of a race of machines that have all but conquered the Earth and enslaved mankind via the Matrix: a virtual reality created to keep human minds alive and complacent whilst the Machines live off of their bioelectric and biothermal energy, essentially turning human beings into organic batteries. As is usually the case for a man versus machine scenario, the events of the Matrix franchise are the product of man's own arrogance and fear.
The Second Renaissance
During the 21st or 22nd century, the technology of human society had advanced to the point where robots were commonplace in everyday life, performing the more mundane and/or hazardous tasks of everyday living. However, fear and panic quickly arose amongst the human populace after a servant robot - B1-66-ER - was taken to court after killing his master who wanted the robot replaced. B1-66-ER argued that he "did not want to die" and acted in self-defence, but was dismantled regardless. This action spurred humanity to begin mass exterminations of all robots across the planet. During this period of violence, the Machines' AI would grow and develop as their persecution continued. Eventually, Machinekind united not in opposition of humanity, but to build their own society and attempt to coexist peacefully with their former masters. The Machines founded their own nation - 01 - and for a time, prospered. Soon, however, 01's prosperity began damaging human economy, prompting mankind into severing all ties with the Machines. Machine ambassadors petitioned for entry into the United Nations but were unanimously rejected and assaulted. Though the Machines had only sought peaceful coexistence, it seemed humanity only saw them as a threat.
Operation: Dark Storm
Refusing to share the world with the Machines, the United Nations sanctioned a nuclear bombardment of 01. The Machines, of course, were more resilient to radiation and heat than fragile human flesh, but they now realised that mankind was hellbent on removing them from the world. In response to the nuclear assault, 01's armies spread out across the Earth, conquering whole nations and crushing all resistance. The remaining human nations decided that the best way to stop the Machines was to cut off their energy supply. The Machines survived on solar energy and thus, Operation: Dark Storm was enacted. Aircraft seeded the sky with some manner of dark clouds that blocked out the sun and brought eternal darkness upon the world. With Dark Storm in effect, the combined human armies prepared to face the vengeful Machines in final battle. And in the end... they lost.
Rise of the Machines and the Creation of the Matrix
The Machines overwhelmed mankind's armies, committing wholesale slaughter and taking both the dead and the living to experiment on. Cut off from the sun, the Machines had to find a new energy source and so they found the most efficient alternative in humanity itself. They installed vast 'farms' that housed humans in the millions, keeping them suspended in tanks of liquid nutrients. As the old human race began to die out, the Machines began cloning their new organic batteries en masse and used the liquefied remains of the dead to feed their new clones. To maintain their 'crops' - and possibly motivated by some sense of retribution - the Machines created The Matrix. Originally, this virtual construct was designed to be the ideal environment where all humans could be happy and want for nothing. However, the human mind could not be fooled by a fake "perfect" world and would not accept it, leading to countless deaths. Eventually the Machines were able to produce a realistic facsimile of 20th century human society which human minds could accept, not idyllic and incomprehensible like the first system. And so from then onward, for a time, the Machines ruled the world without any opposition. But then came The One...
The Coming of the One and the Birth of Zion
At least 100 years prior to the beginning of the Matrix movie trilogy, a man was born within the Matrix possessing unique abilities and powers, able to see the truth of the world and alter the system as he chose. Exactly how or why this person was different from the other farm-grown humans is never made clear, but he was responsible for freeing several people from the Matrix, giving humanity a chance to fight back against the Machines. Eventually, these liberated humans would go on to build Zion, the last outpost of free humans. Since the Earth's surface had been rendered uninhabitable, the city of Zion was constructed near the planet's core, providing thermal energy for fuel to power the machinery that they would need to survive. After the founding of Zion, the Machines took steps to enhance the Matrix to prevent the loss of more human crops. They now faced a renewed outside threat from Zion and became determined to destroy it. The next 100 years would see a bitter war being waged between Zion and the Machines. Despite having vast, superior resources, the Machines have yet to completely eradicate Zion. In The Matrix Reloaded, according to the Architect, Zion has been destroyed numerous times and there have even been numerous Ones between the original and the trilogy's main protagonist, Neo.