First, expanding on Scoots' approach of gently deflecting with humo(u)r, and taking note of your comment about how you drew a blank when the question came, the key is to have your answer lined up ahead of time so you are not caught off guard next time. It's much more effective to immediately fire off a witty response than to fumble for one. I use these two when I don't want to tell someone my age:
Old enough to know better than to answer that question!
One hundred forty-seven. And today I'm feeling every bit of it.
I had a colleague once whose stock response was:
18 and some months.
(This one works best if your actual age is not near 18. My colleague was - I think - in her 30s at the time.)
There are dozens of other suggestions on the web. Search for "witty responses to how old are you" and you'll find sites with lists of responses that run the range from self-deprecatingly clever to downright rude. Choose one or two that work for your personality (preferably not the rude ones!) and have them ready to go for when the question comes at you. Use a cheerful tone of voice - this conveys that you are not offended by the question... but you are also not interested in answering it.
Much of the time, this is enough to stop the asker. Sometimes, people persist, so again, prepare in advance. Have a couple of fallbacks ready in case a followup comes and choose the appropriate one for your situation. It could be a serious explanation of why it's your policy not to give out your age (clarifying that "it's not you, it's me"), or it could be a range ("thirty-something"), or it could be another joke ("my mother doesn't like me to tell people because she thinks it makes her look old"). Once again, the key is to have them ready in advance.
My fallback, in case it's helpful to you, is to explain - at length - why I'm old enough to know not to give out my age. I tell a long, boring story about how a woman once asked and I responded honestly, and she outright cackled at me, crowing loudly "YOU'RE JUST A BABY!" even though my hair was already starting to go grey and she could only have been a few years older than I was.
The details of the story don't matter (though they are true). The real point is:
- the reason has nothing to do with the person I'm currently talking to.
- the story contains nothing they can object to or argue with (which they would be very likely to do if you said you were worried about identity theft).
- it's a boring story that they are not interested in pursuing further.
Once I see they've lost interest in the topic, I end the boring story and we move on to something else.
Second, whenever someone asks you a question about your age, see if you can answer it with a date instead. Many age questions are really date questions in disguise. Your colleague's is a prime example. What he really wanted to know was whether he would have overlapped with your friend, and so you might have said:
You mean when was my friend living in Anytown? Up until 2012. Then he (she) moved to Otherburg.
In this case, that would probably have worked. Of course, you didn't know that for sure until after you had already answered with your age. But be on the lookout in the future - sometimes a question about your age can be answered with a date.