In Star Trek the Next Generation the Borg are a collective in which all the people are part of a single mind. What never seems to get talked about is how the Borg first developed into a collective in the first place. How might a collective such as the Borg develop?
In a lot of sci-fi movies and books the concept of "The Matrix" is being discussed. Mostly as something negative. While The Borg are displayed mostly as negative too, let me introduce you to the Borg mindset:
Problem: There is overwhelming amount of information. So big that one single person cannot even grasp how big the pile of information is.
Wouldn't it be great if you could just know who this musician on the poster is? Right now we solve it by ultra portable devices which have access to all collective human knowledge. Commonly we call them "cellphones."
But imagine. What if you just made a thought about: "I wish to know who this person is." And collective knowledge would immediately respond to you!
Solution: Implant a chip directly into your brain. This chip will have access to the
hive internet all day long. You will know everything you need. Anytime you want!
Problem: People get injured badly. Lots of amputees or otherwise immobile people are right now on the planet.
Wouldn't it be great if we could do something about it? We have very advanced robotics. But we really cannot plug robotic arm or leg directly to the brain... But, wait a second:
Solution: Plug robotic arms and limbs to your chip in your brain. This arm will be connected to shared knowledge and you will be able to move freely!
Problem: People with robotic parts are so cool. I wish I was so cool too! The human body is so limited in its original form. Sigh
Solution: Replace your human parts with robotic parts. Super sight! Super strength! You will look cool! (Call now!)
Problem: The earth cannot feed all the people.
Solution: Get to the ships and discover the universe!
Problem: We found alien form of life, but do not know how to communicate with them.
Solution: Plug them in to collective knowledge. We have computers strong enough to serve us as translating tool.
Problem: Other aliens do not see the added value in sharing knowledge through robotic middle parts.
Solution: WE ARE THE BORG. YOU WILL BE ASSIMILATED. RESISTANCE IS FUTILE
You could follow a natural progression of our current technology and culture:
Present-day: People use smart phones to connect to to the internet, communicating and sharing information globally. Automatic translation software helps break down language barriers.
Near-future: Internet connectivity is now available as an implant, but the information is still presented in ways that we're used to experiencing it: through text or spoken communication.
Future: The internet connectivity implants are now almost entirely ubiquitous (safe when used as directed), connecting people from countless different cultures and languages.
At this point, automatic translation software no longer satisfies a society addicted to instantaneous information...it's too slow and imperfect. The solution is to remove language from the equation.
Far Future: The implants are now capable of transmitting abstract thoughts directly, without any intermediate steps of partitioning them into language first. Everyone now fully understands everyone else, always.
The Next Step: After granting perfect, language-free telepathy, the next step is allowing for shared experiences. Rather than just sharing a thought about the smell of a flower, someone can share the actual experience with whomever they want. With the whole world.
The Unintended Consequence: Possibly the greatest advantage of any intelligent species is adaptability; the ability to be shaped by our experiences and environments, rather than behaving like simple machines (I smell food to the north-- therefore, I move north). But now, all thoughts and experiences are shared from birth (forcing a child to live "cut off" from Society would be the most horrible form of abuse)...everyone becomes more and more similar over time.
Consensus: After many generations, all people would think as one-- and they would be bored. There would be nothing new or original, and uniqueness would become the most prized resource. The only way to mine that resource is to add individuals from other cultures who do not already have implants. At this point, the only such cultures would be extraterrestrial.
Assimilation: The first attempts at assimilation would likely be peaceful attempts to convert outsiders to a superior way of life (no war or unhappiness, and access to all the information you could dream of), but the Collective would instantly overpower any new "recruits" and essentially devour their distinctiveness.
Resistance is Futile: The peaceful method of assimilation would be too slow to satisfy the demands of the Collective. The experiences and memories of a few dozen individual aliens would instantly be fully analyzed by a few billion connected brains. The only way to truly add uniqueness would be to forcefully assimilate billions of individuals.
This leads to a feedback effect wherein the larger the Collective becomes, the quicker it "devours" the distinctiveness of any new members, and the less effect that distinctiveness could have on the whole of the Collective. Thus, even if they devour an entire planet of people who treasure individuality above all else, it would not be enough to sway the Collective from their chosen course.
I like Pavel's answer, though it does assume that the Borg started as a society just like us.
Their evolution could have caused them to develop as extremely social animals, causing them to form tightly knit groups and develop efficient communication skills within those groups, even more so than we did. The people never really developed personal senses of identity. Maybe their planet had a lot of large predators who themselves fought in packs, so the drive to have the larger pack and share skills with each other would be strong.
Outsiders were not only looked down upon, but rather than being ostracised, they were pitied to the point that large social groups would do all they could to include individuals - even if the individual resisted those attempts. (e.g. it was assumed they were disturbed and didn't know what was good for them)
The same began to apply for bigger groups subjugating smaller ones, devouring each other's knowledge and technology and experience - you can see how they might have found this beneficial (for both groups)
Of course they would pursue technology that would help with this. Never having developed the idea of "souls" or personal humanity (for want of a better word), and never fearing individual greed or lust for power, they would have absolutely no qualms with inventing implants to put in their bodies or microchips to put in their brains.
Here is my Borg origin story:
Species 0 is a small peaceful species. They have settled their planet and are moving out into space. They encounter species 1. Species 1 is aggressively violent. They stole warp technology from another species that landed on their planet. Species 0 has the technical edge, but one on one, their soldiers are inferior. Some of their scientists came up with an idea: they would enhance soldiers to the point of outmatching their opponents. These volunteer soldiers would become the first of the Borg.
Initially they were merely physically enhanced to the point of being able to defeat species 1. Afterwards, species 0 continued to expand and meet other species. Eventually they met another species as violent as species 1. They knew what to do and reactivated the Borg program. But this species' main advantage was coordination rather than physical prowess (perhaps this wasn't the second aggressive species they met but a later one). They were telepathic and worked together as one. To counter this, species 0 added cybernetic integration to their super-soldiers. Species 0 wins and continues their ways.
The next major event is a species that is numerous. They overwhelm the Borg's strength and coordination with superior numbers. Species 0 despaired. Driven back to their own planet and facing imminent doom, one of their scientists had an idea: instead of finding volunteers from their own society to become Borg, they could integrate captured members of the enemy army. These became the first of the modern Borg. Instead of defeating the enemy, they assimilate them. But as they assimilate the enemy, more and more of the individual units become enemy converts. In the end, their enemy assimilates them instead.
The net result is that a last resort weapon of a race of peaceful intellectuals becomes the property of an aggressive, conquering race. Resistance is futile. Everyone is assimilated.
How can we bring peace to our planet? By making sure everyone understands each other. How can we make everyone understand each other? By forcing them to share experiences. How can we do do that? By creating a new technology that connects their minds together forcing them to share thoughts and memories.
This technology has allowed us to achieve the impossible: now we have brought peace to our planet. Oh no! Some individuals don't want to accept our new unifying technology. No problem, they will be assimilated.
Now that we have brought peace to our planet, how else can we help people? How can we eliminate all disease, hunger and injury? I know, let's make everyone cyborgs!
Oh no! Earth is being invaded by spacefaring aliens! No problem: we will assimilate the Invaders and take their technology for ourselves.
How that we have space travel let's assimilated the entire galaxy so that all can have peace and order.
With a society similar to ours, the Borg could be a simple outcome of economics.
The "Borg" part of the borg is a contraction of cyborg, and humans are already quite adept at creating cybernetic implants, artificial limbs and so on to repair damage caused by disease, accidents and war. Deaf people can hear with implants, people with spinal injuries are on the verge of walking again as research on using computer chips to transmit nerve signals past damaged portions of the nervous system matures and artificial eyes or retina implants are on the horizon to help people see again.
While the current research is to replace or repair damage, it is also clear that it is possible for these replacements to be "better" than the originals. People with artificial "cheetah feet" (artificial limbs made of carbon fibre which store and release energy through elastic deformation of the limb) are not allowed to compete against uninjured runners because it to thought the energy storage of carbon fibre limbs is greater than the elastic energy storage in human tendons and ligaments. Once that threshold has been passed, it becomes a competitive advantage to replace your limbs and organs with "better" cybernetic devices, and people will begin to turn to augmentation in increasing numbers.
The networking aspect of becoming Borg has been explained at length in many of the other answers, so the only addition I will make is using cybernetic augmentation to the brain to access memory and "improve" thinking will be a large aspect of the rush to become cybernetic organisms. Adding network communications capabilities, and access to "the cloud" is essentially an add on and logical extension to direct interfaces between the brain and cybernetic additions (thinking aids) that people will already be demanding. Your smartphone could work very well as a stand alone computer; it already has vastly more processing power than the Apollo spacecraft that went to the Moon; but its real value is being able to connect to voice and data networks and exchange information.
So once cybernetic additions and replacements for existing human limbs and organs have better performance than the biological equivalents, there will be an economic incentive to have cybernetic devices implanted/replace existing parts in order to gain competitive advantage. Once that incentive is crossed, then the process continues as more and more people seek advantages, and more and more radical and extreme cybernetic modifications will be both demanded and tolerated by society.
Call me cynical, but it seems most likely that someone found a way to use computer technology to harness the power of the human brain. Basically turning other people into fancy computers. It probably started with co-opting babies that never knew any better, but eventually transitioned to stealing brains (still in their protective bodies) from adult people. At that point the whole "collective" mythology would be a useful way to convince people they weren't going to spend the rest of their lives trapped in some tiny corner of their mind helplessly watching their body and brain pursue the goals of some overlord. That way people don't fight tooth and nail to the last breath, and instead surrender thinking "maybe this will be OK....".
Side note: this theory does not preclude the possibility that the original overlord would eventually be subjugated by the ghost in the machine. At which point, no biological people would be able to exert control over "the collective". In fact, there is good reason to believe that the more powerful mind will always eventually control the weaker mind that created it regardless of the safeguards put in place.
This is already happening. We all try to work together for the greater good. that is how economics works. We each specialize in a particular task and communicate with each other to share the benefits of that task. Those of us who communicate better, receive a greater share of the resources created. As technology advances, we communicate faster at an exponentially escalating rate (language=>writing=>phone=>internet=>brain-chip=>hive-mind). At some point, anyone who can not instantly transfer their entire knowledge base will not receive a significant portion of the available resource and be left behind by those who can. On the happy post-scarcity scenario, the proto-borgs who did not join the collective are still exploring the galaxy where they originated, while the proto-borgs that did join the collective have already conquered several galaxies.
The Borg isn't a collective.
A collective can't be defeated short of murdering every single member and individuals strengthen the collective by being individuals. There isn't a control hierarchy in a collective. They act in the best interest of the whole, but are not blind to their own survival. No one is more important than anyone else. They pull their knowledge from each other, but a redundancy exists everywhere. Any member can speak for the collective as they are all linked together.
The Borg is a hive.
Individuals don't exist. Yes, there are exceptions, but these are rare and unintended. They follow the commands of one to a few individuals who they protect at all costs, even at the expense of their own lives. Their own existence is obedience. A member of a hive can't speak on behalf of the hive. The leader can speak through the drone. Losing a member of a hive isn't nearly as traumatizing as losing a member of a collective. In a hive that was just a drone. In a collective that was Mary, she made a damn good cake and was pleasant to everyone. She figured out why the quantum generator had a variance. With the help of Bob and Alice, it was fixed. These interactions make a collective stronger.
Careless assimilation would destroy a collective. A hive is unaffected since they suppress the drones they assimilate.
In Star Trek, the Borg started as a collective. Later they became a hive since defeating a collective is almost impossible. The change was subtle. It's similar to how the United States claims to be a Democracy, but is really a Republic. China claims to be a Republic but is a dictatorship. A religion is a cult. The audience just accepted the change and the word collective became synonymous with hive.
How the Borg actually arose:
1) Everyone on the Borg home planet wired themselves together with headsets and other peripherals to play a popular MMORPG.
2) The peripherals are wireless to allow gameplay at any time and place they desire, day or night.
4) The MMORPG game corporation became the new world government and passed laws requiring mandatory sugical implants of the peripherals by everyone (it's all part of the EULA, don't ya know).
5) Borg homeworld is invaded by aliens who don't play computer games.
6) World government uses conventional soldiers to repel invasion and fails horribly.
7) World government creates a new first person shooter game where teams of players control the actions of soldiers sent against the alien invasion.
8) The new cyborg soldiers defeat the alien invasion.
9) The Borg world government steals the stardrive from the defeated invaders.
10 The Borg world government sends out explorers to find new markets/players for their game.
I'm going to suggest a different tack, and advance the idea that the radical collectivism came first, with complete prohibitions on recognizing any distinctions between individuals, except that of the Great Leader.
At some point, implants that provide the capacity to monitor an individual's thoughts and to punish any dissent (by directly stimulating the parts of the brain responsible for sorrow, so that the dissenter is instantly and supremely miserable) are developed and implanted into everyone, except that the Great Leader's circuitry does not allow others access to his thoughts, or the capacity to punish him. He uses this imbalance to set everyone else against each other, so that anyone who rises one hair's breadth above the rest is immediately dragged down by the rest. In short order, everyone but the Great Leader is ground down to the same level.
Then one day the Great Leader goes to the Great Reviewing Stand in the Sky, and everyone else, now all dedicated to monitoring each other for non-conformity and punishing any such, continues on. Since the only individual with any real creativity in the bunch is now dead, all scientific advancement slows to a crawl and the society stagnates for centuries.
Then, one day, they are contacted by species 2. Having accepted for centuries the notion that the end justifies the means, they implant their monitoring and compliance hardware into the members of the landing party and compel them to lie about the nature of species 1's society, so that species 1 is given access to the scientific and political leadership of species 2. This access is then leveraged to bring all of species 2 into the fold.
It snowballs from there.
I'd say that forming a collective is something we're gradually doing. Already we expect communications to be available and much faster than ever before and most of us feel you've ripped off a mental limb when we aren't able to Google. As communications get better and smaller it's only a matter of time before they end up as something tiny that can be injected directly into our head. Once that happens it makes sense to figure out how to send more complex sensory data back and forth directly. From that point it will be increasingly difficult to tell you from me or ever human from machine.
The main difference is that I don't think a centralized controller like in the Borg makes sense. It's much more efficient to allow individuals to think for themselves and from a security point of view it makes the collective more resilient. As happens in any society stronger personalities may have more influence but it's not quite the same as having a controller.