Abstract Continuous glucose monitoring (CGM) technology has grown rapidly to track real-time blood glucose levels and trends with improved sensor accuracy. The ease of use and wide availability of CGM would facilitate safe and effective decision making for diabetes management. Here, we developed an attention-based deep learning model, CGMformer, pretrained on a well-controlled and diverse corpus of CGM data to represent individual's intrinsic metabolic state and enable clinical applications. During pretraining, CGMformer encodes glucose dynamics including glucose level, fluctuation, hyperglycemia, and hypoglycemia into latent space with self-supervised learning. It shows generalizability in imputing glucose value across five external datasets with different populations and metabolic states (MAE=3.7 mg/dl). We then finetuned CGMformer towards a diverse panel of downstream tasks in the screening of diabetes and complications using task-specific data, which demonstrated a consistently boosted predictive accuracy over direct fine-tuning on a single task (AUROC=0.914 for T2D screening and 0.741 for complication screening). By learning an intrinsic representation of individual's glucose dynamics, CGMformer classify non-diabetic individuals into six clusters with elevated T2D risks, and identify a specific cluster with lean body-shape but high risk of glucose metabolism disorders, which is overlooked by traditional glucose measurements. Furthermore, CGMformer achieves high accuracy in predicting individual's postprandial glucose response with dietary modelling (Pearson correlation coefficient=0.763) and helps personalized dietary recommendation. Overall, CGMformer pretrains a transformer neural network architecture to learn an intrinsic representation by borrowing information from a large amount of daily glucose profiles, demonstrates predictive capabilities fine-tuning towards a broad range of downstream applications, and holds promise in early warning of T2D and recommendation for lifestyle modification in diabetes management.