Cao Xueqin was born to a Han Chinese clan that was brought into personal service (as booi aha or bondservants) to the Manchu royalty in the late 1610s. His ancestors distinguished themselves through military service in the Plain White Banner (正白旗) of the Eight Banners and subsequently held posts as officials which brought both prestige and wealth.
During the Kangxi Emperor's reign, the clan's prestige and power reached its height. Cao Xueqin's grandfather, Cao Yin (曹寅), was a childhood playmate to Kangxi while Cao Yin's mother, Lady Sun (孫氏), was Kangxi's wet nurse. Two years after his ascension, Kangxi appointed Cao Xueqin's great-grandfather, Cao Xi (曹璽), as the Commissioner of Imperial Textiles (織造) in Jiangning (present-day Nanjing), and the family relocated there. When Cao Xi died in 1684, Cao Yin, as Kangxi's personal confidant, took over the post. Cao Yin was one of the era's most prominent men of letters and a keen book collector. Jonathan Spence notes the strong Manchu element in the lives of these Imperial Household bond servants. They balanced the two cultures: Cao Yin took pleasure in horse riding and hunting and Manchu military culture, but was at the same time a sensitive interpreter of Chinese culture. By the early 18th century, the Cao clan had become so rich and influential as to be able to play host four times to the Kangxi Emperor in his six separate itinerant trips south to the Nanjing region. In 1705, the emperor ordered Cao Yin, himself a fluent poet, to compile all surviving shi (lyric poems) from the Tang dynasty, which resulted in The Complete Poems of the Tang.
When Cao Yin died in 1712, Kangxi passed the office over to Cao Yin's only son, Cao Yong (曹顒). Cao Yong died in 1715. Kangxi then allowed the family to adopt a paternal nephew, Cao Fu (曹頫), as Cao Yin's posthumous son to continue in that position. Hence the clan held the office of Imperial Textile Commissioner at Jiangning for three generations.
The family's fortunes lasted until Kangxi's death and the ascension of the Yongzheng Emperor to the throne. Yongzheng severely attacked the family and later confiscated their properties, while Cao Fu was thrown in jail. This was ostensibly for their mismanagement of funds, though perhaps this purge was politically motivated. When Cao Fu was released a year later, the impoverished family was forced to relocate to Beijing. Cao Xueqin, still a young child, lived in poverty with his family.
Almost no records of Cao's early childhood and adulthood have survived. Redology scholars are still debating Cao's exact date of birth, though he is known to have been around forty to fifty at his death. Cao Xueqin was the son of either Cao Fu or Cao Yong. It is known for certain that Cao Yong's only son was born posthumously in 1715; some Redologists believe this son might be Cao Xueqin. In the clan register (五慶堂曹氏宗譜), however, Cao Yong's only son was recorded as a certain Cao Tianyou (曹天佑). Further complicating matters for Redologists is the fact that neither the names Cao Zhan nor Cao Xueqin—names that his contemporaries knew him by—can be traced in the register.
Most of what we know about Cao was passed down from his contemporaries and friends. Cao eventually settled in the countryside west of Beijing where he lived the larger part of his later years in poverty selling off his paintings. Cao was recorded as an inveterate drinker. Friends and acquaintances recalled an intelligent, highly talented man who spent a decade working diligently on a work that must have been Dream of the Red Chamber. They praised both his stylish paintings, particularly of cliffs and rocks, and originality in poetry, which they likened to Li He's. Cao died some time in 1763 or 1764, leaving his novel in a very advanced stage of completion. (At least the first draft had been completed, some pages of the manuscript were lost after being borrowed by friends or relatives.) He was survived by a wife after the death of a son.
Cao achieved posthumous fame through his life's work. The novel, written in "blood and tears", as a commentator said, is a vivid recreation of an illustrious family at its height and its subsequent downfall. A small group of close family and friends appeared to have been transcribing his manuscript when Cao died quite suddenly in 1763–4, apparently out of grief owing to the death of a son. Extant handwritten copies of this work—some 80 chapters—had been in circulation in Beijing shortly after Cao's death and scribal copies soon became prized collectors' items.
In 1791, Cheng Weiyuan (程偉元) and Gao E (高鶚), who claimed to have access to Cao's working papers, edited and published a "complete" 120-chapter version. This was its first woodblock print edition. Reprinted a year later with more revisions, this 120-chapter edition is the novel's most printed version. Many modern scholars question the authorship of the last 40 chapters of the novel, whether it was actually completed by Cao Xueqin.