When the boy reached the age of striving along with his father, Ibrahim said to him, in the meaning of the verse: «فَلَمَّا بَلَغَ مَعَهُ ٱلسَّعْىَ قَالَ يَٰبُنَىَّ إِنِّىٓ أَرَىٰ فِى ٱلْمَنَامِ أَنِّىٓ أَذْبَحُكَ فَٱنظُرْ مَاذَا تَرَىٰ قَالَ يَٰٓأَبَتِ ٱفْعَلْ مَا تُؤْمَرُ سَتَجِدُنِىٓ إِن شَآءَ ٱللَّهُ مِنَ ٱلصَّٰبِرِينَ» (37:102).
Scholars explain that the dream of a prophet is a form of revelation, which is why Ibrahim treated it as a command. Notice how he spoke to his son. He did not simply act, but told him and asked what he thought. The son answered with calm faith: do what you are commanded, and you will find me, if Allah wills, among the steadfast. He placed his patience under the will of Allah.
The verse says the boy had reached the age of striving with his father, which means he was old enough to walk and work with him. The Quran does not give his age as a number. Ibrahim had asked for this child in his own prayer (37:100), so the boy was very dear to him, and that is what made the test so heavy.