Here are the most likely causes of B12 deficiency in an adult - I did not include the causes that are found since birth (congenital or hereditary) as I doubt they apply to you;
-Inadequate dietary intake (ie, vegetarian diet). The body has good stores of B12, so it takes about 5 years of a strictly vegetarian diet to deplete those stores and develop B12 deficiency.
-Loss of gastric mucosa: in conditions where the the inner lining of the stomach is atrophied (unhealthy, dead), such as in pernicious anemia (here the stomach fails to produce a factor known as Intrinsicl Factor "IF" needed to absorb B12) , gastrectomy (this is a type of surgery mostly done to treat obesity "bariatric surgery" of to remove a mass; with the size of the stomach reduced, B12 absorption gets compromised), ingestion of caustic material that burn the stomach, or chronic use of histamine 2 blockers for acidity problems.
-Functionally abnormal IF: it cannot bind and absorb B12
-Inability to properly digest food and extract B12 from it
-Insufficient pancreatic enzymes due to disease in the pancreas can impair B12 absorption
-Bacterial overgrowth in intestine: these bacteria compete with the body for B12
-Diphyllobothrium latum (fish tape worm) also competes with the body for B12
-Disorders of the mucosa of the small intestines: if you suffer from diseases that cause chronic inflammation of the intestines, such as celiac disease (gluten sensitivity) or inflammatory bowel disease, the constant inflammation can negatively affect absorption of many elements, including B12
-Resection of a segment of the small intestines.