Macaroni and Cheese can be left out at room temperature for up to 2 hours.
If you've left the macaroni and cheese out of the fridge at room temperature for over 2 hours then it has likely grown bacteria that you cannot easily see and it should be thrown out to protect your health.
If you're not gonna serve or eat the macaroni within 2 hours make sure to refrigerate the macaroni and cheese because it can go bad quickly at room temperature.
When refrigerated the macaroni and cheese should last for 5 to 7 days.
If the macaroni and cheese smells bad or has grown mold in it then throw it out.
You can also place the macaroni and cheese in a freezer safe container and freeze it.
When frozen the macaroni and cheese will last for up to a year.
However it's best to eat the macaroni and cheese within a few months for the best taste and freshness.