Sanggung was an official title of the senior 5th rank (正五品; Jong 5 pum), the highest attainable for gungnyeo, a lady-in-waiting during the Joseon Dynasty of Korea. Female officers with the title were assigned to govern the inner affairs of the palace. When a regular nain served for more than 15 years, she would be awarded with an ornamental hairpin for a sanggung. Therefore, a newly appointed sanggung was usually 35–45 years old. A court lady at the rank of sanggung was treated well enough to live in her own house with servants.
The title first appears in Goryeosa ("History of Goryeo"), a complied book about the Goryeo period. In the chapter of the book titled Baekgwanji (百官志), regarding all official titles, there were posts named sanggung (尙宮, managing the palace), sangchim (尙寢, managing bedding), sangsik (尙食 managing food), and another sangchim (尙針, managing sewing) during the reign of King Hyeonjong. The book also has another record that Lady Han was appointed as sanggung in March 1031, the 22nd year of the king's reign. These records prove that the sanggung system had existed since the Goryeo period.
As a system on naemyeongbu (內命婦) which refers to women at court with a rank including queen and lady-in-waiting was revised since the foundation of the Joseon Dynasty, female officers with the title, sanggung began to manage inner affairs of the court in general as the highest position of the gunggwan (literally a palace officer). The naemyeongbu was largely divided into naegwan (literally "internal offices") and gunggwan according to Gyeongguk daejeon. The former refers to a king's concubines or a crown prince's consort while gunggwan are female officers with a rank.
The social status of sanggung generally belonged to the yangin (common people) class, distinguished from naegwan in policy.