Let’s get the dry ingredients sorted. In a medium bowl, whisk together the flour, baking soda, cinnamon, nutmeg, and salt. I like to use a whisk here instead of a spoon because it breaks up any little clumps of baking soda – nobody wants to bite into one of those!
In a large bowl (make sure it’s really large – we’ll be adding everything to this), whisk together the oil, eggs, sugar, and vanilla until they’re well combined and look smooth and glossy.
Now for the carrots – you want them finely grated (I use the small holes on a box grater). If your carrots are really moist after grating, give them a quick squeeze with paper towels. Too much moisture can make your cupcakes heavy.
Add your dry ingredients to the wet mixture in three portions, mixing gently with a rubber spatula just until you don’t see any more flour streaks. Scrape down the sides of the bowl as you go.
Fold in your grated carrots (and walnuts if using) until they’re evenly distributed. The batter will be pretty thick, and that’s exactly what we want.
Fill each cupcake liner about 2/3 full – I use an ice cream scoop for this, which gives you perfect portions every time. If you see any empty spaces in your scoops, tap the pan gently on the counter a couple times to settle the batter.
Bake for 20-22 minutes, rotating the pans halfway through. You’ll know they’re done when a toothpick comes out clean and the tops spring back when you gently press them with your finger. The tops should be lightly golden brown and slightly domed.
Let them cool in the pans for 5 minutes (set a timer – any longer and they might get soggy), then transfer to a wire rack to cool completely.