The baby boy is now in hospital in a "serious condition", a police spokesman said.
The 35-year-old woman, who lived with her parents in eastern Madrid, was detained on suspicion of attempting to kill the baby, police said.
"The woman wrapped the baby in a pair of jeans and threw it out of the kitchen window into an interior patio," police said in a statement.
The mother had kept her pregnancy a secret from her parents.
She cut the umbilical chord herself after giving birth in the early hours of the morning and then threw the child out of the kitchen window, about 2.2 metres (seven feet) above an interior patio, police said.
However, shortly afterwards she suffered heavy bleeding and asked her parents to take her to hospital.
"Later, at about 8.30 am, the grandmother of the newborn went into the kitchen and, looking out of the window, saw a baby in the patio. She ran out to pick it up and alerted emergency services," police said.
Two police officers who first arrived at the home found the baby wrapped in blankets, suffering hypothermia and with its heart and breathing stopped.
They managed to revive the child and take it to hospital.