The Five Fields and What They Mean
A cron expression is a sequence of five space-separated fields, each representing a unit of time. The fields are minute, hour, day of month, month, and day of week. Each field accepts a specific set of values and operators, and together they define when a scheduled task should run.
The minute field accepts values from 0 to 59. The hour field accepts 0 to 23. The day of month field accepts 1 to 31. The month field accepts 1 to 12. The day of week field accepts 0 to 7, where both 0 and 7 represent Sunday.
Wildcards and Specific Values
The asterisk is the simplest operator. It means "every valid value" for that field. A cron expression of */5 * * * * runs every five minutes. The asterisk in the hour, day of month, month, and day of week fields means "every hour, every day, every month, every day of the week."
Specific values are straightforward. 30 14 * * * runs at 2:30 PM every day. 0 0 1 1 * runs at midnight on January 1st. The values are positional, so the order matters.
Comma-Separated Lists
Commas let you specify multiple discrete values within a single field. 0 9,17 * * * runs at 9 AM and 5 PM. 0 * * * 1,3,5 runs at the top of every hour on Monday, Wednesday, and Friday.
Lists work in any field. 0 0 1,15 * * runs at midnight on the 1st and 15th of every month. The values do not need to be consecutive.
Ranges
A hyphen defines a range of consecutive values. 0 9-17 * * * runs at the top of every hour from 9 AM through 5 PM. 0 0 1-7 * * runs at midnight on the 1st through the 7th of every month.
Ranges can be combined with lists. 0 9,14,17 * * * runs at 9 AM, 2 PM, and 5 PM. 0 9-17/2 * * * runs at 9 AM, 11 AM, 1 PM, 3 PM, and 5 PM: the step counts from the start of the range, not from zero.
Step Values
The forward slash defines a step interval. */15 * * * * runs every 15 minutes. 0 */2 * * * runs at the top of every even hour.
Step values can be applied to ranges as well. 0 0-23/4 * * * runs at midnight and every four hours after that. The step is applied to the base range, not to the entire field.
Day of Month vs. Day of Week
The third and fifth fields are where most people make mistakes. The day of month field (third) accepts 1 to 31. The day of week field (fifth) accepts 0 to 7.
When both fields have specific values, the task runs if either condition is met. 0 0 15 * 5 runs at midnight on the 15th of every month AND on every Friday. This is not an AND relationship between the two fields — it is an OR.
If only one field has a specific value, the other is treated as "every." 0 0 15 * * runs at midnight on the 15th of every month, regardless of the day of week. 0 0 * * 5 runs at midnight every Friday, regardless of the date.
Common Patterns
Several patterns appear frequently enough to memorize. 0 0 * * * runs at midnight every day. 0 0 * * 0 runs at midnight on Sunday. 0 0 1 * * runs at midnight on the first of every month. 0 0 1 1 * runs at midnight on January 1st.
The expression 0 0 * * * is not the same as 0 0 * * 0. The first runs every day at midnight. The second runs only on Sunday at midnight.
Checking Your Work
Cron expressions can be difficult to read at a glance, especially when they contain multiple operators. A tool like CronExplain can parse a cron expression and show you the next ten firing times, along with a plain-English explanation. This is useful when you need to verify that a complex expression matches your intent.
If you are unsure whether your cron expression behaves as expected, check your system's documentation. Different implementations may handle edge cases differently, particularly around leap years and month lengths.
Tool mentioned: CronExplain