There's two phases of a menstrual cycle, before ovulation known as the follicular phase and after ovulation known as the luteal phase. The second phase is not very variable, it's the same length almost always as it is governed by how long the corpus luteum (remnants of the follicles after the ovum bursts out) survives. The first part is variable and is what causes periods to be irregular. In this phase the eggs mature. The body picks several eggs to mature but only one will "win". However, how fast it wins changes. It all depends on how fast it grows and much it manages to suppress growth of the other eggs and that in turn depends on the quality of the egg. But then this also branches out, as it is controlled by levels of hormones this is heavily affected by stress and diet among other things.
It's unfortunate that the first phase is variable otherwise knowing which day you were going to ovulate would be easy.