Well, a ported box works as a so called Helmholtz resonator. If you picture the air in the tunnel as an air 'cork', the volume of air in the box will get compressed if you push the 'cork' inwards, & the opposite will happen if you try & pull the 'cork' out. If you imagine the 'cork' moving back & forth as a result, it will do so at a certain frequency (the Helmholtz resonance). This resonance depends on 3 things:#1 The volume of air 'trapped' in the box (internal volume)
#2 The area of the 'cork'/tunnel
#3 The depth of the 'cork'/tunnel
At any given box-volume a longer tunnel will lower the resonance (cos the weight of the 'cork' increases). A smaller area of the tunnel will do the same - think of cushion: if you press on it with the palm of your hand, you hand will only sink that deep - if you use only your fingertip using the same force, your finger will sink deeper; the cushion is seemingly softer now. Same thing with the smaller tunnel area - the air 'spring' in the box is softer to the smaller area, thus the Helmholtz resonance lowers.
And, of course, the reverse is true - if you make the tunnel shorter, the resonance gets higher, & the same thing happens if you increase the area of said tunnel.
The purpose of using this in a speaker box are several: Getting a deeper, more powerfull bass - helping the driver-unit where it has to work the hardest, in the bass area. It will typically reduce the movement (=excursion) of the diaphragm to 1/4 at the resonance - & reduce distortion from said driver with the help of the aforementioned reduction of movement.
One can, however, not just put any driver in any box using this principle - several parameters have to be considered; The drivers properties (socalled Thiele/Small parameters - a science in itself! :-) ), the box volume & where to place the resonance - it's here the tunnel/port size comes into play!
Sorry, that sorta got outa hand - hope it helped.