Two officers from Spain's Civil Guard rescued the tiny baby on Wednesday morning in Mejorada del Campo, a town around 20 kilometres from Madrid.
The Civil Guard tweeted the good news, saying "#HappyWednesday for Carlos and Andrés, two Guardia Civil officers who have rescued this baby from a rubbish container in Madrid".
The baby has been taken to Henares hospital while police and the Civil Guard try to locate its parents and establish the facts surrounding the case.
Police were alerted at around 7.21am on Wednesday morning, when a dog walker raised the alarm after hearing a baby crying inside an underground rubbish container.
The baby was found in an underground rubbish container similar to the ones pictured. Screen grab: sermadridnorte/YouTube
Civil Guard officers and firemen were soon on the scene, where workers from Madrid's waste collection services opened the container.
Carlos and Andrés, two Civil Guard officers, discovered the baby inside a backpack and took the child straight to hospital in their patrol car, where doctors are currently assessing its condition.