In this hadeeth, the prophet (pbuh) stated that islamic yearly festivals (eid) are two days. Fitr (After ramadan) and Adha (At Hajj time).
حديث أنس رضي الله عنه قال: "قدم رسول الله صلى الله عليه وسلم المدينة
ولهم يومان يلعبون فيهما فقال: "ما هذان اليومان؟" قالوا: كنا نلعب فيهما
في الجاهلية فقال رسول الله صلى الله عليه وسلم: "إن الله قد أبدلكم بهما
خيراً منهما يوم الأضحى ويوم الفطر" رواه أحمد وأبو داود والنسائي
والحاكم وصححه ابن تيمية والألباني.
Anas may Allah be pleased with him said: The Messenger of Allah peace
be upon him came to AlMadina (and they had two festival days) in which
he said: "What are these two days?" They said: We were celebrating in
them before Islam. He (pbuh) said: "God substitued them with better
days: the day of Fitr and Adha" narrated by Ahmad, Abu Dawood and
Nasa'y.
The length of Adha eid is 4 days (the 4 days after day of arafa); because these are the days in which you are allowed to offer you sacrifice. Also you are not allowed to fast in these days.
The length of Fitr eid is the first day after ramadan -only 1 day- (not 3 as people think). It is not allowed to fast in this day.
Regarding legalisations, It depends on the country laws. For example, in Egypt the official holidays are 2 in Fitr and 3 in Adha.