IMPORTANCE Approximately 1 million patients in the United States with type 2 diabetes mellitus and mild-to-moderate kidney disease do not receive guideline-directed therapy with metformin. This may reflect uncertainty regarding the risk of acidosis in patients with chronic kidney disease. OBJECTIVE To quantify the association between metformin use and hospitalization with acidosis across the range of estimated glomerular filtration rate (eGFR), accounting for change in eGFR stage over time. DESIGN, SETTING, AND PARTICIPANTS Community-based cohort of 75 413 patients with diabetes in Geisinger Health System, with time-dependent assessment of eGFR stage from January 2004 until January 2017. Results were replicated in 67 578 new metformin users and 14 439 new sulfonylurea users from 2010 to 2015, sourced from 350 private US health systems. EXPOSURES Metformin use. MAIN OUTCOMES AND MEASURES Hospitalization with acidosis (International Classification of Diseases, Ninth Revision, Clinical Modification code of 276.2). RESULTS In the primary cohort (n = 75 413), mean (SD) patient age was 60.4 (15.5) years, and 51% (n = 38 480) of the participants were female. There were 2335 hospitalizations with acidosis over a median follow-up of 5.7 years (interquartile range, 2.5-9.9 years). Compared with alternative diabetes management, time-dependent metformin use was not associated with incident acidosis overall (adjusted hazard ratio [HR], 0.98; 95% CI, 0.89-1.08) or in patients with eGFR 45 to 59 mL/min/1.73 m 2 (adjusted HR, 1.16; 95% CI, 0.95-1.41) and eGFR 30 to 44 mL/min/1.73 m 2 (adjusted HR, 1.09; 95% CI, 0.83-1.44). On the other hand, metformin use was associated with an increased risk of acidosis at eGFR less than 30 mL/min/1.73 m 2 (adjusted HR, 2.07; 95% CI, 1.33-3.22). Results were consistent when new metformin users were compared with new sulfonylurea users (adjusted HR for eGFR 30-44 mL/min/1.73 m 2 , 0.77; 95% CI, 0.29-2.05), in a propensity-matched cohort (adjusted HR for eGFR 30-44 mL/min/1.73 m 2 , 0.71; 95% CI, 0.45-1.12), when baseline insulin users were excluded (adjusted HR for eGFR 30-44 mL/min/1.73 m 2 , 1.16; 95% CI, 0.87-1.57), and in the replication cohort (adjusted HR for eGFR 30-44 mL/min/1.73 m 2 , 0.86; 95% CI, 0.37-2.01). CONCLUSIONS AND RELEVANCE In 2 real-world clinical settings, metformin use was associated with acidosis only at eGFR less than 30 mL/min/1.73 m 2. Our results support cautious use of metformin in patients with type 2 diabetes and eGFR of at least 30 mL/min/1.73 m 2 .