Question: I travelled from outside of Europe to Madrid, Spain via Frankfurt, Germany. As my first point of entry into the Schengen area was Germany my immigration was done there. I had initially planned to stay for 22 days and I told the same to the immigration official. My visa-free stamp says the number 22 next to the date.

However I am loving Spain and I want to extend my trip.

**Can I stay for the full 90 days which are allowed within any 180 day period or do I need to leave within 22 days?**

Also in case I am allowed to stay for the full 90 days, what is the significance of the number "22" which was stamped on the passport. **Are the number of days stamped on the passport to verify that the traveler is actually staying for the length of time which the traveler stated at the time of entry?**

**Are there any negative consequences to staying for more than the amount of time which was stated at the time of entry?**

Answer: 
Schengen stamps do not show a period of admission. They show only the date of the border crossing. Schengen border officers do not grant a period of admission -- this is controlled only by the terms of the visa in combination with the 90/180 rule, or, for a visa-free visit, by the 90/180 rule alone.

If the number 22 is part of the stamp it's just a coincidence that the stamp's [control number](https://travel.stackexchange.com/a/171939/19400) was 22. If the officer wrote "22" by hand then there's something else unusual going on, but we need more information to know what it might be.
No, that's not the purpose of the entry stamp. There is no record of your initial conversation and no system to track or enforce the purpose or planned length of stay of visa-free visitors (visa applications, on the other hand, are documented in a database). The main things that should be checked when you exit the Schengen area is whether you exceeded the maximum length of stay (90 days in your case) and whether there is an alert about you (arrest, surveillance) or your travel documents (stolen documents).

As @phoog explained, there is no legal concept of a period of admission and it is not up to the border guards you talked to to decide how long you may stay. You can of course be questioned about the nature of your trips, your financial resources, your ties with your country of residence, etc. both when leaving and when re-entering the Schengen area. I would guess that the longer your stay, the more likely you are to attract the interest of border guards, even more so if you make several long stays, but it's not directly related to changing your mind about the length of stay.