I am using a 16MHz crystal with an atmega328. I added two capacitors to the crystal as usual. Everytime the capacitors are attached, avrdudee does not recognize the atmega. Once I remove the capacitors it's recognized. I've tried using different capacitor values from 22pf to 47uf and the results are the same. How come avrdudee fails to recognize the microcontroller when the capacitors are attached to the crystal?
Which oscillator option are you using?
12-22pF is the limit for total capacitance C1 + C2 for low power oscillator.
The limit for each capacitor (C1, C2) for full swing is 12-22pF.
So one would expect it to work with the full swing oscillator (C1=C2=22pF) but perhaps not with the low power oscillator.
22pF is too much already, the ATmega328 datasheet, Section 13.3/13.4 specifies 12pF to 22pF on both XTAL1 and XTAL2 for both the 16MHz full swing and the low power oscillator options, and your layout may already provide a few pF.
If you use a breadboard, it has about 15pF between adjacent clamps.