Skip to content

Cron Expressions Explained: A Beginner's Guide to Cron Jobs

Cron is a time-based job scheduler found in Unix and Linux systems. A cron expression is a string of five (or six) fields that defines when a scheduled task should run. If you have ever needed to run a backup at 2 AM every night or send a report every Monday morning, you have probably used cron.

The Five-Field Syntax

A standard cron expression has five fields separated by spaces:

┌───────────── minute (0-59)

│ ┌───────────── hour (0-23)

│ │ ┌───────────── day of month (1-31)

│ │ │ ┌───────────── month (1-12)

│ │ │ │ ┌───────────── day of week (0-7, 0 and 7 = Sunday)

│ │ │ │ │

* * * * *

Special Characters

  • * matches any value. * * * * * runs every minute.
  • , separates multiple values. 1,15 in the day field means the 1st and 15th.
  • - defines a range. 1-5 in the day-of-week field means Monday through Friday.
  • / defines a step. */5 in the minute field means every 5 minutes.

Common Cron Schedule Examples

ExpressionSchedule
0 * * * *Every hour (at minute 0)
0 0 * * *Every day at midnight
0 9 * * 1Every Monday at 9:00 AM
*/15 * * * *Every 15 minutes
0 2 * * *Every day at 2:00 AM
0 0 1 * *First day of every month at midnight
30 4 * * 0Every Sunday at 4:30 AM

Cron in Different Environments

While the five-field format is universal, different platforms extend it. AWS EventBridge uses a sixth field for years. GitHub Actions uses the standard five-field cron in its schedule trigger. Kubernetes CronJobs follow the same syntax. Node.js libraries like node-cron add a seconds field at the beginning, giving six fields total.

Common Mistakes to Avoid

  • Running too frequently. * * * * * runs every minute. If your job takes longer than a minute, you will have overlapping executions.
  • Forgetting timezones. Cron uses the system timezone by default. A job scheduled for 0 9 * * * on a UTC server runs at 9 AM UTC, not your local time.
  • Day-of-month vs day-of-week conflict. When both fields are set (not *), the behavior differs between implementations. Some systems use OR logic, others use AND.
  • No error handling. Always redirect cron output to a log file or monitoring system so you know when jobs fail.

Testing Cron Expressions

Before deploying a cron schedule to production, always test it. An online cron parser can show you the next execution times and a human-readable description of your expression. This prevents expensive mistakes like accidentally running a heavy database job every minute instead of every hour.

Test your cron expression

Parse any cron expression and see the next scheduled run times in a human-readable format.

Open Cron Parser