← All guides

Cron Expressions Explained: Read Any Schedule in Five Fields

A cron expression is a schedule written in five short fields, like 0 9 * * 1-5. Servers use these lines to run backups, reports, cleanups, and reminders while nobody is watching. The format is compact, old, and everywhere, and it is famously easy to write almost right: one field off and a monthly job runs every minute. This guide teaches you to read any cron line at sight, and to write one you can defend, using real examples throughout.

The five fields, in order

Every cron expression has five fields, separated by spaces, always in the same order: minute, hour, day of the month, month, and day of the week. The fields are read left to right from the smallest unit to the largest. Each field holds a rule for its unit. The job runs at every moment when all five rules are true at once, with one exception we will meet in its own section below.

Each field has its own range. Minutes run 0 to 59. Hours run 0 to 23, so 14 means two in the afternoon. Day of the month runs 1 to 31. Month runs 1 to 12, and on many systems the short names jan to dec work too. Day of the week runs 0 to 7, where both 0 and 7 mean Sunday, and the names sun to sat usually work. An asterisk in a field means every allowed value: an asterisk in the minute field means every minute of the hour.

The four symbols that do the work

Four symbols turn a field from a single value into a rule. The asterisk means all values. A comma builds a list, like 1,15 in the day field for the first and the fifteenth. A hyphen builds a range, like 9-17 in the hour field for the working day. A slash builds a step: */15 in the minute field means every fifteenth minute, and 2 in a range like 0-30/10 means every ten minutes inside that range. Nearly every schedule you will ever meet is built from just these four.

Read a full line with the symbols in hand. The expression 0 9 * * 1-5 reads: minute 0, hour 9, any day of the month, any month, days Monday to Friday. That is nine in the morning on weekdays, the classic start-of-work run. The expression 30 2 * * * is half past two every night, a common backup time. The expression 0 0 1 * * is midnight on the first of every month. Once the fields are in order, no cron line is a mystery.

Counting the runs

A schedule is easier to trust when you can count it. The expression */15 * * * * runs every fifteen minutes: four times an hour, 96 times a day, 672 times a week. If that job sends an email or writes a file, you now know the size of what it produces. The expression 0 */6 * * * runs every six hours, four times a day. The expression 0 9 * * 1-5 runs five times a week, about twenty times a month.

Counting catches the most expensive cron mistake there is: the missing field. A line like * 3 * * * looks like a nightly job at three, and it is, sixty times over, because the minute field holds an asterisk. The job runs every minute of the three o'clock hour. Whenever you write a schedule, count its runs per day and per week before you save it. If the count surprises you, the line is wrong, and it is far better to be surprised now than by an overflowing mailbox later.

The trap: day of the month meets day of the week

When you restrict both the day-of-the-month field and the day-of-the-week field, most cron systems do not require both to match. They run the job when either one matches. The rule comes from the original cron design, and the common implementations keep it. Two restricted day fields mean or, not and.

See what that does to a real line. The expression 0 9 1 * 1 looks like nine in the morning on the first Monday of the month. It is not. It runs at nine on the first day of every month, and at nine on every Monday, because either match is enough. There is no way to say first Monday in one classic cron line. The usual fix is to schedule the job for every Monday and let the job itself check the date, or to accept the wider schedule. If you only restrict one of the two day fields and leave the other as an asterisk, the trap never arms, and the line means exactly what it says.

Time zones and the clock on the wall

Cron reads the clock of the machine it runs on, in that machine's time zone, unless your system is set up otherwise. A job written for nine in the morning runs at nine server time, which may not be nine where you sit. Schedules also meet daylight saving time twice a year: a job set inside the hour that repeats in autumn can run twice, and a job set inside the hour that vanishes in spring can be skipped, depending on the implementation.

The habits that keep you safe are simple. Know which time zone your server keeps, and write schedules in that zone on purpose. Avoid placing important jobs inside the two changing hours of the year. And after you write a line, ask a tool to show you the next few run times as real dates and times. A schedule you have seen as a list of actual moments, today, tomorrow, and next week, is a schedule you understand. That check takes seconds and it is the difference between trusting a line and hoping in it.

Try it yourself

Build and check schedules with the free Cron Expression Generator on CodeToolWorks: pick the times in plain words, read any expression back in English, and see when it runs next. When a log line gives you a number instead of a date, the Timestamp Converter turns Unix timestamps into readable dates and back.