Heat oven to 350° F.
Cook the macaroni according to the package directions.
Melt the butter in a saucepan over medium heat. Sprinkle the flour over the top. Cook, stirring constantly, for 2 minutes. Still stirring, slowly add the milk. Cook, stirring occasionally, until the sauce has thickened, about 7 minutes. Add the Cheddar, Gruyère, salt, and cayenne (if using) and heat until the cheeses melt.
Drain and rinse the macaroni. Add it to the sauce and toss. Transfer to a buttered casserole. Bake for 25 to 30 minutes.
In Advance: Assemble the macaroni and cheese but do not bake it. Cover and refrigerate for up to 24 hours. Bake as directed, adding 15 to 20 minutes to the cooking time.