In Javanese mythology, the gamelan was created by Sang Hyang Guru in Saka era 167 (c. AD 230), the god who ruled as king of all Java from a palace on the Maendra mountains in Medangkamulan (now Mount Lawu). He needed a signal to summon the gods and thus invented the gong. For more complex messages, he invented two other Gongs, thus forming the original gamelan set.
The earliest image of musical ensembles are found in 8th century Borobudur temple, Central Java. Musical instruments such as bamboo flute, bells, drums in various sizes, lute, and bowed and plucked string instruments were identified in this image. However it lacks metallophones and xylophones element. Nevertheless, the image of this musical ensemble is suggested to be the ancient form of the gamelan.
In the palaces of Java are the oldest known ensembles, the Munggang and Kodokngorek gamelans, apparently from the 12th century. These formed the basis of a "loud style." A different, "soft style" developed out of the kemanak tradition and is related to the traditions of singing Javanese poetry, in a manner which is often believed to be similar to performance of modern bedhaya dance. In the 17th century, these loud and soft styles mixed, and to a large extent the variety of modern gamelan styles of Bali, Java, and Sunda resulted from different ways of mixing these elements. Thus, despite the seeming diversity of styles, many of the same theoretical concepts, instruments, and techniques are shared between the styles.