Oooh, good one! Typically in a brand identity I'd say 5-7. But that's an entire brand. The break down is 1-3 primary colours, 3-4 secondary colours and some neutrals (black, white, navy, greys, creams).
But for a logo on it's own, max 1-3. Remember simple colour palettes are 80% more recognisable than complex ones.
So now you know how many colours you need, you need to take into consideration the psychology behind using them, warm and cool colours, monochromatic, complimentary. A colour like a bright yellow is considered a comforting colour, while orange is striking and eager for attention. Orange and reds are used heavily in the food manufacturing and fast food industries. Blue triggers calm feelings, so a lot of medical businesses use it. Facebook uses blue to keep people calm and make sure they are comfortable lingering on the platform. Greens organic and environmental, but also used in banking and insurance. Black, white, grey and deep purple have that regal, high-end feel to them.
You need to match the colours to the vibe that you're creating.