Before the arrival of the Spanish colonizers in the Philippines in the 16th century, the ancient barangays were well-organized independent villages and in some cases, cosmopolitan sovereign principalities, which functioned much like a city-state. The ancient barangay was the dominant organizational pattern among indigenous communities in the Philippine archipelago. The name barangay originated from balangay, a Malay word meaning "sailboat".
The word barangay in modern use refers to the smallest administrative division in the Philippines, also known by its former Spanish adopted name, the barrio. This modern context for the use of the term barangay was adopted during the administration of President Ferdinand Marcos when he ordered the replacement of the old barrios and municipal councils. This act was eventually codified under the 1991 Local Government Code.
There are a number of distinctions between the modern Barangay or Barrio, and the city-states and independent principalities encountered by the Spanish when they first arrived in 1521 and established relatively permanent settlements in 1574. The most glaring difference would be that the modern entity represents a geographical entity, the pre-colonial barangays represented loyalty to a particular head (datu). Even during the early days of Spanish rule, it was not unusual for people living beside each other to actually belong to different barangays. They owed their loyalty to different Datus. Also, while the modern barangay represents only the smallest administrative unit of government, the barangay of precolonial times was either independent, or belonged to what was only a loose confederation of several barangays, over which the rulers picked among themselves who would be foremost - known as the Pangulo or Rajah. In most cases, his function was to make decisions which would involve multiple barangays, such as disputes between members of two different barangays. Internally, each datu retained his jurisdiction.