mid-12c., "large group of people," from Old French compagnie "society, friendship, intimacy; body of soldiers" (12c.), from Late Latin companio, literally "bread fellow, messmate," from Latin com "with, together" (see com-) + panis "bread," from PIE root *pa- "to feed." Abbreviation co. dates from 1670s.
Meaning "companionship, consort of persons one with another, intimate association" is from late 13c. Meaning "person or persons associated with another in any way" is from c. 1300. In Middle English the word also could mean "sexual union, intercourse" (c. 1300).
From late 14c. as "a number of persons united to perform or carry out anything jointly," which developed a commercial sense of "business association" by 1550s, the word having been used in reference to trade guilds from late 14c. Meaning "subdivision of an infantry regiment" (in 19c. usually 60 to 100 men, commanded by a captain) is from c. 1400.
Meaning "person or persons with whom one voluntarily associates" is from c. 1600; phrase keep company "consort" is from 1560s (bear company in the same sense is from c. 1300). Expression two's company "two persons are just right" (for conversation, etc.), is attested from 1849; the following line varies: but three is none (or not), 1849; three's trumpery (1864); three's a crowd (1856).
1550s, "line of battle in close ranks," from Latin phalanx "compact body of heavily armed men in battle array," or directly from Greek phalanx (genitive phalangos) "line of battle, battle array," also "finger or toe bone," originally "round piece of wood, trunk, log," a word of unknown origin. Perhaps from PIE root *bhelg- "plank, beam" (source of Old English balca "balk;" see balk (n.)).
In anatomy, originally the whole row of finger joints, which fit together like infantry in close order. Figurative sense of "number of persons banded together in a common cause" is attested from 1600 (compare Spanish Falangist, member of a fascist organization founded in 1933).
The celebrated Macedonian phalanx was normally drawn up sixteen ranks deep, the men being clad in armor, bearing shields, and armed with swords and with spears from 21 to 24 feet long. In array the shields formed a continuous bulwark, and the ranks were placed at such intervals that five spears which were borne pointed forward and upward protected every man in the front rank. The phalanx on smooth ground, and with its flanks and rear adequately protected, was practically invincible; but it was cumbrous and slow in movement, and if once broken could only with great difficulty be reformed. [Century Dictionary]