This study aims to examine the phenomenon of code switching and code mixing in Andrea Hirata's novel Sang Pemimpi using a sociolinguistic approach. The phenomenon of language switching in literary works is a reflection of the social, cultural, and educational dynamics of multilingual societies such as Indonesia. This study applies a qualitative descriptive method with a content analysis approach to the narrative and character dialogues in the novel. Data were collected through text documentation, then classified based on the type of code switching (inter-sentential, intra-sentential, and tag switching) and the form of code mixing (insertion, alternation, congruent lexicalization). The results of the analysis show that code mixing is more dominant than code switching. The use of English in this novel often aims to strengthen character characterization, reflect education levels, and convey social aspirations and modern identities. Code switching is used in certain contexts that function to emphasize certain ideas, emotions, or ideological values. This finding is in line with sociolinguistic theory which states that language choice is closely related to the social context and purpose of communication. This study is expected to contribute to the study of language in literature and become a reference for language teaching and understanding identity through the use of codes in literary texts. Keywords: code switching, code mixing, sociolinguistics, The Dreamer, linguistic identity.