The factors are current age and medal count.
You can attack and be attacked by people who are at your age, one age below you and one age above you, with a similar number of medals.
For example, a Classical player can attack/be attacked by Iron Agers, Classicals and Medievals with a medal count similar as yours. So you will never be able to trample Bronze Age players with gunpowder cannons, even if you have 100 medals.
And unlike the cry-babys out there says, you can win attacks and defenses against players above your age, it's a matter of managing well your attacks and base layout.