Preheat the oven to 350°F (175°C). Grease and flour a 9×5 inch loaf pan to prevent the cake from sticking and ensure an even release. If you prefer, you can also line the pan with parchment paper for easier removal later. Make sure the oven has fully preheated before you place the cake inside to guarantee even cooking throughout.
In a medium bowl, whisk together the all-purpose flour, baking powder, baking soda, salt, ground cinnamon, and ground nutmeg. The dry ingredients are important for the rise and texture of the cake, and sifting them together helps distribute the baking powder and soda evenly throughout the batter. The cinnamon and nutmeg will provide warmth and a comforting spice flavor that complements the carrots perfectly.
In a large mixing bowl, beat the softened butter and granulated sugar together until the mixture becomes light and airy. This should take about 3 to 5 minutes using an electric mixer on medium speed. The butter and sugar should have a pale color, and the texture should be fluffy and smooth. This step is crucial as it incorporates air into the batter, which contributes to a light and tender cake.
Add the eggs to the butter and sugar mixture one at a time, beating well after each addition. This allows the eggs to fully incorporate into the mixture, ensuring a smooth batter. After the eggs are incorporated, stir in the vanilla extract. The vanilla extract adds a subtle depth of flavor that enhances the sweetness of the cake.
Gradually add the dry mixture to the wet ingredients in parts, alternating with the sour cream. Begin by adding about one-third of the dry mixture, followed by half of the sour cream, and continue alternating until both are fully incorporated. Start and finish with the dry ingredients. Mixing until just blended helps prevent overworking the batter, which could result in a dense cake.
Once the wet and dry ingredients are combined, gently fold in the finely shredded carrots. The carrots add moisture and sweetness, and they should be evenly distributed throughout the batter. If you are using chopped walnuts, fold them in at this stage. Walnuts add a crunchy texture and a nutty flavor that complements the sweetness of the carrots, but they are entirely optional.
Pour the batter into the prepared loaf pan, smoothing the top with a spatula. The batter should fill the pan about halfway, allowing room for the cake to rise as it bakes. Make sure the batter is evenly distributed in the pan so that the cake cooks uniformly.
Bake the cake in the preheated oven for 60 to 70 minutes. Start checking for doneness at the 60-minute mark by inserting a toothpick into the center of the cake. The toothpick should come out clean or with just a few crumbs attached. If the toothpick is still wet with batter, continue baking for an additional 5 minutes and check again. The cake should be golden brown on top and firm to the touch.
Once the cake is done, remove it from the oven and allow it to cool in the pan for about 15 minutes. This brief resting period allows the cake to set slightly, making it easier to transfer. After 15 minutes, carefully remove the cake from the pan and place it on a wire rack to cool completely. Allowing the cake to cool fully will help preserve its texture and prevent the glaze from melting too quickly when applied.
While the cake is cooling, prepare the cream cheese glaze. In a medium bowl, beat the softened cream cheese until smooth. This step is important for achieving a creamy texture without lumps. Gradually add the powdered sugar, milk, and vanilla extract, beating continuously until the glaze is smooth and pourable. The glaze should have a thick yet fluid consistency, perfect for drizzling over the cooled cake.
Once the cake is completely cool, drizzle the cream cheese glaze generously over the top. Use a spoon or a small spatula to spread the glaze evenly, allowing it to drip down the sides for an attractive presentation. The glaze will add sweetness and a creamy contrast to the spiced carrot cake.