"Well, my gran brought me up and she's a witch ...but the family thought I was all- Muggle for ages. My Great Uncle Algie kept trying to catch me off my guard and force some magic out of me -- he pushed me off the end of Blackpool pier once, I nearly drowned -- but nothing happened until I was eight."
-- Neville Longbottom (PS7)
The names of future Hogwarts students are written down at birth in the Book of Admittance, a special parchment book bound with dragon hide kept in a locked tower. When a magical child is born, the Quill of Acceptance floats out of a silver ink pot nearby to write the name, but the Book may suddenly “snap shut” if it suspects a Squib or non-magical child (Pm). If a child develops magical ability any time before the age of eleven, there name will be written down then (JKR, Pm). Every year Professor McGonagall checks the book, then uses this information to send out owls to these children as they approach their eleventh birthdays (Sch1, Pm).
Hagrid told Harry that his name had been been "down" on the list since he was born (PS4).
Neville Longbottom, born just a day before Harry, had a harder time proving his magical skill. It was only when his Uncle Algie tossed him out the window at the age of 8 and he survived the fall that the Book would allow the Quill to write his name down for Hogwarts (PS7,Pm).
The Quill of Acceptance and Book of Admittance are "sentient" magical items, similar to the Elder Wand, which can "choose" its true master even if separated by distance. The Quill and the Book can "see" when a baby is born, and "feel" whether he or she has magical ability. Dumbledore believed it was good for the school that the Book got the last word, especially when families were upset about having a Squib who couldn't attend Hogwarts (Pm).