Your timings are very tight - you might be lucky, or you might not.
There's a free shuttle bus from T2 to T4. When you reach T4, go downstairs to catch the Cercianos train to Chamartin. It only takes 11 minutes, BUT as far as I can recall, the trains run every 30 minutes. As
@StFina suggests, it would be worth checking the departure times. If you're likely to have a long wait for the train, a taxi might be a more reliable option.
There's more information here:
http://www.aena.es/csee/Satellite/A.../en/Page/1237554326802//Public-transport.html
Good luck! If your flight is on time and you're travelling with hand luggage, it might work out OK. If it were me, I would definitely try to make it happen.