If all goes well, you'll have plenty of time. The bus from T1 to T4 takes about 20 minutes.
Going in direction T1 to T4, you want to be on the 1st Floor at the departures level.
(Going direction T4 to T1, you have to be on the Arrivals level, which is the Planta Baja, Lower level)
The bus runs every 5 minutes between 6:30 a.m. and 23:30.
From 23:30 - 1:50 a.m. it runs every 20 minutes; from 1:50 -6:30, every 40 minutes)
In my experience, going through Immigration in Barajas is usually pretty fast, but of course if several big flights all land at once you may get long lines.
Getting to your gate at T4 might be a long haul. But it's very well marked, with lots of indication about how much time it will take (though the times posted are very generous and you usually arrive in much less time than they indicate).
A tip -- The elevators in T4 are usually much quicker than the escalators because of the distances between upper and lower levels.
Buen camino! Laurie