The following papers may further help, particularly the defining/demonstrating and guiding the use of theme, category, and sub-category.
Bengtsson, M. (2016) How to plan and perform a qualitative study using content analysis, Nursing Plus Open, 2, s, pp. 8-14.
Elo, S. and Kyngäs, H. (2008) The qualitative content analysis process, Journal of advanced nursing, 62, 1, pp. 107-115.
Erlingsson, C. and Brysiewicz, P. (2017) A hands-on guide to doing content analysis, African Journal of Emergency Medicine, 7, 3, pp. 93-99.
Schreier, M. (2014) Qualitative Content Analysis, in Flick, U. (ed.) The SAGE Handbook of Qualitative Data Analysis. London: SAGE Publications Ltd, pp. 170-183.
Vaismoradi, M., Jones, J., Turunen, H. and Snelgrove, S. (2016) Theme development in qualitative content analysis and thematic analysis, Journal of Nursing Education and Practice, 6, 5, pp. 100-110.
Themes generally "emerge" as the last stage of the analysis, based on a comparison of codes. But there are often so many low-level codes that you need to group them into higher-order categories before you can make effective comparisons across the sets of codes.
Perhaps it would be useful to consider the data that you are examining. For instance, if you are reading through interview transcripts. Then you will typically be looking for meaning sets of words, either individually, or grouped together into meaning categories. These can be termed, codes. Then together these codes (groups of meaningful words, general ideas about what the person is saying) can be grouped together in a higher level hierarchy into another category (thus potentially turning the initial category into a sub-category). Lastly, the goal tends to be to reach a theme, an overall understanding of what all these words mean when grouped together in a meaningful way to answer your research question. I know many people love the work of Johnny Saldaña regarding coding, https://www.amazon.com/Coding-Manual-Qualitative-Researchers-Third/dp/1473902495 which you can review and get some insights, too. Good luck!
The following papers may further help, particularly the defining/demonstrating and guiding the use of theme, category, and sub-category.
Bengtsson, M. (2016) How to plan and perform a qualitative study using content analysis, Nursing Plus Open, 2, s, pp. 8-14.
Elo, S. and Kyngäs, H. (2008) The qualitative content analysis process, Journal of advanced nursing, 62, 1, pp. 107-115.
Erlingsson, C. and Brysiewicz, P. (2017) A hands-on guide to doing content analysis, African Journal of Emergency Medicine, 7, 3, pp. 93-99.
Schreier, M. (2014) Qualitative Content Analysis, in Flick, U. (ed.) The SAGE Handbook of Qualitative Data Analysis. London: SAGE Publications Ltd, pp. 170-183.
Vaismoradi, M., Jones, J., Turunen, H. and Snelgrove, S. (2016) Theme development in qualitative content analysis and thematic analysis, Journal of Nursing Education and Practice, 6, 5, pp. 100-110.
I humbly offer you the following text of my authorship: the notion of "variable" will also help you to understand the notion of sub-category for cases of qualitative scales.
Article Sobre conceptos, categorías y variables. (Respuesta a una pr...
The guiding rule should be the utility of the construct rather than the hierarchy. The utility is achieved by reaching the "right" level of abstraction. Basically, moving form text, to code, to category, and to themes is a motion between these degrees of abstraction. The text itself being the riches on the one hand, and least abstract on the other.
Codes are attempts to create groups of codes according to their common denominator. Typically, you get to the sub-category after you have the category, because you realize that a category is to broad (i.e., too abstract) to represent the nuances of your data. For instance, you may begin with aggregating the following codes: happy, sad, depressed, ashamed perplexed, ambivalent, and angry into a category "emotions" only later to realize that you can create more nuanced sub-categories "positive emotions", "negative emotions" and "mixed emotions". These are less abstract to some degree and thus more nuanced.
Moving to themes is considerably more complicated because it is beyond finding common denominators between codes. It is an art (not so much a method" of identifying the ideas or patterns that run through the text. See attached papers for guidance on this matter. Themes (should) manage to integrate the abstractness of the categories within the context of the research.