A cron expression is five short fields, and almost every one you write will do what it looks like it does. The ones that don't fail quietly: the job runs on an extra day, runs at an uneven interval, or runs twice on one night a year. This guide goes through those cases using the behaviour of cronie and Vixie cron, the daemons behind most Linux crontabs, and notes where other schedulers read the same expression differently.
The Five Fields
From left to right the fields are minute, hour, day of month, month and day of week. A job runs in every minute where all of them match, with one exception for the two day fields that the next section covers.
Each field takes a single value, a list separated by commas (1,15), a range with a hyphen (9-17), or * for every value. A step after a slash thins out a range or a *, so 0-23/2 and */2 in the hour field both mean every even hour. Ranges include both ends, and they have to run from low to high. cronie refuses 22-2 in the hour field, so a window across midnight is written as two ranges, 22-23,0-2.
Months and weekdays also take their three-letter English names in any case. cronie's manual says plainly that ranges and lists of names are allowed, so mon-fri and jan,jul both work. Full names such as monday do not.
What Each Field Accepts
Values for cronie and Vixie cron. Other schedulers mostly agree on the ranges but differ on the extras.
| Field | Values | Worth knowing |
|---|---|---|
| Minute | 0-59 | */n restarts at 0 every hour |
| Hour | 0-23 | Read in the cron daemon's time zone |
| Day of month | 1-31 | 31 never matches in a 30-day month |
| Month | 1-12 or JAN-DEC | Names work in ranges and lists |
| Day of week | 0-7 or SUN-SAT | Both 0 and 7 mean Sunday |
The Two Day Fields Are Joined With OR
This is the rule behind most "why did it run today" questions. When both the day of month and the day of week are restricted, cron runs on any day that matches either one. The crontab(5) manual gives the example 30 4 1,15 * 5, which runs at 04:30 on the 1st and the 15th of each month and also on every Friday. It does not mean Fridays that fall on the 1st or the 15th.
The exception is a field that starts with *. cronie's parser sets a flag whenever the first character of a day field is an asterisk, and when that flag is set on either field, both fields have to match. With a plain * that changes nothing, since every day matches it. It matters with steps: 0 9 */2 * 1 has a day-of-month field that starts with *, so cronie runs it only on odd-numbered days that are also Mondays.
Other implementations draw that line elsewhere. In robfig/cron, a widely used Go scheduler library, */2 with a step above 1 does not count as a star, so the same expression joins the fields with OR and runs on every odd day plus every Monday. When an expression restricts both day fields, test it in the scheduler that will actually run it.
The OR rule also catches an expression that looks harmless. 0 0 1 * 0-6 reads like "the 1st of the month, any weekday", but neither field starts with *, the fields are joined with OR, and 0-6 matches every day, so the job runs daily.
The first Monday of the month
Cron cannot express "the first Monday" on its own, and 0 9 1-7 * 1 is the classic wrong attempt, since OR makes it run on the 1st to the 7th and on every Monday. The common workaround schedules days 1 to 7 and lets the command check the weekday: 0 9 1-7 * * [ "$(date +\%u)" = 1 ] && /path/to/job. The backslash before % is required. In a crontab command line an unescaped % turns into a newline, and everything after it is passed to the command as input.
Steps Restart at the Edge of the Field
A step does not set an interval. It picks values inside one field, counting from the start of that field, and the count starts over when the field rolls over.
*/15 in the minute field gives 0, 15, 30 and 45, and the gaps stay even because 15 divides 60. */7 gives 0, 7, 14 and so on up to 56, and then the hour turns over and the next run is at minute 0, four minutes later. The same happens with hours: 0 */5 * * * runs at 00:00, 05:00, 10:00, 15:00 and 20:00, and then again at 00:00 after only four hours. Only steps that divide 60 (for minutes) or 24 (for hours) give a regular rhythm.
Day-of-month steps are worse, because months have different lengths. 0 0 */2 * * means days 1, 3, 5 and so on through 31. In a 31-day month the job runs on the 31st and again on the 1st. In a 30-day month it runs on the 29th and then waits two days for the 1st.
A step after a single number, such as 5/15, is another split between implementations. robfig/cron reads it as 5-59/15. cronie's parser rejects it, because it only accepts a step after * or after a range. Writing the range out, 5-59/15, works in both.
Check an expression before it ships
Plain-English meaning, the next runs in any time zone, and a warning for each of these traps.
Six or Seven Fields Means a Different Dialect
Quartz, the Java scheduler, and the many libraries that copy its syntax use six mandatory fields with seconds in front, plus an optional year at the end. 0 0 12 * * ? is noon every day in Quartz and an error in a crontab.
The extra field is easy to spot. The day-of-week numbering is not. Quartz counts 1 to 7 starting from Sunday, so its documentation's 6#3 is the third Friday and 2#1 the first Monday. A Quartz 1-5 is Sunday to Thursday, where the same text in a crontab is Monday to Friday. Names avoid the problem in both, since MON-FRI means the same thing everywhere.
Quartz also has special characters cron does not: L for the last day of the month or the last given weekday, W for the nearest weekday to a date, # for the nth weekday of the month, and ? for "no specific value". Quartz requires ? in one of the two day fields, because it does not support restricting both at once. Kubernetes CronJobs accept ? as a synonym for *, and cronie rejects it.
The Same Expression in Different Schedulers
Time zone behaviour as documented by each project at the time of writing.
| Scheduler | Fields | Time zone | Notes |
|---|---|---|---|
| crontab (cronie) | 5 | Server's local zone, or CRON_TZ | Rejects ?, L, W and # |
| GitHub Actions | 5 (POSIX) | UTC unless the workflow sets one | Shortest interval 5 minutes, runs only on the default branch |
| Kubernetes CronJob | 5 | Controller manager's local zone, or .spec.timeZone | ? equals *, CRON_TZ inside the schedule is rejected |
| Quartz | 6 or 7 | Set on the trigger | Seconds first, Sunday is 1, needs ? in a day field |
What Happens on a Daylight Saving Night
When clocks go forward in spring, an hour of wall-clock time never happens. When they go back in autumn, an hour happens twice. A job scheduled inside either hour has to be handled somehow, and cronie handles it in a specific way that its cron(8) manual describes.
Time changes of less than three hours, such as daylight saving changes, get special treatment for jobs that run at a fixed time. If the clock jumps forward, fixed-time jobs that would have run in the skipped interval run immediately after the jump. If the clock goes back, cronie avoids running the same job twice. A 02:30 job in New York on 10 March 2024, when the clocks went from 02:00 straight to 03:00, ran at 03:00. On 3 November 2024, when 01:30 happened twice, a 01:30 job ran once.
In the source, "fixed time" means neither the minute nor the hour field starts with *. Jobs that do start with * there, such as */15 * * * * or 0 */2 * * *, follow the clock as it reads after the change. They simply get no runs in the skipped hour and get a second round of runs in the repeated one.
All of this is about the daemon's own time zone. For a crontab that sets its own zone with CRON_TZ, a comment in cronie's source admits that jobs can be missed or run twice during that zone's change, and recommends not scheduling anything in that hour.
Changes of more than three hours are treated as corrections to the clock or the time zone, and cron uses the new time straight away. Other schedulers do their own thing on these nights, so the safest choices are to run the cron daemon in UTC or to keep jobs that must run exactly once out of the 01:00 to 03:00 window, where most daylight saving changes happen.
Habits That Keep Schedules Predictable
Most cron surprises are avoidable with a few conventions.
Leave one day field as *
If you restrict only the day of month or only the day of week, the OR rule never comes into play and every scheduler agrees on the meaning.
Use steps that divide evenly
Minute steps of 1, 2, 3, 4, 5, 6, 10, 12, 15, 20 or 30, and hour steps of 1, 2, 3, 4, 6, 8 or 12, keep every gap the same length.
Use names for weekdays
MON-FRI means the same in cron, Quartz and Kubernetes, while 1-5 does not.
Avoid minute 0
Everyone schedules on the hour, and shared runners feel it. GitHub's documentation lists the start of every hour as a high-load time when scheduled workflows may be delayed, and suggests picking another minute.
Write the time zone down
Put CRON_TZ in the crontab, timeZone in the CronJob, or a comment next to the line. A schedule without its zone is only half a schedule.
Frequently Asked Questions
Related Tools
Keep Reading
Ten Digits or Thirteen: Reading a Unix Timestamp Without Guessing
Milliseconds read as seconds land in the year 55,840. Why the digit count gives the unit away, why JSON rounds off nanoseconds, and where 2038 still bites.
Inclusive or Exclusive: Why Day Counts Come Out One Off
Monday to Friday is four days or five. How court deadlines, Excel's NETWORKDAYS and hotel bills each count, and why a business day depends on where you are.
Why a Regex Can Hang: Backtracking and the Patterns That Cause It
One regular expression took Cloudflare's network down for 27 minutes. The shape that causes it is recognisable in seconds once you know what to look for.