In a medium saucepan over medium heat, melt the butter. Once melted, add the diced onion and cook for about 3-4 minutes until it becomes translucent and fragrant. Stir in the minced garlic and cook for an additional minute, being careful not to let it burn.
Sprinkle the flour over the cooked onions and garlic. Stir constantly for about 2 minutes to cook off the raw flour taste.
Gradually pour in the milk while whisking continuously to avoid any lumps. Keep whisking until the mixture is combined and begins to thicken, which should take about 3-5 minutes.
Once the mixture has thickened, reduce the heat to low. Gradually add in the shredded cheddar cheese, stirring until fully melted and smooth.
Taste your nacho cheese sauce and season it with salt and pepper as needed.