"ydw" is not really "yes" -- it's more "I am".
Welsh usually answers questions yes/no not with separate words that are just for that, but by repeating the appropriate verb -- as if you said "Are you pretty? I am. Am I pretty? You are not."
So here, "ydw" would be "I am", and "nac ydw", "I am not".
Those would be appropriate answers for a question that starts with "Wyt ti ...?" (are you ...?), though we'd usually say "Yes" and "No" in English rather than "I am" / "I am not", except for some speakers who do this due to Celtic influence on their English :)
- dw i (or: rw i, rydw i) = I am (in a positive statement, e.g. I am eating cheese = Dw i'n bwyta caws)
- dw i ddim (or: dydw i ddim) = I am not (negative statement, e.g. I am not going = Dw i ddim yn mynd)
- ydw i ...? = am I ...? (question)
- Ydw. = Yes, I am. (Answer to a question)
In slightly more formal/standard situations, there are different forms for positive statements, negative statements, and questions / answers to questions.
In common language, the positive and negative forms are the same (dw i / dw i ddim), but you may also see ones where the positive form has r- and the negative one has d-. The question one has neither of those and is thus only "ydw" rather than "rydw" or "dydw".
These come from an original form ydwyf which got worn down to ydw or even dw -- and for positive statements used to have an yr in front (yr ydwyf i becoming rydw i) and negative ones a nid (nid ydwyf i becoming dydw i (ddim)). I believe questions used to have an a before which did not leave any mark behind for this verb.